/** * 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. * * @flow * @format */ 'use strict'; import type {RNTesterModuleExample} from '../../types/RNTesterTypes'; import type {TextStyle} from 'react-native'; import RNTesterButton from '../../components/RNTesterButton'; import RNTesterText from '../../components/RNTesterText'; import {RNTesterThemeContext} from '../../components/RNTesterTheme'; import ExampleTextInput from './ExampleTextInput'; import * as React from 'react'; import {createRef, memo, useContext, useState} from 'react'; import { Button, Platform, StyleSheet, Switch, Text, TextInput, View, } from 'react-native'; const styles = StyleSheet.create({ multiline: { height: 50, marginBottom: 4, }, singleLine: { fontSize: 16, }, labelContainer: { flexDirection: 'row', marginVertical: 2, }, label: { width: 115, textAlign: 'right', marginRight: 10, paddingTop: 2, fontSize: 12, }, inputContainer: { flex: 1, }, rewriteContainer: { flexDirection: 'row', alignItems: 'center', }, remainder: { textAlign: 'right', width: 24, }, hashtag: { color: 'blue', fontWeight: 'bold', }, eventLabel: { margin: 3, fontSize: 12, }, focusedUncontrolled: { margin: -2, }, wrappedText: { maxWidth: 300, }, }); class AutoFocusWithSelectOnFocusTextExample extends React.Component< $FlowFixMe, any, > { constructor(props: any | void) { super(props); this.state = { autoFocusFalse: 'autoFocus: false - selectTextOnFocus: true', autoFocusTrue: 'autoFocus: true - selectTextOnFocus: true', }; } render(): React.Node { return ( this.setState({autoFocusFalse: text})} accessibilityLabel="I am the accessibility label for text input" /> this.setState({autoFocusTrue: text})} accessibilityLabel="I am the accessibility label for text input" /> ); } } class WithLabel extends React.Component<$FlowFixMe> { render(): React.Node { return ( {this.props.label} {this.props.children} ); } } class RewriteExample extends React.Component<$FlowFixMe, any> { constructor(props: any | void) { super(props); this.state = {text: ''}; } render(): React.Node { const limit = 20; const remainder = limit - this.state.text.length; const remainderColor = remainder > 5 ? 'blue' : 'red'; return ( { text = text.replace(/ /g, '_'); this.setState({text}); }} value={this.state.text} /> {remainder} ); } } class RewriteExampleInvalidCharacters extends React.Component<$FlowFixMe, any> { constructor(props: any | void) { super(props); this.state = {text: ''}; } render(): React.Node { return ( { this.setState({text: text.replace(/\s/g, '')}); }} value={this.state.text} /> ); } } class RewriteInvalidCharactersAndClearExample extends React.Component< $FlowFixMe, any, > { inputRef: ?React.ElementRef = null; constructor(props: any | void) { super(props); this.state = {text: ''}; } render(): React.Node { return ( { this.inputRef = ref; }} multiline={true} onChangeText={text => { this.setState({text: text.replace(/ /g, '')}); }} value={this.state.text} />