How do I stop the whole page from scrolling on web? #2289
Unanswered
giacomocerquone
asked this question in
Help
Replies: 2 comments 1 reply
-
Anyone? Another way in which I could put the matter is that each converted View by react-native-web should have overflow: 'hidden' by default in order to reproduce the same behavior we have on native |
Beta Was this translation helpful? Give feedback.
0 replies
-
To ensure parity between rn.web and rn.* i've been wrapping my screens with the following component export const LayoutEncompassViewport = ({
children,
}: {
children: ReactNode;
}) => {
const { height: windowHeight, width: windowWidth } = useWindowDimensions();
return (
<View
style={{
// and set size based on window
height: windowHeight ?? '100vh',
width: windowWidth ?? '100vw',
// ensure parity between rn.web and rn.native regarding requiring a scrollview in order to have scrolling
overflow: 'hidden',
}}
>
{children}
</View>
);
}; Like OP noted, this reproduces the same behavior we have on native in the web, by hiding any overflow. This also makes it easy for you to add scroll views which fill this container, since it has an explicit height. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey there, I wonder why this example gives different results between native and web:
https://snack.expo.dev/@giacomocerquone/crabby-apple
TLDR: To create a fixed positioned View on ios or android you just need to put the element outside of a scrollview. This is not enough on web though where the entire page scrolls.
Developing Modals or any other "overlayed" component, can get tricky if you don't know this. Is this reported somewhere in the documentation? What's your take on this?
/cc @necolas
Beta Was this translation helpful? Give feedback.
All reactions