/**
* 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.
*
* @flow
* @format
*/
'use strict';
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
import React, {useState} from 'react';
import {
Alert,
Button,
KeyboardAvoidingView,
Modal,
Pressable,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
} from 'react-native';
const onButtonPress = () => {
Alert.alert('Successfully Registered!');
};
const TextInputForm = () => {
return (
);
};
const CloseButton = (
props:
| {behavior: any, setModalOpen: any}
| {behavior: string, setModalOpen: any},
) => {
return (
props.setModalOpen(false)}
style={styles.closeButton}>
Close
);
};
const KeyboardAvoidingViewBehaviour = () => {
const [modalOpen, setModalOpen] = useState(false);
const [behavior, setBehavior] = useState('padding');
return (
{/* $FlowFixMe[incompatible-type] Natural Inference rollout. See
* https://fburl.com/workplace/6291gfvu */}
setBehavior('padding')}
style={[
styles.pillStyle,
{backgroundColor: behavior === 'padding' ? 'blue' : 'white'},
]}>
Padding
setBehavior('position')}
style={[
styles.pillStyle,
{backgroundColor: behavior === 'position' ? 'blue' : 'white'},
]}>
Position
setBehavior('height')}
style={[
styles.pillStyle,
{backgroundColor: behavior === 'height' ? 'blue' : 'white'},
]}>
Height
setModalOpen(true)}>
Open Example
);
};
const KeyboardAvoidingDisabled = () => {
const [modalOpen, setModalOpen] = useState(false);
return (
setModalOpen(true)}>
Open Example
);
};
const KeyboardAvoidingVerticalOffset = () => {
const [modalOpen, setModalOpen] = useState(false);
return (
setModalOpen(true)}>
Open Example
);
};
const KeyboardAvoidingContentContainerStyle = () => {
const [modalOpen, setModalOpen] = useState(false);
return (
setModalOpen(true)}>
Open Example
);
};
const styles = StyleSheet.create({
outerContainer: {
flex: 1,
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
paddingHorizontal: 20,
paddingTop: 20,
},
contentContainer: {
paddingTop: 20,
backgroundColor: '#abdebf',
},
textInput: {
borderRadius: 5,
borderWidth: 1,
height: 44,
width: 300,
marginBottom: 20,
paddingHorizontal: 10,
},
closeView: {
alignSelf: 'stretch',
},
pillStyle: {
padding: 10,
marginHorizontal: 5,
marginVertical: 10,
borderRadius: 20,
borderWidth: 1,
borderColor: 'blue',
},
closeButton: {
flexDirection: 'row',
justifyContent: 'flex-end',
marginVertical: 10,
padding: 10,
},
touchableText: {
fontWeight: '500',
color: 'blue',
},
});
exports.title = 'KeyboardAvoidingView';
exports.description =
'Base component for views that automatically adjust their height or position to move out of the way of the keyboard.';
exports.examples = [
{
title: 'Keyboard Avoiding View with different behaviors',
description:
('Specify how to react to the presence of the keyboard. Android and iOS both interact' +
'with this prop differently. On both iOS and Android, setting behavior is recommended.': string),
render(): React.Node {
return ;
},
},
{
title: 'Keyboard Avoiding View with keyboardVerticalOffset={distance}',
description:
('This is the distance between the top of the user screen and the react native' +
'view, may be non-zero in some use cases. Defaults to 0.': string),
render(): React.Node {
return ;
},
},
{
title: 'Keyboard Avoiding View with enabled={false}',
render(): React.Node {
return ;
},
},
{
title: 'Keyboard Avoiding View with contentContainerStyle',
render(): React.Node {
return ;
},
},
] as Array;