-
Notifications
You must be signed in to change notification settings - Fork 1.4k
chore: upgrade reanimated to v4 #6720
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
f58a536
23ec327
abab68f
1514c7e
5f28192
c0a4d25
f27e9f5
14ecf41
58b5141
a624049
00af6b8
d181c65
d3f516b
caedf9e
cbfe560
8f89ea2
65be6cf
08056fb
b4a596f
76cc834
e13c5a4
4fe2c97
64f4dd9
1dba726
caf9d5a
b0d5d9f
e3ccc64
2f535e3
3776737
7f04181
40d9fb9
f868d6d
504d378
54698cb
9ed2a82
baca611
fd97518
deb038d
6afa789
3937eec
acd8675
854b508
9feee82
b5aaff9
6413650
d0f3d39
a8cdebd
ebe4419
b054ed4
bcbc7fe
8a0d12c
02cd74f
e50f3ad
af3098d
b7c2b2f
22ff512
cc271ef
eb37e68
b5a87b7
a0a6854
ebd8f88
f4defa6
d66c812
7662c7f
88e8b42
c19cadf
7946eb4
d6a3237
6fc21de
7d1f242
301b0c3
8daab95
d23a7e0
7c02045
38cd2c9
930c88a
d0d218b
3bab462
cd35041
35b55df
50e1ffc
ec14b28
28d9062
fb40b8b
ae5df9f
fdaf544
05c7b5a
5064359
650104e
7144138
8db5f90
d3f23e7
c03938c
4e7cc2b
0e45349
dbffe97
d33a796
719c192
1e6da08
e8abcf1
8b410dc
b81a3ae
9c25b88
54c2e9d
2b3e51a
5756896
45d1292
ac20a76
cdda960
cff02b6
c48a040
cdf85b0
4ff6637
88be3cd
6bb597e
03e0ae0
a130cd1
a541660
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,20 @@ | ||
| import React from 'react'; | ||
| import { type LayoutChangeEvent, View, TextInput, type TextInputProps, TouchableNativeFeedback } from 'react-native'; | ||
| import { PanGestureHandler, type PanGestureHandlerGestureEvent } from 'react-native-gesture-handler'; | ||
| import { Gesture, GestureDetector } from 'react-native-gesture-handler'; | ||
| import Animated, { | ||
| type SharedValue, | ||
| runOnJS, | ||
| useAnimatedGestureHandler, | ||
| useAnimatedProps, | ||
| useAnimatedStyle, | ||
| useDerivedValue, | ||
| useSharedValue | ||
| useSharedValue, | ||
| withTiming | ||
| } from 'react-native-reanimated'; | ||
| import { scheduleOnRN } from 'react-native-worklets'; | ||
|
|
||
| import styles from './styles'; | ||
| import { useTheme } from '../../theme'; | ||
| import { SEEK_HIT_SLOP, THUMB_SEEK_SIZE, ACTIVE_OFFSET_X, DEFAULT_TIME_LABEL } from './constants'; | ||
|
|
||
| Animated.addWhitelistedNativeProps({ text: true }); | ||
| const AnimatedTextInput = Animated.createAnimatedComponent(TextInput); | ||
|
|
||
| interface ISeek { | ||
|
|
@@ -50,6 +49,7 @@ const Seek = ({ currentTime, duration, loaded = false, onChangeTime }: ISeek) => | |
| const timeLabel = useSharedValue(DEFAULT_TIME_LABEL); | ||
| const scale = useSharedValue(1); | ||
| const isPanning = useSharedValue(false); | ||
| const contextX = useSharedValue(0); | ||
|
|
||
| const styleLine = useAnimatedStyle(() => ({ | ||
| width: translateX.value | ||
|
|
@@ -64,21 +64,25 @@ const Seek = ({ currentTime, duration, loaded = false, onChangeTime }: ISeek) => | |
| maxWidth.value = width; | ||
| }; | ||
|
|
||
| const onGestureEvent = useAnimatedGestureHandler<PanGestureHandlerGestureEvent, { offsetX: number }>({ | ||
| onStart: (_event, ctx) => { | ||
| const panGesture = Gesture.Pan() | ||
| .enabled(loaded) | ||
| .activeOffsetX([-ACTIVE_OFFSET_X, ACTIVE_OFFSET_X]) | ||
| .onStart(() => { | ||
| isPanning.value = true; | ||
| ctx.offsetX = translateX.value; | ||
| }, | ||
| onActive: ({ translationX }, ctx) => { | ||
| translateX.value = clamp(ctx.offsetX + translationX, 0, maxWidth.value); | ||
| scale.value = 1.3; | ||
| }, | ||
| onFinish() { | ||
| scale.value = 1; | ||
| contextX.value = translateX.value; | ||
| scale.value = withTiming(1.3, { duration: 150 }); | ||
| }) | ||
| .onUpdate(event => { | ||
| const newX = contextX.value + event.translationX; | ||
| translateX.value = clamp(newX, 0, maxWidth.value); | ||
| }) | ||
| .onEnd(() => { | ||
| scheduleOnRN(onChangeTime, Math.round(currentTime.value * 1000)); | ||
Rohit3523 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }) | ||
|
Comment on lines
+67
to
+81
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cd app/containers/AudioPlayer && wc -l Seek.tsxRepository: RocketChat/Rocket.Chat.ReactNative Length of output: 90 🏁 Script executed: cat -n app/containers/AudioPlayer/Seek.tsx | head -100Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 4014 🏁 Script executed: # Search for ISeek interface definition
rg "interface ISeek" -A 10Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 743 🏁 Script executed: # Search for scheduleOnRN usage and imports
rg "scheduleOnRN" -B 2 -A 2Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 8010 🏁 Script executed: # Search for onChangeTime type definition
rg "onChangeTime" -B 2 -A 2Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 1552 Wrap the async seek callback before scheduling it. Line 80 passes 🛡️ Proposed fix+ const commitChangeTime = React.useCallback((time: number) => {
+ void onChangeTime(time).catch(() => {
+ // Route this through the existing error/reporting path.
+ });
+ }, [onChangeTime]);
+
const panGesture = Gesture.Pan()
.enabled(loaded)
.activeOffsetX([-ACTIVE_OFFSET_X, ACTIVE_OFFSET_X])
.onStart(() => {
isPanning.value = true;
contextX.value = translateX.value;
scale.value = withTiming(1.3, { duration: 150 });
})
.onUpdate(event => {
const newX = contextX.value + event.translationX;
translateX.value = clamp(newX, 0, maxWidth.value);
})
.onEnd(() => {
- scheduleOnRN(onChangeTime, Math.round(currentTime.value * 1000));
+ scheduleOnRN(commitChangeTime, Math.round(currentTime.value * 1000));
})🤖 Prompt for AI Agents |
||
| .onFinalize(() => { | ||
| isPanning.value = false; | ||
| runOnJS(onChangeTime)(Math.round(currentTime.value * 1000)); | ||
| } | ||
| }); | ||
| scale.value = withTiming(1, { duration: 150 }); | ||
| }); | ||
|
Comment on lines
+82
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "Seek.tsx" -type fRepository: RocketChat/Rocket.Chat.ReactNative Length of output: 115 🏁 Script executed: cat -n ./app/containers/AudioPlayer/Seek.tsxRepository: RocketChat/Rocket.Chat.ReactNative Length of output: 5414 🌐 Web query:
💡 Result: In react-native-gesture-handler, the Pan gesture's onFinalize callback receives a second parameter called didSucceed, which is a boolean indicating whether the gesture was successfully recognized and completed. Signature: onFinalize: (event: PanHandlerData, didSucceed: boolean) => void - didSucceed is true if the gesture reached the END state (successfully completed after being ACTIVE). - didSucceed is false if the gesture FAILED or was CANCELLED. This applies to the modern API (usePanGesture in RNGH 3.x+). The callback is called whenever the handler stops recognizing the gesture, after onDeactivate if the gesture activated. Citations:
Restore the pre-pan position when the gesture is cancelled. When a pan gesture is cancelled, 🔁 Proposed fix- .onFinalize(() => {
+ .onFinalize((_, didSucceed) => {
+ if (isPanning.value && !didSucceed) {
+ translateX.value = contextX.value;
+ currentTime.value = (contextX.value * duration.value) / maxWidth.value || 0;
+ }
isPanning.value = false;
scale.value = withTiming(1, { duration: 150 });
});🤖 Prompt for AI Agents |
||
|
|
||
| useDerivedValue(() => { | ||
| if (isPanning.value) { | ||
|
|
@@ -118,9 +122,9 @@ const Seek = ({ currentTime, duration, loaded = false, onChangeTime }: ISeek) => | |
| <View style={[styles.line, { backgroundColor: colors.strokeLight }]}> | ||
| <Animated.View style={[styles.line, styleLine, { backgroundColor: colors.buttonBackgroundPrimaryDefault }]} /> | ||
| </View> | ||
| <PanGestureHandler enabled={loaded} onGestureEvent={onGestureEvent} activeOffsetX={[-ACTIVE_OFFSET_X, ACTIVE_OFFSET_X]}> | ||
| <GestureDetector gesture={panGesture}> | ||
| <Animated.View hitSlop={SEEK_HIT_SLOP} style={[styles.thumbSeek, { backgroundColor: thumbColor }, styleThumb]} /> | ||
| </PanGestureHandler> | ||
| </GestureDetector> | ||
| </View> | ||
| </View> | ||
| </TouchableNativeFeedback> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.