/**
* 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, Text, TextInput, View, StyleSheet} = require('react-native');
import type {RNTesterExampleModuleItem} from '../../types/RNTesterTypes';
const styles = StyleSheet.create({
default: {
borderWidth: StyleSheet.hairlineWidth,
borderColor: '#0f0f0f',
flex: 1,
fontSize: 13,
padding: 4,
},
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,
},
});
class WithLabel extends React.Component<$FlowFixMeProps> {
render() {
return (
{this.props.label}
{this.props.children}
);
}
}
class RewriteExample extends React.Component<$FlowFixMeProps, any> {
constructor(props) {
super(props);
this.state = {text: ''};
}
render() {
const limit = 20;
const remainder = limit - this.state.text.length;
const remainderColor = remainder > 5 ? 'blue' : 'red';
return (
{
text = text.replace(/ /g, '_');
this.setState({text});
}}
style={styles.default}
value={this.state.text}
/>
{remainder}
);
}
}
class RewriteExampleInvalidCharacters extends React.Component<
$FlowFixMeProps,
any,
> {
constructor(props) {
super(props);
this.state = {text: ''};
}
render() {
return (
{
this.setState({text: text.replace(/\s/g, '')});
}}
style={styles.default}
value={this.state.text}
/>
);
}
}
class RewriteInvalidCharactersAndClearExample extends React.Component<
$FlowFixMeProps,
any,
> {
inputRef: ?React.ElementRef = null;
constructor(props) {
super(props);
this.state = {text: ''};
}
render() {
return (
{
this.inputRef = ref;
}}
multiline={false}
onChangeText={text => {
this.setState({text: text.replace(/\s/g, '')});
}}
style={styles.default}
value={this.state.text}
/>
);
}
}
module.exports = ([
{
title: 'Auto-focus',
render: function(): React.Node {
return (
);
},
},
{
title: "Live Re-Write ( -> '_') + maxLength",
render: function(): React.Node {
return ;
},
},
{
title: 'Live Re-Write (no spaces allowed)',
render: function(): React.Node {
return ;
},
},
{
title: 'Live Re-Write (no spaces allowed) and clear',
render: function(): React.Node {
return ;
},
},
{
title: 'Auto-capitalize',
render: function(): React.Node {
return (
);
},
},
{
title: 'Auto-correct',
render: function(): React.Node {
return (
);
},
},
{
title: 'Keyboard types',
render: function(): React.Node {
const keyboardTypes = [
'default',
'ascii-capable',
'numbers-and-punctuation',
'url',
'number-pad',
'phone-pad',
'name-phone-pad',
'email-address',
'decimal-pad',
'twitter',
'web-search',
'ascii-capable-number-pad',
'numeric',
];
const examples = keyboardTypes.map(type => {
return (
);
});
return {examples};
},
},
]: Array);