I’ve got a ScrollView nested in an absolute positioned View that is bigger then it’s parent. The scrolling works fine if I press inside that parent, but when I go outside it, it’s not handling the touches. How can I get around this?
I can’t scroll if I touch the screen below the green line.
Code to reproduce:
<View style={{flex: 1, justifyContent: "center", alignItems: "center"}}>
<View style={{width: "80%", height: 150, borderWidth: 1}}>
<View style={{position: 'absolute', height: 400, width: "80%", backgroundColor: "green", alignSelf: "center"}}>
<ScrollView>
<View style={{height: 200, backgroundColor: "red"}} />
<View style={{height: 200, backgroundColor: "blue"}} />
<View style={{height: 200, backgroundColor: "yellow"}} />
</ScrollView>
</View>
</View>
</View>
Expo Snack: https://snack.expo.dev/uV88qpP7f (Happens on android)
5
Answers
You can do this
Best way I found was to move the ScrollView outside of the card container and get the top position of the ScrollView by calculating the area of the button and container it’s supposed to be relating to. Sort of how tooltips often function.
I moved your example to a FlatList as it seems like that was what you were hoping to do in the example.
Here’s the snack https://snack.expo.dev/@corywritescode/frowning-carrot
Issue is with your approach to design. You can achieve the desire functionality with same design by following code.
Demo
https://snack.expo.dev/bsHCCB1_l
Try declaring your
Box
above the scroll view otherwise the touch area belowBox
won’t workScrollView
with Position absolute should be below to Box to make touch in workCode
Absolute position style causes this problem. I just remove it and set new style above.