/**
* 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.
*
* @format
* @flow
*/
'use strict';
const React = require('react');
const {Text, TextInput, View, StyleSheet, Switch} = require('react-native');
const TextInputSharedExamples = require('./TextInputSharedExamples.js');
import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
class ToggleDefaultPaddingExample extends React.Component<
$FlowFixMeProps,
$FlowFixMeState,
> {
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
constructor(props) {
super(props);
this.state = {hasPadding: false};
}
render(): React.Node {
return (
this.setState({hasPadding: !this.state.hasPadding})}>
Toggle padding
);
}
}
class AutogrowingTextInputExample extends React.Component<{...}> {
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
constructor(props) {
super(props);
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
* when making Flow check .android.js files. */
this.state = {
multiline: true,
fullWidth: true,
text: '',
contentSize: {
width: 0,
height: 0,
},
};
}
/* $FlowFixMe[missing-local-annot] The type annotation(s) required by Flow's
* LTI update could not be added via codemod */
UNSAFE_componentWillReceiveProps(props) {
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
* when making Flow check .android.js files. */
this.setState({
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
* when making Flow check .android.js files. */
multiline: props.multiline,
});
}
render(): React.Node {
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
* when making Flow check .android.js files. */
const {style, multiline, ...props} = this.props;
return (
Full width:
=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
value={this.state.fullWidth}
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
onValueChange={value => this.setState({fullWidth: value})}
/>
Multiline:
=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
value={this.state.multiline}
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
onValueChange={value => this.setState({multiline: value})}
/>
TextInput:
{/* $FlowFixMe(>=0.122.0 site=react_native_android_fb) This comment
* suppresses an error found when Flow v0.122.0 was deployed. To see
* the error, delete this comment and run Flow. */}
=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
multiline={this.state.multiline}
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
style={[style, {width: this.state.fullWidth ? '100%' : '50%'}]}
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
onChangeText={value => this.setState({text: value})}
onContentSizeChange={event =>
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
this.setState({contentSize: event.nativeEvent.contentSize})
}
{...props}
/>
Plain text value representation:
{/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */}
{this.state.text}
{/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */}
Content Size: {JSON.stringify(this.state.contentSize)}
);
}
}
const styles = StyleSheet.create({
multiline: {
height: 60,
fontSize: 16,
},
singleLine: {
fontSize: 16,
},
singleLineWithHeightTextInput: {
height: 30,
},
default: {
borderWidth: StyleSheet.hairlineWidth,
borderColor: '#0f0f0f',
flex: 1,
fontSize: 13,
padding: 4,
},
});
exports.title = 'TextInput';
exports.documentationURL = 'https://reactnative.dev/docs/textinput';
exports.category = 'Basic';
exports.description = 'Single and multi-line text inputs.';
exports.examples = ([
...TextInputSharedExamples,
{
title: 'Colors and text inputs',
render: function (): React.Node {
return (
Darker backgroundColor
);
},
},
{
title: 'Font Weight',
render: function (): React.Node {
return (
{[
'normal',
'bold',
'900',
'800',
'700',
'600',
'500',
'400',
'300',
'200',
'100',
].map(fontWeight => (
))}
);
},
},
{
title: 'Text input, themes and heights',
render: function (): React.Node {
return (
);
},
},
{
title: 'letterSpacing',
render: function (): React.Node {
return (
);
},
},
{
title: 'Passwords',
render: function (): React.Node {
return (
);
},
},
{
title: 'Editable',
render: function (): React.Node {
return (
);
},
},
{
title: 'Multiline',
render: function (): React.Node {
return (
multiline with children, aligned bottom-right
);
},
},
{
title: 'Editable and Read only',
render: function (): React.Node {
return (
);
},
},
{
title: 'Fixed number of lines',
platform: 'android',
render: function (): React.Node {
return (
);
},
},
{
title: 'Auto-expanding',
render: function (): React.Node {
return (
generic generic generic
small small small small small small
regular regular
huge huge huge huge huge
generic generic generic
);
},
},
{
title: 'Text Auto Complete',
render: function (): React.Node {
return (
);
},
},
{
title: 'Return key',
render: function (): React.Node {
const returnKeyTypes = [
'none',
'go',
'search',
'send',
'done',
'previous',
'next',
];
const returnKeyLabels = ['Compile', 'React Native'];
const examples = returnKeyTypes.map(type => {
return (
);
});
const types = returnKeyLabels.map(type => {
return (
);
});
return (
{examples}
{types}
);
},
},
{
title: 'Inline Images',
render: function (): React.Node {
return (
);
},
},
{
title: 'Toggle Default Padding',
render: function (): React.Node {
return ;
},
},
]: Array);