/**
* Copyright (c) Facebook, Inc. and its 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,
Slider,
Switch,
} = require('react-native');
const TextInputSharedExamples = require('./TextInputSharedExamples.js');
import type {RNTesterExampleModuleItem} from '../../types/RNTesterTypes';
class ToggleDefaultPaddingExample extends React.Component<
$FlowFixMeProps,
$FlowFixMeState,
> {
constructor(props) {
super(props);
this.state = {hasPadding: false};
}
render() {
return (
this.setState({hasPadding: !this.state.hasPadding})}>
Toggle padding
);
}
}
class AutogrowingTextInputExample extends React.Component<{...}> {
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 = {
width: 100,
multiline: true,
text: '',
contentSize: {
width: 0,
height: 0,
},
};
}
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() {
/* $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 (
Width:
=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
onValueChange={value => this.setState({width: 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:
=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.width + '%'}]}
/* $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})
}
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was
* found when making Flow check .android.js files. */
{...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,
},
});
exports.title = '';
exports.description = 'Single and multi-line text inputs.';
exports.examples = ([
...TextInputSharedExamples,
{
title: 'Colors and text inputs',
render: function(): React.Node {
return (
Darker backgroundColor
);
},
},
{
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: '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: '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);