-
Notifications
You must be signed in to change notification settings - Fork 424
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
nested ScrollView is not working inside PagerView #848
Comments
Any update guys ?? |
same problem +1 |
I have the same issue +1 |
👀 |
Please provide a repro repo. |
same issue |
same issue + 1. is there any ways to solve this problem? now i have to nested a ScrollView with props horizontal and pagingEnabled rather than use the PagerView |
Not ideal but you can implement a workaround using a Here is an example of what I mean by that: import { View, StyleSheet, Dimensions } from "react-native";
import PagerView from "react-native-pager-view";
import { Gesture, GestureDetector } from "react-native-gesture-handler";
import Animated, {
useSharedValue,
useAnimatedScrollHandler,
type SharedValue,
useAnimatedProps,
} from "react-native-reanimated";
const ScreenWidth = Dimensions.get("window").width;
const ScrollableContainer = () => {
const translateY = useSharedValue(0);
const handleScroll = useAnimatedScrollHandler((event) => {
translateY.set(event.contentOffset.y);
});
return (
<Animated.ScrollView
style={styles.scrollView}
onScroll={handleScroll}
scrollEventThrottle={16}
animatedProps={useAnimatedProps(() => ({
contentOffset: { x: 0, y: translateY.get() },
}))}
>
{Array.from({ length: 5 }, (_, index) => (
<View style={styles.pageContainer} key={index.toString()}>
<Pager translateY={translateY} />
</View>
))}
</Animated.ScrollView>
);
};
type PagerProps = { translateY: SharedValue<number> };
const Pager = ({ translateY }: PagerProps) => {
const initialOffset = useSharedValue(0);
const gesture = Gesture.Pan()
.onStart(() => {
initialOffset.set(translateY.value);
})
.onUpdate((e) => {
translateY.set(Math.max(initialOffset.get() - e.translationY, 0));
});
return (
<GestureDetector gesture={gesture}>
<AnimatedPagerView
style={styles.pagerView}
initialPage={0}
orientation="horizontal"
overScrollMode="never"
>
<View style={[styles.page, { backgroundColor: "red" }]} />
<View style={[styles.page, { backgroundColor: "green" }]} />
<View style={[styles.page, { backgroundColor: "blue" }]} />
</AnimatedPagerView>
</GestureDetector>
);
};
const AnimatedPagerView = Animated.createAnimatedComponent(PagerView);
const styles = StyleSheet.create({
scrollView: {
flex: 1,
backgroundColor: "#f8f8f8",
},
pageContainer: {
height: 300,
marginVertical: 10,
},
pagerView: {
flex: 1,
width: ScreenWidth,
},
page: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
});
export default ScrollableContainer; Hope that helped 🤷♂️ |
Nested scrollView is not working when I try to show the products inside pagerView as a nested. If I give the height of the pagerView, like 3000, then it scrolls; otherwise, it does not scroll, but other Views become also 3000. How can I fix this issue?
The text was updated successfully, but these errors were encountered: