I have a Swipable button inside a ScrollVIew, when i press the button or swipe it , i want to disable vertical ScrollView behaviour so i have more conroll over the view and gives the user more control on the swipe left or right action he wants to achieve.

I also tried to use this functions:

  const disableVerticalScroll = () => {
     if (Platform.OS === "ios") {
       scrollViewRef.current.setNativeProps({ scrollEnabled: false });
    } else {
       scrollViewRef.current.setNativeProps({ scrollEnabled: true });
     }
   };

   const enableVerticalScroll = () => {
     if (Platform.OS === "ios") {
       scrollViewRef.current.setNativeProps({ scrollEnabled: true });
     } else {
       scrollViewRef.current.setNativeProps({ scrollEnabled: false });
     }
   };

And use a PenGestureHandler that wraps the whole ScrollView but still the same effect: 

<PanGestureHandler
          onGestureEvent={({ nativeEvent }) => {
            // Disable vertical scrolling if the swipeable button is being swiped
            if (nativeEvent.translationX !== 0) {
              disableVerticalScroll();
            } else {
              enableVerticalScroll();
            }
          }}
          onHandlerStateChange={({ nativeEvent }) => {
            // Enable vertical scrolling when the swipeable button is released
            if (nativeEvent.state === State.END) {
              enableVerticalScroll();
            }
          }}
          activeOffsetX={[-20, 20]}
          >

Thanks in advance!

0

There are 0 best solutions below