Skip to content

Instantly share code, notes, and snippets.

@david-arteaga
Last active September 5, 2024 20:44
Show Gist options
  • Save david-arteaga/04b326b108deb8419fa1e3faf41a359f to your computer and use it in GitHub Desktop.
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
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