Skip to content

Commit c27a218

Browse files
authored
fix: change old gesture handler useAnimatedGestureHandler to the new API (#2563)
* feat: configure ReactionList reaction theme (#2561) * fix: expo sample app keyboardVerticalOffset for channel and thread screen * fix: change old gesture handler useAnimatedGestureHandler to the new API
1 parent 87593c3 commit c27a218

File tree

13 files changed

+654
-722
lines changed

13 files changed

+654
-722
lines changed

package/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
"moment": "2.29.2",
142142
"prettier": "2.8.8",
143143
"react": "18.2.0",
144-
"react-docgen-typescript": "1.22.0",
145144
"react-dom": "18.2.0",
146145
"react-native": "0.73.6",
147146
"react-native-builder-bob": "0.23.1",

package/src/components/ImageGallery/ImageGallery.tsx

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
import React, { useEffect, useRef, useState } from 'react';
2-
import { Image, ImageStyle, Keyboard, Platform, StyleSheet, ViewStyle } from 'react-native';
2+
import { Image, ImageStyle, Keyboard, StyleSheet, ViewStyle } from 'react-native';
33

4-
import {
5-
PanGestureHandler,
6-
PinchGestureHandler,
7-
TapGestureHandler,
8-
} from 'react-native-gesture-handler';
4+
import { GestureDetector } from 'react-native-gesture-handler';
95

106
import Animated, {
117
Easing,
@@ -41,10 +37,7 @@ import {
4137
import { useImageGalleryGestures } from './hooks/useImageGalleryGestures';
4238

4339
import { useImageGalleryContext } from '../../contexts/imageGalleryContext/ImageGalleryContext';
44-
import {
45-
OverlayProviderProps,
46-
useOverlayContext,
47-
} from '../../contexts/overlayContext/OverlayContext';
40+
import { OverlayProviderProps } from '../../contexts/overlayContext/OverlayContext';
4841
import { useTheme } from '../../contexts/themeContext/ThemeContext';
4942
import { useViewport } from '../../hooks/useViewport';
5043
import { isVideoPackageAvailable, VideoType } from '../../native';
@@ -53,8 +46,6 @@ import { getResizedImageUrl } from '../../utils/getResizedImageUrl';
5346
import { getUrlOfImageAttachment } from '../../utils/getUrlOfImageAttachment';
5447
import { getGiphyMimeType } from '../Attachment/utils/getGiphyMimeType';
5548

56-
const isAndroid = Platform.OS === 'android';
57-
5849
const MARGIN = 32;
5950

6051
export enum HasPinched {
@@ -146,7 +137,6 @@ export const ImageGallery = <
146137
},
147138
} = useTheme();
148139
const [gridPhotos, setGridPhotos] = useState<Photo<StreamChatGenerics>[]>([]);
149-
const { overlay } = useOverlayContext();
150140
const { messages, selectedMessage, setSelectedMessage } =
151141
useImageGalleryContext<StreamChatGenerics>();
152142

@@ -212,14 +202,6 @@ export const ImageGallery = <
212202
*/
213203
const headerFooterVisible = useSharedValue(1);
214204

215-
/**
216-
* Gesture handler refs
217-
*/
218-
const doubleTapRef = useRef<TapGestureHandler>(null);
219-
const panRef = useRef<PanGestureHandler>(null);
220-
const pinchRef = useRef<PinchGestureHandler>(null);
221-
const singleTapRef = useRef<TapGestureHandler>(null);
222-
223205
/**
224206
* Shared values for movement
225207
*/
@@ -353,7 +335,7 @@ export const ImageGallery = <
353335
}
354336
}, [uriForCurrentImage]);
355337

356-
const { onDoubleTap, onPan, onPinch, onSingleTap } = useImageGalleryGestures({
338+
const { doubleTap, pan, pinch, singleTap } = useImageGalleryGestures({
357339
currentImageHeight,
358340
halfScreenHeight,
359341
halfScreenWidth,
@@ -518,38 +500,13 @@ export const ImageGallery = <
518500
style={[StyleSheet.absoluteFillObject, showScreenStyle]}
519501
>
520502
<Animated.View style={[StyleSheet.absoluteFillObject, containerBackground]} />
521-
<TapGestureHandler
522-
minPointers={1}
523-
numberOfTaps={1}
524-
onGestureEvent={onSingleTap}
525-
ref={singleTapRef}
526-
waitFor={[panRef, pinchRef, doubleTapRef]}
527-
>
503+
<GestureDetector gesture={singleTap}>
528504
<Animated.View style={StyleSheet.absoluteFillObject}>
529-
<TapGestureHandler
530-
maxDeltaX={8}
531-
maxDeltaY={8}
532-
maxDist={8}
533-
minPointers={1}
534-
numberOfTaps={2}
535-
onGestureEvent={onDoubleTap}
536-
ref={doubleTapRef}
537-
>
505+
<GestureDetector gesture={doubleTap}>
538506
<Animated.View style={StyleSheet.absoluteFillObject}>
539-
<PinchGestureHandler
540-
onGestureEvent={onPinch}
541-
ref={pinchRef}
542-
simultaneousHandlers={[panRef]}
543-
>
507+
<GestureDetector gesture={pinch}>
544508
<Animated.View style={StyleSheet.absoluteFill}>
545-
<PanGestureHandler
546-
enabled={overlay === 'gallery'}
547-
maxPointers={isAndroid ? undefined : 1}
548-
minDist={10}
549-
onGestureEvent={onPan}
550-
ref={panRef}
551-
simultaneousHandlers={[pinchRef]}
552-
>
509+
<GestureDetector gesture={pan}>
553510
<Animated.View style={StyleSheet.absoluteFill}>
554511
<Animated.View style={[styles.animatedContainer, pagerStyle, pager]}>
555512
{imageGalleryAttachments.map((photo, i) =>
@@ -609,13 +566,13 @@ export const ImageGallery = <
609566
)}
610567
</Animated.View>
611568
</Animated.View>
612-
</PanGestureHandler>
569+
</GestureDetector>
613570
</Animated.View>
614-
</PinchGestureHandler>
571+
</GestureDetector>
615572
</Animated.View>
616-
</TapGestureHandler>
573+
</GestureDetector>
617574
</Animated.View>
618-
</TapGestureHandler>
575+
</GestureDetector>
619576
<ImageGalleryHeader<StreamChatGenerics>
620577
opacity={headerFooterOpacity}
621578
photo={imageGalleryAttachments[selectedIndex]}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState } from 'react';
22
import { SafeAreaView, StyleSheet, Text, TouchableOpacity, View, ViewStyle } from 'react-native';
3-
import Animated, { Extrapolate, interpolate, useAnimatedStyle } from 'react-native-reanimated';
3+
import Animated, { Extrapolation, interpolate, useAnimatedStyle } from 'react-native-reanimated';
44

55
import { ImageGalleryVideoControl } from './ImageGalleryVideoControl';
66

@@ -148,7 +148,7 @@ export const ImageGalleryFooterWithContext = <
148148
opacity: opacity.value,
149149
transform: [
150150
{
151-
translateY: interpolate(visible.value, [0, 1], [height, 0], Extrapolate.CLAMP),
151+
translateY: interpolate(visible.value, [0, 1], [height, 0], Extrapolation.CLAMP),
152152
},
153153
],
154154
}),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useMemo, useState } from 'react';
22
import { Pressable, SafeAreaView, StyleSheet, Text, View, ViewStyle } from 'react-native';
3-
import Animated, { Extrapolate, interpolate, useAnimatedStyle } from 'react-native-reanimated';
3+
import Animated, { Extrapolation, interpolate, useAnimatedStyle } from 'react-native-reanimated';
44

55
import { useOverlayContext } from '../../../contexts/overlayContext/OverlayContext';
66
import { useTheme } from '../../../contexts/themeContext/ThemeContext';
@@ -114,7 +114,7 @@ export const ImageGalleryHeader = <
114114
opacity: opacity.value,
115115
transform: [
116116
{
117-
translateY: interpolate(visible.value, [0, 1], [-height, 0], Extrapolate.CLAMP),
117+
translateY: interpolate(visible.value, [0, 1], [-height, 0], Extrapolation.CLAMP),
118118
},
119119
],
120120
}));

0 commit comments

Comments
 (0)