Replies: 2 comments 5 replies
-
We're also interested in this over at the https://github.com/PedroBern/react-native-collapsible-tab-view/ library. See the GIFs in the Readme for an overview. To clarify, we're overlaying a View on top of a scrollview to provide as the header. When the scrollview scrolls, we move the header up. However, some users would like to be able to scroll from the header, or have a horizontal scrollview inside the header. There is a hacky PR here that attempts to fix this: PedroBern/react-native-collapsible-tab-view#254 by basically sending simulated scroll events to the underlying scrollview but it's not ideal and doesn't handle all cases. (cc @tiagocorreiaalmeida) Any ideas if this is possible to do with rngh? (sorry for the ping, but perhaps you can share some insight @j-piasecki) |
Beta Was this translation helpful? Give feedback.
-
Is this close to the behavior you want to achieve? pointerevents.mp4Here's the code for it: Pointer events exampleimport React, { useState } from 'react';
import { StyleSheet, View, Button } from 'react-native';
import {
GestureDetector,
Gesture,
ScrollView,
TouchableOpacity,
} from 'react-native-gesture-handler';
import Animated, {
useAnimatedStyle,
useSharedValue,
} from 'react-native-reanimated';
function Spacer(props: { color: string }) {
return (
<View
style={{
backgroundColor: props.color,
width: 200,
height: 200,
margin: 15,
}}
/>
);
}
export default function Test() {
const [dragEnabled, setDragEnabled] = useState(true);
const x = useSharedValue(0);
const y = useSharedValue(0);
const gesture = Gesture.Pan()
.onChange((e) => {
x.value += e.changeX;
y.value += e.changeY;
})
.enabled(dragEnabled);
const style = useAnimatedStyle(() => ({
transform: [{ translateX: x.value }, { translateY: y.value }],
}));
return (
<View style={{ flex: 1 }}>
<ScrollView
style={{ flex: 1 }}
contentContainerStyle={{ alignItems: 'center' }}>
<Spacer color="green" />
<Spacer color="yellow" />
<Button
title={dragEnabled ? 'Disable drag' : 'Enable drag'}
onPress={() => {
setDragEnabled(!dragEnabled);
}}
/>
<Spacer color="green" />
<Spacer color="yellow" />
</ScrollView>
<View
style={{ ...StyleSheet.absoluteFillObject }}
pointerEvents={'box-none'}>
<GestureDetector gesture={gesture}>
<Animated.View
pointerEvents={dragEnabled ? 'auto' : 'box-none'}
style={[
{
backgroundColor: 'red',
width: 200,
height: 100,
justifyContent: 'center',
alignItems: 'center',
},
style,
]}>
<TouchableOpacity>
<View
style={{ backgroundColor: 'blue', width: 100, height: 50 }}
/>
</TouchableOpacity>
</Animated.View>
</GestureDetector>
</View>
</View>
);
} As for your question @andreialecu, If the header is above the scroll view, then setting |
Beta Was this translation helpful? Give feedback.
-
Consider the following scene:
I am setting up gesture handlers in such a way as to achieve the following requirements:
a. Drag events are no longer handled, and should "fall through" to the ScrollView for scrolling. (it's okay if this only applies to new gestures)
I am struggling to achieve the points 2a and 3 at the same time. Setting
pointerEvents="none"
on the box causes the events to fall through onto the ScrollView. However, it also prevents the content inside the box from receiving tap gestures. And while simply disabling the gesture stops the pan events, they do not fall through onto the ScrollView.Is there some approach where I can allow certain gestures (pan) to fall through to outside components, while still capturing some other types of gestures (tap)?
Beta Was this translation helpful? Give feedback.
All reactions