Skip to content

Commit 5825685

Browse files
authored
fix: image gallery safe area (#2855)
* fix: image gallery safe area * fix: isMessageAIGenerated type issue * fix: bring back animations for opening and closing of the gallery header/footer
1 parent 851237c commit 5825685

File tree

4 files changed

+39
-30
lines changed

4 files changed

+39
-30
lines changed

examples/SampleApp/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const DrawerNavigatorWrapper: React.FC<{
183183
enableOfflineSupport
184184
// @ts-expect-error
185185
ImageComponent={FastImage}
186-
isMessageAIGenerated={(message: MessageType) => message.ai_generated}
186+
isMessageAIGenerated={(message: MessageType) => !!message.ai_generated}
187187
>
188188
<AppOverlayProvider>
189189
<UserSearchProvider>

package/src/components/ImageGallery/components/ImageGalleryFooter.tsx

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import {
2121
VideoType,
2222
} from '../../../native';
2323

24+
const ReanimatedSafeAreaView = Animated.createAnimatedComponent
25+
? Animated.createAnimatedComponent(SafeAreaView)
26+
: SafeAreaView;
27+
2428
import { DefaultStreamChatGenerics, FileTypes } from '../../../types/types';
2529
import type { Photo } from '../ImageGallery';
2630

@@ -154,28 +158,26 @@ export const ImageGalleryFooterWithContext = <
154158
};
155159

156160
return (
157-
<SafeAreaView
161+
<Animated.View
158162
accessibilityLabel={accessibilityLabel}
159163
onLayout={(event) => setHeight(event.nativeEvent.layout.height)}
160164
pointerEvents={'box-none'}
161165
style={styles.wrapper}
162166
>
163-
<Animated.View style={footerStyle}>
164-
<View style={[{ backgroundColor: white }, container]}>
165-
{photo.type === FileTypes.Video ? (
166-
videoControlElement ? (
167-
videoControlElement({ duration, onPlayPause, paused, progress, videoRef })
168-
) : (
169-
<ImageGalleryVideoControl
170-
duration={duration}
171-
onPlayPause={onPlayPause}
172-
paused={paused}
173-
progress={progress}
174-
videoRef={videoRef}
175-
/>
176-
)
177-
) : null}
178-
</View>
167+
<ReanimatedSafeAreaView style={[{ backgroundColor: white }, footerStyle, container]}>
168+
{photo.type === FileTypes.Video ? (
169+
videoControlElement ? (
170+
videoControlElement({ duration, onPlayPause, paused, progress, videoRef })
171+
) : (
172+
<ImageGalleryVideoControl
173+
duration={duration}
174+
onPlayPause={onPlayPause}
175+
paused={paused}
176+
progress={progress}
177+
videoRef={videoRef}
178+
/>
179+
)
180+
) : null}
179181
<View style={[styles.innerContainer, { backgroundColor: white }, innerContainer]}>
180182
{leftElement ? (
181183
leftElement({ openGridView, photo, share, shareMenuOpen })
@@ -204,8 +206,8 @@ export const ImageGalleryFooterWithContext = <
204206
</TouchableOpacity>
205207
)}
206208
</View>
207-
</Animated.View>
208-
</SafeAreaView>
209+
</ReanimatedSafeAreaView>
210+
</Animated.View>
209211
);
210212
};
211213

package/src/components/ImageGallery/components/ImageGalleryHeader.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import type { DefaultStreamChatGenerics } from '../../../types/types';
1616
import { getDateString } from '../../../utils/i18n/getDateString';
1717
import type { Photo } from '../ImageGallery';
1818

19+
const ReanimatedSafeAreaView = Animated.createAnimatedComponent
20+
? Animated.createAnimatedComponent(SafeAreaView)
21+
: SafeAreaView;
22+
1923
export type ImageGalleryHeaderCustomComponent<
2024
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
2125
> = ({
@@ -58,6 +62,7 @@ export const ImageGalleryHeader = <
5862
centerContainer,
5963
container,
6064
dateText,
65+
innerContainer,
6166
leftContainer,
6267
rightContainer,
6368
usernameText,
@@ -93,12 +98,12 @@ export const ImageGalleryHeader = <
9398
};
9499

95100
return (
96-
<SafeAreaView
101+
<View
97102
onLayout={(event) => setHeight(event.nativeEvent.layout.height)}
98103
pointerEvents={'box-none'}
99104
>
100-
<Animated.View style={headerStyle}>
101-
<View style={[styles.container, { backgroundColor: white }, container]}>
105+
<ReanimatedSafeAreaView style={[{ backgroundColor: white }, headerStyle, container]}>
106+
<View style={[styles.innerContainer, innerContainer]}>
102107
{leftElement ? (
103108
leftElement({ hideOverlay, photo })
104109
) : (
@@ -124,8 +129,8 @@ export const ImageGalleryHeader = <
124129
<View style={[styles.rightContainer, rightContainer]} />
125130
)}
126131
</View>
127-
</Animated.View>
128-
</SafeAreaView>
132+
</ReanimatedSafeAreaView>
133+
</View>
129134
);
130135
};
131136

@@ -137,16 +142,16 @@ const styles = StyleSheet.create({
137142
flex: 1,
138143
justifyContent: 'center',
139144
},
140-
container: {
141-
flexDirection: 'row',
142-
justifyContent: 'space-between',
143-
paddingVertical: 8,
144-
},
145145
date: {
146146
fontSize: 12,
147147
fontWeight: '500',
148148
opacity: 0.5,
149149
},
150+
innerContainer: {
151+
flexDirection: 'row',
152+
justifyContent: 'space-between',
153+
paddingVertical: 8,
154+
},
150155
leftContainer: {
151156
flex: 1,
152157
justifyContent: 'center',

package/src/contexts/themeContext/utils/theme.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ export type Theme = {
226226
centerContainer: ViewStyle;
227227
container: ViewStyle;
228228
dateText: TextStyle;
229+
innerContainer: ViewStyle;
229230
leftContainer: ViewStyle;
230231
rightContainer: ViewStyle;
231232
usernameText: TextStyle;
@@ -983,6 +984,7 @@ export const defaultTheme: Theme = {
983984
centerContainer: {},
984985
container: {},
985986
dateText: {},
987+
innerContainer: {},
986988
leftContainer: {},
987989
rightContainer: {},
988990
usernameText: {},

0 commit comments

Comments
 (0)