-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix withDecay rubberBandFactor
on Web
#4270
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
piaskowyk
approved these changes
Mar 24, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
馃憤
kacperkapusciak
added a commit
that referenced
this pull request
May 17, 2023
## Summary In #4270 withDecay rubberBandFactor got fixed on the Web with a fix where velocity got multiplied by `1000` to overcome an issue present in RNGH. This got addressed in software-mansion/react-native-gesture-handler#2443 and released in Gesture Handler 2.10 thus making the fix unnecessary. ## Recordings ### Before with RNGH 2.10 https://github.com/software-mansion/react-native-reanimated/assets/39658211/3caf7961-3f0e-4a00-9889-18da33dbfd32 ### After with RNGH 2.10 https://github.com/software-mansion/react-native-reanimated/assets/39658211/2ca02d9f-bfd6-4e13-83c2-aaa6312e8e6a ## Test plan Run this snippet in WebExample <details open> <summary>Code example</summary> ```jsx import React from 'react'; import {StyleSheet, View} from 'react-native'; import Animated, { useAnimatedStyle, useSharedValue, withDecay, } from 'react-native-reanimated'; import { Gesture, GestureDetector, GestureHandlerRootView, } from 'react-native-gesture-handler'; const SIZE = 120; export default function App() { const offset = useSharedValue(0); const width = useSharedValue(0); const onLayout = event => { width.value = event.nativeEvent.layout.width; }; const pan = Gesture.Pan() .onChange(event => { // highlight-next-line offset.value += event.changeX; }) .onFinalize(event => { // highlight-start offset.value = withDecay({ velocity: event.velocityX, rubberBandEffect: true, clamp: [-(width.value / 2) + SIZE / 2, width.value / 2 - SIZE / 2], }); // highlight-end }); const animatedStyles = useAnimatedStyle(() => ({ transform: [{translateX: offset.value}], })); return ( <GestureHandlerRootView style={styles.container}> <View onLayout={onLayout} style={styles.wrapper}> <GestureDetector gesture={pan}> <Animated.View style={[styles.box, animatedStyles]} /> </GestureDetector> </View> </GestureHandlerRootView> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', height: '100%', }, wrapper: { flex: 1, width: '100%', alignItems: 'center', justifyContent: 'center', }, box: { height: SIZE, width: SIZE, backgroundColor: '#b58df1', borderRadius: 20, cursor: 'grab', alignItems: 'center', justifyContent: 'center', }, }); ``` </details>
fluiddot
pushed a commit
to wordpress-mobile/react-native-reanimated
that referenced
this pull request
Jun 5, 2023
## Summary This PR fixes an issue where rubberBandFactor on Web was handled by factor of 1000x and patch for "pixels-per-second" issue on Web for that was only applied on default config. ### Before When `rubberBandEffect: true` is provided a box handled with gesture shoots to the moon 馃殌 https://user-images.githubusercontent.com/39658211/227472276-6bcec45b-75cf-4696-a5fc-34e39aae6b44.mov ### After After this fix it behaves nicely 馃槑 https://user-images.githubusercontent.com/39658211/227474684-cbdbecdc-e1cc-4f42-b364-94cdbac83887.mov ## Test plan Run this snippet both in `WebExample/`: ```javascript import { StyleSheet, View } from 'react-native'; import Animated, { useAnimatedStyle, useSharedValue, withDecay, } from 'react-native-reanimated'; import { Gesture, GestureDetector, GestureHandlerRootView, } from 'react-native-gesture-handler'; export default function App() { const offset = useSharedValue(0); const pan = Gesture.Pan() .onChange((event) => { offset.value += event.changeY; }) .onFinalize((event) => { offset.value = withDecay({ velocity: event.velocityY, clamp: [-200, 200], rubberBandFactor: 0.7, rubberBandEffect: true, }); }); const animatedStyles = useAnimatedStyle(() => ({ transform: [{ translateY: offset.value }], })); return ( <GestureHandlerRootView style={styles.container}> <View style={styles.container}> <GestureDetector gesture={pan}> <Animated.View style={[styles.box, animatedStyles]} /> </GestureDetector> </View> </GestureHandlerRootView> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', height: '100%', }, box: { height: 120, width: 120, backgroundColor: '#001A72', borderRadius: 20, cursor: 'grab', }, }); ```
fluiddot
pushed a commit
to wordpress-mobile/react-native-reanimated
that referenced
this pull request
Jun 5, 2023
## Summary In software-mansion#4270 withDecay rubberBandFactor got fixed on the Web with a fix where velocity got multiplied by `1000` to overcome an issue present in RNGH. This got addressed in software-mansion/react-native-gesture-handler#2443 and released in Gesture Handler 2.10 thus making the fix unnecessary. ## Recordings ### Before with RNGH 2.10 https://github.com/software-mansion/react-native-reanimated/assets/39658211/3caf7961-3f0e-4a00-9889-18da33dbfd32 ### After with RNGH 2.10 https://github.com/software-mansion/react-native-reanimated/assets/39658211/2ca02d9f-bfd6-4e13-83c2-aaa6312e8e6a ## Test plan Run this snippet in WebExample <details open> <summary>Code example</summary> ```jsx import React from 'react'; import {StyleSheet, View} from 'react-native'; import Animated, { useAnimatedStyle, useSharedValue, withDecay, } from 'react-native-reanimated'; import { Gesture, GestureDetector, GestureHandlerRootView, } from 'react-native-gesture-handler'; const SIZE = 120; export default function App() { const offset = useSharedValue(0); const width = useSharedValue(0); const onLayout = event => { width.value = event.nativeEvent.layout.width; }; const pan = Gesture.Pan() .onChange(event => { // highlight-next-line offset.value += event.changeX; }) .onFinalize(event => { // highlight-start offset.value = withDecay({ velocity: event.velocityX, rubberBandEffect: true, clamp: [-(width.value / 2) + SIZE / 2, width.value / 2 - SIZE / 2], }); // highlight-end }); const animatedStyles = useAnimatedStyle(() => ({ transform: [{translateX: offset.value}], })); return ( <GestureHandlerRootView style={styles.container}> <View onLayout={onLayout} style={styles.wrapper}> <GestureDetector gesture={pan}> <Animated.View style={[styles.box, animatedStyles]} /> </GestureDetector> </View> </GestureHandlerRootView> ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', height: '100%', }, wrapper: { flex: 1, width: '100%', alignItems: 'center', justifyContent: 'center', }, box: { height: SIZE, width: SIZE, backgroundColor: '#b58df1', borderRadius: 20, cursor: 'grab', alignItems: 'center', justifyContent: 'center', }, }); ``` </details>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes an issue where rubberBandFactor on Web was handled by factor of 1000x and patch for "pixels-per-second" issue on Web for that was only applied on default config.
Before
When
rubberBandEffect: true
is provided a box handled with gesture shoots to the moon 馃殌Screen.Recording.2023-03-24.at.09.56.48.mov
After
After this fix it behaves nicely 馃槑
Screen.Recording.2023-03-24.at.10.07.04.mov
Test plan
Run this snippet both in
WebExample/
: