You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to figure out how to prevent vertical scrolling inside of a ScrollView. I've been following many of @Gaeron's post (below) and while I believe his scenarios have been fixed, I still think there's problems working with a WebView:
I've upgraded to 2.22.0 after reading an issue about how WebView panning has been fixed in native (which it has!) but I'm still struggling to figure this scenario out:
But that didn't do anything, on the contrary, it stopped the Webview from working as well. I created this Snack that includes what I'm trying to get done but no variation of these seems to help:
Ultimately, this is what I came up with. It works but I feel like I should be able to do this using the gesture responder exclusively. Am I wrong? Any help would be appreciated. Thank you!
functionPanningWebviewExample(){constscrollViewRef=useRef<ScrollView>(null);constwebview=Gesture.Native().shouldActivateOnStart(true).disallowInterruption(true);// Function to handle scrollingconsthandleScroll=(translationY: number)=>{if(scrollViewRef.current){scrollViewRef.current.scrollTo({y: 420,animated: true,});}};constpan=Gesture.Pan().maxPointers(2).onUpdate((event)=>{"worklet";const{ translationY, translationX, velocityY, velocityX }=event;// Minimum vertical movement required (in points)constVERTICAL_THRESHOLD=30;// Ratio of vertical to horizontal movement required// Higher = more vertical movement needed compared to horizontalconstVERTICAL_RATIO_THRESHOLD=3;// Minimum velocity for the gesture (points per second)constVELOCITY_THRESHOLD=300;constverticalRatio=Math.abs(translationY)/(Math.abs(translationX)||0.1);consthasMinimumVerticalMovement=Math.abs(translationY)>VERTICAL_THRESHOLD;constisVerticalGesture=verticalRatio>VERTICAL_RATIO_THRESHOLD;consthasSignificantVelocity=Math.abs(velocityY)>VELOCITY_THRESHOLD;constisDownward=translationY<0;if(isVerticalGesture&&hasMinimumVerticalMovement&&hasSignificantVelocity&&isDownward){runOnJS(handleScroll)(translationY);}});constgesture=Gesture.Simultaneous(webview,pan);return(<ScrollViewref={scrollViewRef}horizontal={false}bounces={true}directionalLockEnabled={true}showsVerticalScrollIndicator={false}style={{flex: 1}}contentContainerStyle={{paddingBottom: 16}}><GestureDetectorgesture={gesture}><WebViewsource={{uri: 'https://google.com'}}/></GestureDetector></ScrollView>);};
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there,
I've been trying to figure out how to prevent vertical scrolling inside of a ScrollView. I've been following many of @Gaeron's post (below) and while I believe his scenarios have been fixed, I still think there's problems working with a WebView:
I've upgraded to 2.22.0 after reading an issue about how WebView panning has been fixed in native (which it has!) but I'm still struggling to figure this scenario out:
I previously thought I could use something like
But that didn't do anything, on the contrary, it stopped the Webview from working as well. I created this Snack that includes what I'm trying to get done but no variation of these seems to help:
What am I doing wrong?
Ultimately, this is what I came up with. It works but I feel like I should be able to do this using the gesture responder exclusively. Am I wrong? Any help would be appreciated. Thank you!
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions