/**
* 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 {
Button,
InputAccessoryView,
Text,
TextInput,
View,
StyleSheet,
Slider,
Switch,
Alert,
} = require('react-native');
const TextInputSharedExamples = require('./TextInputSharedExamples.js');
import type {RNTesterExampleModuleItem} from '../../types/RNTesterTypes';
class WithLabel extends React.Component<$FlowFixMeProps> {
render() {
return (
{this.props.label}
{this.props.children}
);
}
}
class TextInputAccessoryViewExample extends React.Component<{...}, *> {
constructor(props) {
super(props);
this.state = {text: 'Placeholder Text'};
}
render() {
const inputAccessoryViewID = 'inputAccessoryView1';
return (
this.setState({text})}
value={this.state.text}
/>
);
}
}
class RewriteExampleKana extends React.Component<$FlowFixMeProps, any> {
constructor(props) {
super(props);
this.state = {text: ''};
}
render() {
return (
{
this.setState({text: text.replace(/ひ/g, '日')});
}}
style={styles.default}
value={this.state.text}
/>
);
}
}
class SecureEntryExample extends React.Component<$FlowFixMeProps, any> {
constructor(props) {
super(props);
this.state = {
text: '',
password: '',
isSecureTextEntry: true,
};
}
render() {
return (
this.setState({text})}
value={this.state.text}
/>
Current text is: {this.state.text}
this.setState({password: text})}
secureTextEntry={this.state.isSecureTextEntry}
value={this.state.password}
/>
{
this.setState({isSecureTextEntry: value});
}}
style={{marginLeft: 4}}
value={this.state.isSecureTextEntry}
/>
);
}
}
class AutogrowingTextInputExample extends React.Component<
$FlowFixMeProps,
$FlowFixMeState,
> {
constructor(props) {
super(props);
this.state = {
width: 100,
multiline: true,
text: '',
contentSize: {
width: 0,
height: 0,
},
};
}
UNSAFE_componentWillReceiveProps(props) {
this.setState({
multiline: props.multiline,
});
}
render() {
const {style, multiline, ...props} = this.props;
return (
Width:
this.setState({width: value})}
/>
Multiline:
this.setState({multiline: value})}
/>
TextInput:
this.setState({text: value})}
onContentSizeChange={event =>
this.setState({contentSize: event.nativeEvent.contentSize})
}
{...props}
/>
Plain text value representation:
{this.state.text}
Content Size: {JSON.stringify(this.state.contentSize)}
);
}
}
const styles = StyleSheet.create({
default: {
borderWidth: StyleSheet.hairlineWidth,
borderColor: '#0f0f0f',
flex: 1,
fontSize: 13,
padding: 4,
},
multiline: {
borderWidth: StyleSheet.hairlineWidth,
borderColor: '#0f0f0f',
flex: 1,
fontSize: 13,
height: 50,
padding: 4,
marginBottom: 4,
},
multilinePlaceholderStyles: {
letterSpacing: 10,
lineHeight: 20,
textAlign: 'center',
},
multilineExpandable: {
height: 'auto',
maxHeight: 100,
},
multilineWithFontStyles: {
color: 'blue',
fontWeight: 'bold',
fontSize: 18,
fontFamily: 'Cochin',
height: 60,
},
singlelinePlaceholderStyles: {
letterSpacing: 10,
textAlign: 'center',
},
labelContainer: {
flexDirection: 'row',
marginVertical: 2,
flex: 1,
},
label: {
width: 115,
alignItems: 'flex-end',
marginRight: 10,
paddingTop: 2,
},
rewriteContainer: {
flexDirection: 'row',
alignItems: 'center',
},
remainder: {
textAlign: 'right',
width: 24,
},
});
exports.displayName = (undefined: ?string);
exports.title = '';
exports.description = 'Single and multi-line text inputs.';
exports.examples = ([
...TextInputSharedExamples,
{
title: 'Live Re-Write (ひ -> 日)',
render: function(): React.Node {
return ;
},
},
{
title: 'Keyboard Accessory View',
render: function(): React.Node {
return ;
},
},
{
title: 'Nested content and `value` property',
render: function(): React.Node {
return (
(first raw text node)
(internal raw text node)
(last raw text node)
(first raw text node)
(internal raw text node)
(last raw text node)
);
},
},
{
title: 'Keyboard appearance',
render: function(): React.Node {
const keyboardAppearance = ['default', 'light', 'dark'];
const examples = keyboardAppearance.map(type => {
return (
);
});
return {examples};
},
},
{
title: 'Return key types',
render: function(): React.Node {
const returnKeyTypes = [
'default',
'go',
'google',
'join',
'next',
'route',
'search',
'send',
'yahoo',
'done',
'emergency-call',
];
const examples = returnKeyTypes.map(type => {
return (
);
});
return {examples};
},
},
{
title: 'Enable return key automatically',
render: function(): React.Node {
return (
);
},
},
{
title: 'Secure text entry',
render: function(): React.Node {
return ;
},
},
{
title: 'Colored input text',
render: function(): React.Node {
return (
);
},
},
{
title: 'Colored highlight/cursor for text input',
render: function(): React.Node {
return (
);
},
},
{
title: 'Clear button mode',
render: function(): React.Node {
const clearButtonModes = [
'never',
'while-editing',
'unless-editing',
'always',
];
const examples = clearButtonModes.map(mode => {
return (
);
});
return {examples};
},
},
{
title: 'Clear and select',
render: function(): React.Node {
return (
);
},
},
{
title: 'Multiline blur on submit',
render: function(): React.Node {
return (
Alert.alert('Alert', event.nativeEvent.text)
}
/>
);
},
},
{
title: 'Multiline',
render: function(): React.Node {
return (
);
},
},
{
title: 'TextInput Intrinsic Size',
render: function(): React.Node {
return (
Singleline TextInput
Multiline TextInput
);
},
},
{
title: 'Auto-expanding',
render: function(): React.Node {
return (
);
},
},
{
title: 'Auto-expanding',
render: function(): React.Node {
return (
huge
generic generic generic
small small small small small small
regular regular
huge huge huge huge huge
generic generic generic
);
},
},
{
title: 'TextInput maxLength',
render: function(): React.Node {
return (
);
},
},
{
title: 'Text Content Type',
render: function(): React.Node {
return (
);
},
},
{
title: 'TextInput Placeholder Styles',
render: function(): React.Node {
return (
);
},
},
{
title: 'showSoftInputOnFocus',
render: function(): React.Node {
return (
);
},
},
]: Array);