Last active
September 5, 2024 20:44
-
-
Save david-arteaga/04b326b108deb8419fa1e3faf41a359f to your computer and use it in GitHub Desktop.
[React Native SafeAreaView, KeyboardAvoidingView, ScrollView] The best way to handle safe areas and keyboard in a scroll view #react-native #SafeAreaView #ScrollView #KeyboardAvoidingView
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
import React from 'react'; | |
import { | |
SafeAreaView, | |
StyleSheet, | |
KeyboardAvoidingView, | |
ScrollView, | |
Platform, | |
} from 'react-native'; | |
export default function Screen() { | |
return ( | |
<SafeAreaView style={[styles.sav]}> | |
<KeyboardAvoidingView | |
style={[styles.keyboard]} | |
behavior={Platform.select({android: 'height', default: 'padding'})}> | |
<ScrollView | |
style={[styles.scroll]} | |
keyboardDismissMode="interactive" | |
keyboardShouldPersistTaps="handled"> | |
</ScrollView> | |
</KeyboardAvoidingView> | |
</SafeAreaView> | |
); | |
} | |
const styles = StyleSheet.create({ | |
sav: { | |
flex: 1, | |
}, | |
scroll: { | |
overflow: 'visible', | |
}, | |
keyboard: { | |
flex: 1, | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment