Created
June 24, 2019 16:04
-
-
Save amhinson/cad715e549144440d458c666dc5d01de to your computer and use it in GitHub Desktop.
React Native - Enable scrolling only when content is larger than screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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