-
-
Notifications
You must be signed in to change notification settings - Fork 988
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
Change how velocity is calculated on the new web implementation #2443
Conversation
if (index < 0) { | ||
index += this.bufferSize; | ||
} | ||
|
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.
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.
Why?
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.
idk, this is the only newline in all methods and it looks kinda redundant
Co-authored-by: Tomek Zawadzki <tomekzawadzki98@gmail.com>
## 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>
## 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>
…400) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [react-native-gesture-handler](https://togithub.com/software-mansion/react-native-gesture-handler) | [`~2.9.0` -> `~2.11.0`](https://renovatebot.com/diffs/npm/react-native-gesture-handler/2.9.0/2.11.0) | [![age](https://badges.renovateapi.com/packages/npm/react-native-gesture-handler/2.11.0/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/npm/react-native-gesture-handler/2.11.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/npm/react-native-gesture-handler/2.11.0/compatibility-slim/2.9.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/npm/react-native-gesture-handler/2.11.0/confidence-slim/2.9.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>software-mansion/react-native-gesture-handler</summary> ### [`v2.11.0`](https://togithub.com/software-mansion/react-native-gesture-handler/releases/tag/2.11.0) [Compare Source](https://togithub.com/software-mansion/react-native-gesture-handler/compare/2.10.2...2.11.0) A small release made for nice people at Expo 😃. #### 🐛 Bug fixes - Correctly attach root view recognizer in modals on iOS by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2498](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2498) **Full Changelog**: software-mansion/react-native-gesture-handler@2.10.2...2.11.0 ### [`v2.10.2`](https://togithub.com/software-mansion/react-native-gesture-handler/releases/tag/2.10.2) [Compare Source](https://togithub.com/software-mansion/react-native-gesture-handler/compare/2.10.1...2.10.2) #### 🐛 Bug fixes - Fix root view error for jest by [@​IvanIhnatsiuk](https://togithub.com/IvanIhnatsiuk) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2491](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2491) - Prevent GH buttons from activating when scrolling list by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2494](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2494) #### New Contributors - [@​IvanIhnatsiuk](https://togithub.com/IvanIhnatsiuk) made their first contribution in [https://github.com/software-mansion/react-native-gesture-handler/pull/2491](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2491) **Full Changelog**: software-mansion/react-native-gesture-handler@2.10.1...2.10.2 ### [`v2.10.1`](https://togithub.com/software-mansion/react-native-gesture-handler/releases/tag/2.10.1) [Compare Source](https://togithub.com/software-mansion/react-native-gesture-handler/compare/2.10.0...2.10.1) #### 🐛 Bug fixes - Fix operation scheduling on iOS by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2483](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2483) ### [`v2.10.0`](https://togithub.com/software-mansion/react-native-gesture-handler/releases/tag/2.10.0) [Compare Source](https://togithub.com/software-mansion/react-native-gesture-handler/compare/2.9.0...2.10.0) #### ❗ Important changes - Enable the new web implementation by default by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2394](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2394) - Replace `setImmediate` and `requestAnimationFrame` with `queueMicrotask` by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2467](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2467) - Show error when gestures are used without root view by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2420](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2420) - Change how velocity is calculated on the new web implementation by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2443](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2443) #### 🐛 Bug fixes - Fix types for gestureHandlerRootHOC to accept component with props by [@​Nodonisko](https://togithub.com/Nodonisko) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2413](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2413) - Remove `DrawerLayoutAndroid` import on web by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2305](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2305) - Fix ripple always showing on Touchables when on Android 13 by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2418](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2418) - Whitelist `Native` gesture props in `GestureDetector` by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2433](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2433) - Fix Gesture Handlers getting stuck due to missing `up` event when using the new web implementation by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2442](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2442) - Fix Gesture Handler's buttons activating after scroll when using `RefreshControl` by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2457](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2457) - Make single instance assertion work with Gradle Configuration Cache by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2453](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2453) - fix: PureNativeButton is not exported by [@​magrinj](https://togithub.com/magrinj) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2447](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2447) - fix: do not apply namespace if it is not available in agp by [@​WoLewicki](https://togithub.com/WoLewicki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2448](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2448) #### 👍 Improvements - Returns Swipeable reference on renderLeftActions by [@​ntocampos](https://togithub.com/ntocampos) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2426](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2426) - Add a method `reset` to component `Swipeable` by [@​UNIDY2002](https://togithub.com/UNIDY2002) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2431](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2431) - Remove conditional imports for native components by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2461](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2461) - Add `dragOffsetFromLeftEdge` and `dragOffsetFromRightEdge` props to `Swipeable` by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2408](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2408) #### 🔢 Miscellaneous - Bump ua-parser-js from 0.7.31 to 0.7.33 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2392](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2392) - Bump ua-parser-js from 0.7.24 to 0.7.33 in /docs by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2389](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2389) - Hide `back-to-top` button in the docs by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2398](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2398) - Upgrade Expo in the example app to use API 47 by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2393](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2393) - chore: change fabric flag by [@​WoLewicki](https://togithub.com/WoLewicki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2397](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2397) - Bump http-cache-semantics from 4.1.0 to 4.1.1 in /docs by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2407](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2407) - Bump http-cache-semantics from 4.1.0 to 4.1.1 by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2406](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2406) - End-to-end tests for web version by [@​m-bert](https://togithub.com/m-bert) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2298](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2298) - Bump ua-parser-js from 0.7.32 to 0.7.33 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2417](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2417) - Bump loader-utils from 1.4.0 to 1.4.2 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2416](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2416) - Bump decode-uri-component from 0.2.0 to 0.2.2 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2415](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2415) - Add `Handler state` section to sidebar by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2422](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2422) - Bump webpack from 5.73.0 to 5.76.1 in /docs by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2436](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2436) - chore: set library namespace in build script by [@​kkafar](https://togithub.com/kkafar) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2435](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2435) - docs: add appjs banner by [@​kacperkapusciak](https://togithub.com/kacperkapusciak) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2432](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2432) - Bump [@​xmldom/xmldom](https://togithub.com/xmldom/xmldom) from 0.7.6 to 0.7.9 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2444](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2444) - Bump [@​sideway/formula](https://togithub.com/sideway/formula) from 3.0.0 to 3.0.1 in /e2e/web-tests by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2445](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2445) - Bump minimist from 1.2.5 to 1.2.8 in /example by [@​dependabot](https://togithub.com/dependabot) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2456](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2456) - Move `GestureHandlerRootView` to `components` directory by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2468](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2468) - Remove unnecessary `throw` by [@​j-piasecki](https://togithub.com/j-piasecki) in [https://github.com/software-mansion/react-native-gesture-handler/pull/2446](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2446) #### New Contributors - [@​Nodonisko](https://togithub.com/Nodonisko) made their first contribution in [https://github.com/software-mansion/react-native-gesture-handler/pull/2413](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2413) - [@​ntocampos](https://togithub.com/ntocampos) made their first contribution in [https://github.com/software-mansion/react-native-gesture-handler/pull/2426](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2426) - [@​UNIDY2002](https://togithub.com/UNIDY2002) made their first contribution in [https://github.com/software-mansion/react-native-gesture-handler/pull/2431](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2431) - [@​magrinj](https://togithub.com/magrinj) made their first contribution in [https://github.com/software-mansion/react-native-gesture-handler/pull/2447](https://togithub.com/software-mansion/react-native-gesture-handler/pull/2447) **Full Changelog**: software-mansion/react-native-gesture-handler@2.9.0...2.10.0 </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/dooboolab-community/dooboo-ui). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMTAuMCIsInVwZGF0ZWRJblZlciI6IjM1LjExMC4wIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9--> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Description
Changes how pointer velocity is calculated on the web. Previously, it was using only the last two events which wasn't the best solution as the speed of the pointer just before it's released may not represent the speed of the swipe.
This changes it to be calculated using the same algorithm as Flutter.
Test plan
Use the
Velocity test
example added to the app