Skip to content

Commit ec0eba9

Browse files
author
Alessandro Diez
committed
feat: add renderItem
1 parent 02a0e56 commit ec0eba9

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

Example/app.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ const renderCarousel = () => (
2727
<View style={{ backgroundColor: '#E67E22', flex: 1 }}/>
2828
</Carousel>
2929
)
30+
31+
const renderItem = (open) => (
32+
<View style={styles.customItemBox}>
33+
<TouchableOpacity onPress={open} style={styles.customItemButton}>
34+
<Text style={styles.customItemText}>I'm a custom element</Text>
35+
</TouchableOpacity>
36+
</View>
37+
)
38+
3039
export default () => (
3140
<SafeAreaView>
3241
<ScrollView style={styles.container}>
@@ -67,6 +76,14 @@ export default () => (
6776
</Lightbox>
6877
</View>
6978
<View style={styles.text}><Text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </Text></View>
79+
<Lightbox renderItem={renderItem}>
80+
<Image
81+
style={styles.contain}
82+
resizeMode="contain"
83+
source={{ uri: 'https://www.yayomg.com/wp-content/uploads/2014/04/yayomg-pig-wearing-party-hat.jpg' }}
84+
/>
85+
</Lightbox>
86+
<View style={styles.text}><Text>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </Text></View>
7087
</ScrollView>
7188
</SafeAreaView>
7289
)
@@ -127,4 +144,18 @@ const styles = StyleSheet.create({
127144
text: {
128145
marginVertical: BASE_PADDING * 2,
129146
},
147+
customItemBox: {
148+
height: 150,
149+
justifyContent: 'center',
150+
alignItems: 'center',
151+
},
152+
customItemButton: {
153+
backgroundColor: '#000000',
154+
justifyContent: 'center',
155+
alignItems: 'center',
156+
},
157+
customItemText: {
158+
padding: 20,
159+
color: '#FFFFFF'
160+
}
130161
});

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ const MyApp = () => (
8383
|**`activeProps`**|`object`|Optional set of props applied to the content component when in lightbox mode. Usable for applying custom styles or higher resolution image source.|
8484
|**`renderHeader(close)`**|`function`|Custom header instead of default with X button|
8585
|**`renderContent`**|`function`|Custom lightbox content instead of default child content|
86+
|**`renderItem(open)`**|`function`|Custom content instead of default child content|
8687
|**`willClose`**|`function`|Triggered before lightbox is closed|
8788
|**`onClose`**|`function`|Triggered when lightbox is closed|
8889
|**`onOpen`**|`function`|Triggered when lightbox is opened|

src/Lightbox.tsx

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface LightboxProps<T = any> extends IGestureProps {
3434
activeProps?: Record<string, T>;
3535
renderContent?: Func<T, JSX.Element>;
3636
renderHeader?: Func<T, JSX.Element>;
37+
renderItem?: Func<T, JSX.Element>;
3738
didOpen?: Func<T, void>;
3839
onOpen?: Func<T, void>;
3940
willClose?: Func<T, void>;
@@ -58,6 +59,7 @@ const Lightbox: React.FC<LightboxProps> = ({
5859
disabled = false,
5960
renderContent,
6061
renderHeader,
62+
renderItem,
6163
didOpen = noop,
6264
onOpen = noop,
6365
willClose = noop,
@@ -139,17 +141,27 @@ const Lightbox: React.FC<LightboxProps> = ({
139141
...rest,
140142
});
141143

142-
return (
143-
<View ref={_root} style={style} onLayout={onLayout}>
144-
<Animated.View style={{ opacity: layoutOpacity.current }}>
145-
<TouchableHighlight
144+
const _renderItem = () => {
145+
if (renderItem) {
146+
return renderItem(open);
147+
}
148+
149+
return (
150+
<TouchableHighlight
146151
underlayColor={underlayColor}
147152
onPress={open}
148153
onLongPress={onLongPress}
149154
disabled={disabled}
150155
>
151156
{children}
152-
</TouchableHighlight>
157+
</TouchableHighlight>
158+
);
159+
}
160+
161+
return (
162+
<View ref={_root} style={style} onLayout={onLayout}>
163+
<Animated.View style={{ opacity: layoutOpacity.current }}>
164+
{_renderItem()}
153165
</Animated.View>
154166
{disabled ? null : <LightboxOverlay {...getOverlayProps()} />}
155167
</View>

src/LightboxOverlay.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { useGesture, IGestureProps, useNextTick } from "./hooks";
1919

2020
type OmitedLightboxProps = Omit<
2121
LightboxProps,
22-
"style" | "disabled" | "underlayColor" | "activeProps" | "renderContent"
22+
"style" | "disabled" | "underlayColor" | "activeProps" | "renderContent" | "renderItem"
2323
>;
2424

2525
export interface LightboxOverlayProps

yarn.lock

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2+
# yarn lockfile v1
3+
4+
5+
"js-tokens@^3.0.0 || ^4.0.0":
6+
version "4.0.0"
7+
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
8+
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==
9+
10+
loose-envify@^1.4.0:
11+
version "1.4.0"
12+
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
13+
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
14+
dependencies:
15+
js-tokens "^3.0.0 || ^4.0.0"
16+
17+
object-assign@^4.1.1:
18+
version "4.1.1"
19+
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
20+
integrity sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=
21+
22+
prop-types@^15.7.2:
23+
version "15.8.1"
24+
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
25+
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
26+
dependencies:
27+
loose-envify "^1.4.0"
28+
object-assign "^4.1.1"
29+
react-is "^16.13.1"
30+
31+
react-is@^16.13.1:
32+
version "16.13.1"
33+
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
34+
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==

0 commit comments

Comments
 (0)