Skip to content

Instantly share code, notes, and snippets.

@amhinson
Created June 24, 2019 16:04
Show Gist options
  • Save amhinson/cad715e549144440d458c666dc5d01de to your computer and use it in GitHub Desktop.
Save amhinson/cad715e549144440d458c666dc5d01de to your computer and use it in GitHub Desktop.
React Native - Enable scrolling only when content is larger than screen
const DEVICE_HEIGHT = Dimensions.get("window").height;
const Screen = () => {
const [screenHeight, setScreenHeight] = useState(0);
function onContentSizeChange(contentWidth, contentHeight) {
setScreenHeight(contentHeight);
}
const scrollEnabled = screenHeight > DEVICE_HEIGHT;
return (
<ScrollView
scrollEnabled={scrollEnabled}
onContentSizeChange={onContentSizeChange}
>
{/* content */}
</ScrollView>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment