/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ 'use strict'; import * as React from 'react'; import { FlatList, ScrollView, StyleSheet, Switch, Text, TextInput, View, } from 'react-native'; export function ScrollViewKeyboardInsetsExample() { const [automaticallyAdjustKeyboardInsets, setAutomaticallyAdjustKeyboardInsets] = React.useState(true); const [flatList, setFlatList] = React.useState(false); const [inverted, setInverted] = React.useState(false); const [heightRestricted, setHeightRestricted] = React.useState(false); const scrollViewProps = { style: heightRestricted && styles.scrollViewHeightRestricted, contentContainerStyle: styles.scrollViewContent, automaticallyAdjustKeyboardInsets: automaticallyAdjustKeyboardInsets, keyboardDismissMode: 'interactive', }; const data = [...Array(20).keys()]; const renderItem = ({ item, index }) => { const largeInput = (index % 5) === 4; return ( ); }; return ( automaticallyAdjustKeyboardInsets is {automaticallyAdjustKeyboardInsets + ''} setAutomaticallyAdjustKeyboardInsets(v)} value={automaticallyAdjustKeyboardInsets} style={styles.controlSwitch}/> FlatList is {flatList + ''} setFlatList(v)} value={flatList} style={styles.controlSwitch}/> {flatList && ( inverted is {inverted + ''} setInverted(v)} value={inverted} style={styles.controlSwitch}/> )} HeightRestricted is {heightRestricted + ''} setHeightRestricted(v)} value={heightRestricted} style={styles.controlSwitch}/> {flatList ? ( ) : ( {data.map((item, index) => renderItem({ item, index }))} ) } ); } const styles = StyleSheet.create({ container: { flex: 1, alignItems: 'stretch', justifyContent: 'flex-start', }, scrollViewHeightRestricted: { marginVertical: 50, borderColor: '#f00', borderWidth: 1, }, scrollViewContent: { paddingVertical: 5, paddingHorizontal: 10, }, textInputRow: { borderWidth: 1, marginVertical: 8, borderColor: '#999', }, textInput: { width: '100%', backgroundColor: '#fff', fontSize: 24, padding: 8, }, textInputLarger: { minHeight: 200, }, controlRow: { padding: 10, alignItems: 'center', flexDirection: 'row', justifyContent: 'space-between', backgroundColor: '#fff', borderTopWidth: 1, borderTopColor: '#ccc', borderBottomWidth: 1, borderBottomColor: '#ccc', }, controlSwitch: { }, controlTextInput: { flex: 1, paddingVertical: 10, paddingHorizontal: 10, borderWidth: 2, borderColor: '#ccc', borderRadius: 8, }, code: { fontSize: 12, fontFamily: 'Courier', }, }); exports.title = 'ScrollViewKeyboardInsets'; exports.category = 'iOS'; exports.description = 'ScrollView automaticallyAdjustKeyboardInsets adjusts keyboard insets when soft keyboard is activated.'; exports.examples = [ { title: ' automaticallyAdjustKeyboardInsets Example', render: (): React.Node => , }, ];