/** * 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, Platform, 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, }, multiline: { borderWidth: StyleSheet.hairlineWidth, borderColor: '#0f0f0f', flex: 1, fontSize: 13, height: 50, padding: 4, marginBottom: 4, }, singleLine: { fontSize: 16, }, 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, }, hashtag: { color: 'blue', fontWeight: 'bold', }, eventLabel: { margin: 3, fontSize: 12, }, }); 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={true} onChangeText={text => { this.setState({text: text.replace(/ /g, '')}); }} style={styles.default} value={this.state.text} />