Files
react-native/packages/rn-tester/js/examples/TextInput/TextInputExample.ios.js
T
Mateo Guzmán 79ed11f8f4 fix(rn-tester): text input and xml http request dark mode adjustments (#48207)
Summary:
Was troubleshooting in these modules recently and noticed a few texts off in dark mode. Replacing a few instances of the Text component in all I could see in the two screens.

## Changelog:

[INTERNAL] - RN Tester `TextInput` & `XMLHttpRequest` dark mode adjustments

Pull Request resolved: https://github.com/facebook/react-native/pull/48207

Test Plan:
<details>
<summary>View Screenshots (before fixes)</summary>

| Screenshot 1 | Screenshot 2 | Screenshot 3 | Screenshot 4 | Screenshot 5 | Screenshot 6 |
|--------------|--------------|--------------|--------------|--------------|--------------|
| ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 11 36](https://github.com/user-attachments/assets/c396bc5d-4b3c-4f63-8ac0-68bc808aa9d4) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 11 21](https://github.com/user-attachments/assets/cd8e5a2f-9066-4bc7-b56b-65dbd6df7dc4) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 10 30](https://github.com/user-attachments/assets/da451c18-40cd-4421-b8f5-a2462f82fee9) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 10 23](https://github.com/user-attachments/assets/32925fdb-f983-439f-b898-6986b739895a) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 10 19](https://github.com/user-attachments/assets/f0db7b49-dfef-4abc-aef0-2d55b016c0f8) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 10 16](https://github.com/user-attachments/assets/bad6dc45-3679-4bb6-aadd-6743053cd90f) |
| ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 10 10](https://github.com/user-attachments/assets/43028f51-c6e2-4b26-b20d-a3639606d6d5) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 10 07](https://github.com/user-attachments/assets/f8e2196e-bc64-4507-b330-d1d85730ddff) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 09 59](https://github.com/user-attachments/assets/a7100770-4b38-421f-9b73-09e4fff9e012) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 09 53](https://github.com/user-attachments/assets/27759c8c-0e56-4b92-8173-ba031b994e5c) | | | |

</details>

<details>
<summary>View Screenshots (after fixes)</summary>

| Screenshot 1 | Screenshot 2 | Screenshot 3 | Screenshot 4 | Screenshot 5 | Screenshot 6 |
|--------------|--------------|--------------|--------------|--------------|--------------|
| ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 05 30](https://github.com/user-attachments/assets/71c0287d-d98a-4bfe-85dc-1e08da12ce43) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 05 26](https://github.com/user-attachments/assets/45eac165-f42a-4193-98cc-3ee85d963382) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 05 23](https://github.com/user-attachments/assets/c0e4432d-2d1d-487f-8965-3829c3257364) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 05 19](https://github.com/user-attachments/assets/ab81500c-66c1-4b90-b2b1-f7c490e0029b) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 05 16](https://github.com/user-attachments/assets/aafcad74-e851-49a8-9db0-df06f81f0b30) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 05 11](https://github.com/user-attachments/assets/29a2a6c8-e448-4c90-844d-29a248f9ab69) |
| ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 05 07](https://github.com/user-attachments/assets/54e505c4-c554-4000-aac1-61b97e034f55) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 04 39](https://github.com/user-attachments/assets/0e91dc29-199d-424e-b36a-6b0f7a317cd2) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 04 22](https://github.com/user-attachments/assets/e965b01d-0b03-4d01-a971-57c3bd550146) | ![Simulator Screenshot - iPhone SE (3rd generation) - 2024-12-11 at 00 04 15](https://github.com/user-attachments/assets/50ef03a6-bf1a-4db3-845b-e98373369574) |  |  |

</details>

Reviewed By: cipolleschi

Differential Revision: D67087492

Pulled By: javache

fbshipit-source-id: c9c64377d8c10d965bc5db7783aa80f099ce858a
2024-12-12 04:07:10 -08:00

996 lines
28 KiB
JavaScript

/**
* 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.
*
* @format
* @flow
*/
'use strict';
import type {
RNTesterModule,
RNTesterModuleExample,
} from '../../types/RNTesterTypes';
import type {KeyboardType} from 'react-native/Libraries/Components/TextInput/TextInput';
import RNTesterText from '../../components/RNTesterText';
import ExampleTextInput from './ExampleTextInput';
const TextInputSharedExamples = require('./TextInputSharedExamples.js');
const React = require('react');
const {
Alert,
Button,
InputAccessoryView,
StyleSheet,
Switch,
Text,
TextInput,
View,
} = require('react-native');
class WithLabel extends React.Component<$FlowFixMeProps> {
render(): React.Node {
return (
<View style={styles.labelContainer}>
<View style={styles.label}>
<RNTesterText>{this.props.label}</RNTesterText>
</View>
{this.props.children}
</View>
);
}
}
class TextInputAccessoryViewChangeTextExample extends React.Component<
{...},
{text: string},
> {
constructor(props: void | {...}) {
// $FlowFixMe[incompatible-call]
super(props);
this.state = {text: 'Placeholder Text'};
}
render(): React.Node {
const inputAccessoryViewID = 'inputAccessoryView1';
return (
<View>
<RNTesterText>
Set InputAccessoryView with ID & reset text:
</RNTesterText>
<ExampleTextInput
inputAccessoryViewID={inputAccessoryViewID}
onChangeText={text => this.setState({text})}
value={this.state.text}
/>
<InputAccessoryView nativeID={inputAccessoryViewID}>
<View style={{backgroundColor: 'white'}}>
<Button
onPress={() => this.setState({text: 'Placeholder Text'})}
title="Reset Text"
/>
</View>
</InputAccessoryView>
</View>
);
}
}
class TextInputAccessoryViewChangeKeyboardExample extends React.Component<
{...},
{keyboardType: string, text: string},
> {
constructor(props: void | {...}) {
// $FlowFixMe[incompatible-call]
super(props);
this.state = {text: '', keyboardType: 'default'};
}
_switchKeyboard = () => {
this.setState({
keyboardType:
this.state.keyboardType === 'default' ? 'number-pad' : 'default',
});
};
render(): React.Node {
const inputAccessoryViewID = 'inputAccessoryView2';
return (
<View>
<RNTesterText>
Set InputAccessoryView with ID & switch keyboard:
</RNTesterText>
{/* $FlowFixMe[incompatible-use] */}
<ExampleTextInput
inputAccessoryViewID={inputAccessoryViewID}
onChangeText={text => this.setState({text})}
value={this.state.text}
// $FlowFixMe[incompatible-type]
keyboardType={this.state.keyboardType}
returnKeyType="done"
/>
<InputAccessoryView nativeID={inputAccessoryViewID}>
<View style={{backgroundColor: 'white'}}>
<Button onPress={this._switchKeyboard} title="Switch Keyboard" />
</View>
</InputAccessoryView>
</View>
);
}
}
class TextInputAccessoryViewDefaultDoneButtonExample extends React.Component<
$ReadOnly<{|
keyboardType: KeyboardType,
|}>,
{text: string},
> {
constructor(props: void | $ReadOnly<{keyboardType: KeyboardType}>) {
// $FlowFixMe[incompatible-call]
super(props);
this.state = {text: ''};
}
render(): React.Node {
return (
<ExampleTextInput
onChangeText={text => this.setState({text})}
value={this.state.text}
keyboardType={this.props.keyboardType}
returnKeyType="done"
/>
);
}
}
class RewriteExampleKana extends React.Component<$FlowFixMeProps, any> {
constructor(props: any | void) {
super(props);
this.state = {text: ''};
}
render(): React.Node {
return (
<View style={styles.rewriteContainer}>
<ExampleTextInput
multiline={false}
onChangeText={text => {
this.setState({text: text.replace(/ひ/g, '日')});
}}
value={this.state.text}
/>
</View>
);
}
}
class SecureEntryExample extends React.Component<$FlowFixMeProps, any> {
constructor(props: any | void) {
super(props);
this.state = {
text: '',
password: '',
isSecureTextEntry: true,
};
}
render(): React.Node {
return (
<View>
<ExampleTextInput
secureTextEntry={true}
defaultValue="abc"
onChangeText={text => this.setState({text})}
value={this.state.text}
/>
<RNTesterText>Current text is: {this.state.text}</RNTesterText>
<View
style={{
flex: 1,
flexDirection: 'row',
}}>
<ExampleTextInput
defaultValue="cde"
onChangeText={text => this.setState({password: text})}
secureTextEntry={this.state.isSecureTextEntry}
value={this.state.password}
/>
<Switch
onValueChange={value => {
this.setState({isSecureTextEntry: value});
}}
style={{marginLeft: 4}}
value={this.state.isSecureTextEntry}
/>
</View>
</View>
);
}
}
class AutogrowingTextInputExample extends React.Component<
$FlowFixMeProps,
$FlowFixMeState,
> {
constructor(props: any | void) {
super(props);
this.state = {
multiline: true,
fullWidth: true,
text: '',
contentSize: {
width: 0,
height: 0,
},
};
}
UNSAFE_componentWillReceiveProps(props: any) {
this.setState({
multiline: props.multiline,
});
}
render(): React.Node {
const {style, multiline, ...props} = this.props;
return (
<View>
<RNTesterText>Full width:</RNTesterText>
<Switch
value={this.state.fullWidth}
onValueChange={value => this.setState({fullWidth: value})}
/>
<RNTesterText>Multiline:</RNTesterText>
<Switch
value={this.state.multiline}
onValueChange={value => this.setState({multiline: value})}
/>
<RNTesterText>TextInput:</RNTesterText>
<ExampleTextInput
value="prop"
multiline={this.state.multiline}
style={[style, {width: this.state.fullWidth ? '100%' : '50%'}]}
onChangeText={value => this.setState({text: value})}
onContentSizeChange={event =>
this.setState({contentSize: event.nativeEvent.contentSize})
}
{...props}
/>
<RNTesterText>Plain text value representation:</RNTesterText>
<RNTesterText>{this.state.text}</RNTesterText>
<RNTesterText>
Content Size: {JSON.stringify(this.state.contentSize)}
</RNTesterText>
</View>
);
}
}
const TextInputWithFocusButton = () => {
const inputToFocusRef = React.useRef<React.ElementRef<
typeof TextInput,
> | null>(null);
return (
<View>
<ExampleTextInput
ref={inputToFocusRef}
placeholder="height increases with content"
defaultValue="React Native enables you to build world-class application experiences on native platforms using a consistent developer experience based on JavaScript and React. The focus of React Native is on developer efficiency across all the platforms you care about - learn once, write anywhere. Facebook uses React Native in multiple production apps and will continue investing in React Native."
multiline={true}
enablesReturnKeyAutomatically={true}
returnKeyType="go"
style={[styles.multiline, styles.multilineExpandable]}
/>
<Button
title="Focus"
onPress={() => {
inputToFocusRef.current?.focus();
}}
/>
</View>
);
};
const styles = StyleSheet.create({
multiline: {
height: 50,
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,
},
label: {
width: 115,
alignItems: 'flex-end',
marginRight: 10,
paddingTop: 2,
},
rewriteContainer: {
flexDirection: 'row',
alignItems: 'center',
},
remainder: {
textAlign: 'right',
width: 24,
},
});
const textInputExamples: Array<RNTesterModuleExample> = [
...TextInputSharedExamples,
{
title: 'Live Re-Write (ひ -> 日)',
render: function (): React.Node {
return <RewriteExampleKana />;
},
},
{
title: 'Keyboard Input Accessory View',
render: function (): React.Node {
return (
<View>
<TextInputAccessoryViewChangeTextExample />
<TextInputAccessoryViewChangeKeyboardExample />
</View>
);
},
},
{
title: "Default Input Accessory View with returnKeyType = 'done'",
render: function (): React.Node {
const keyboardTypesWithDoneButton = [
'number-pad',
'phone-pad',
'decimal-pad',
'ascii-capable-number-pad',
];
const examples = keyboardTypesWithDoneButton.map(type => {
return (
<WithLabel key={'keyboardType: ' + type} label={type}>
<TextInputAccessoryViewDefaultDoneButtonExample
key={type}
keyboardType={type}
/>
</WithLabel>
);
});
return <View>{examples}</View>;
},
},
{
title: 'Custom Input Accessory View Button Label',
render: function (): React.Node {
return (
<View>
<WithLabel label="Localized Label">
<ExampleTextInput
keyboardType="number-pad"
inputAccessoryViewButtonLabel="Presiona aquí para terminar"
/>
</WithLabel>
<WithLabel label="Custom Label">
<ExampleTextInput
keyboardType="ascii-capable-number-pad"
inputAccessoryViewButtonLabel="Press here to finish"
/>
</WithLabel>
</View>
);
},
},
{
title: 'Nested content and `value` property',
render: function (): React.Node {
return (
<View>
<WithLabel label="singleline">
<ExampleTextInput value="(value property)">
(first raw text node)
<Text style={{color: 'red'}}>(internal raw text node)</Text>
(last raw text node)
</ExampleTextInput>
</WithLabel>
<WithLabel label="multiline">
<ExampleTextInput multiline={true} value="(value property)">
(first raw text node)
<Text style={{color: 'red'}}>(internal raw text node)</Text>
(last raw text node)
</ExampleTextInput>
</WithLabel>
</View>
);
},
},
{
title: 'Keyboard appearance',
render: function (): React.Node {
const keyboardAppearance = ['default', 'light', 'dark'];
const examples = keyboardAppearance.map(type => {
return (
<WithLabel key={type} label={type}>
<ExampleTextInput keyboardAppearance={type} />
</WithLabel>
);
});
return <View>{examples}</View>;
},
},
{
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 (
<WithLabel key={type} label={type}>
<ExampleTextInput returnKeyType={type} />
</WithLabel>
);
});
return <View>{examples}</View>;
},
},
{
title: 'Enable return key automatically',
render: function (): React.Node {
return (
<View>
<WithLabel label="true">
<ExampleTextInput enablesReturnKeyAutomatically={true} />
</WithLabel>
</View>
);
},
},
{
title: 'Secure text entry',
render: function (): React.Node {
return <SecureEntryExample />;
},
},
{
title: 'Colored input text',
render: function (): React.Node {
return (
<View>
<ExampleTextInput style={{color: 'blue'}} defaultValue="Blue" />
<ExampleTextInput style={{color: 'green'}} defaultValue="Green" />
</View>
);
},
},
{
title: 'Colored highlight/cursor for text input',
render: function (): React.Node {
return (
<View>
<ExampleTextInput
selectionColor={'green'}
defaultValue="Highlight me"
/>
<ExampleTextInput
selectionColor={'rgba(86, 76, 205, 1)'}
defaultValue="Highlight me"
/>
</View>
);
},
},
{
title: 'Clear button mode',
render: function (): React.Node {
const clearButtonModes = [
'never',
'while-editing',
'unless-editing',
'always',
];
const examples = clearButtonModes.map(mode => {
return (
<WithLabel key={mode} label={mode}>
<ExampleTextInput clearButtonMode={mode} defaultValue={mode} />
</WithLabel>
);
});
return <View>{examples}</View>;
},
},
{
title: 'Clear and select',
render: function (): React.Node {
return (
<View>
<WithLabel label="clearTextOnFocus">
<ExampleTextInput
placeholder="text is cleared on focus"
defaultValue="text is cleared on focus"
clearTextOnFocus={true}
/>
</WithLabel>
<WithLabel label="selectTextOnFocus">
<ExampleTextInput
placeholder="text is selected on focus"
defaultValue="text is selected on focus"
selectTextOnFocus={true}
/>
</WithLabel>
<WithLabel label="clearTextOnFocus (multiline)">
<ExampleTextInput
placeholder="text is cleared on focus"
defaultValue="text is cleared on focus"
clearTextOnFocus={true}
multiline={true}
/>
</WithLabel>
<WithLabel label="selectTextOnFocus (multiline)">
<ExampleTextInput
placeholder="text is selected on focus"
defaultValue="text is selected on focus"
selectTextOnFocus={true}
multiline={true}
/>
</WithLabel>
</View>
);
},
},
{
title: 'Multiline blur on submit',
render: function (): React.Node {
return (
<View>
<ExampleTextInput
style={styles.multiline}
placeholder="blurOnSubmit = true"
returnKeyType="next"
blurOnSubmit={true}
multiline={true}
onSubmitEditing={event =>
Alert.alert('Alert', event.nativeEvent.text)
}
/>
</View>
);
},
},
{
title: 'Multiline',
render: function (): React.Node {
return (
<View>
<ExampleTextInput
placeholder="multiline text input"
multiline={true}
style={styles.multiline}
/>
<ExampleTextInput
placeholder="multiline text input with font styles and placeholder"
multiline={true}
clearTextOnFocus={true}
autoCorrect={true}
autoCapitalize="words"
placeholderTextColor="red"
keyboardType="url"
style={[styles.multiline, styles.multilineWithFontStyles]}
/>
<ExampleTextInput
placeholder="multiline text input with max length"
maxLength={5}
multiline={true}
style={styles.multiline}
/>
<ExampleTextInput
placeholder="uneditable multiline text input"
editable={false}
multiline={true}
style={styles.multiline}
/>
<ExampleTextInput
defaultValue="uneditable multiline text input with phone number detection: 88888888."
editable={false}
multiline={true}
style={styles.multiline}
dataDetectorTypes="phoneNumber"
/>
</View>
);
},
},
{
title: 'Editable and Read only',
render: function (): React.Node {
return (
<View>
<ExampleTextInput
placeholder="editable text input using editable prop"
editable
/>
<ExampleTextInput
placeholder="uneditable text input using editable prop"
editable={false}
/>
<ExampleTextInput
placeholder="editable text input using readOnly prop"
readOnly={false}
/>
<ExampleTextInput
placeholder="uneditable text input using readOnly prop"
readOnly
/>
</View>
);
},
},
{
title: 'TextInput Intrinsic Size',
render: function (): React.Node {
return (
<View>
<RNTesterText>Singleline TextInput</RNTesterText>
<View style={{height: 80}}>
<ExampleTextInput
style={{
position: 'absolute',
fontSize: 16,
backgroundColor: '#eeeeee',
borderColor: '#666666',
borderWidth: 5,
borderTopWidth: 20,
borderRadius: 10,
borderBottomRightRadius: 20,
padding: 10,
paddingTop: 20,
}}
testID="singleline_textinput"
placeholder="Placeholder defines intrinsic size"
/>
</View>
<RNTesterText>Multiline TextInput</RNTesterText>
<View style={{height: 80}}>
<ExampleTextInput
style={{
position: 'absolute',
fontSize: 16,
backgroundColor: '#eeeeee',
borderColor: '#666666',
borderWidth: 5,
borderTopWidth: 20,
borderRadius: 10,
borderBottomRightRadius: 20,
padding: 10,
paddingTop: 20,
maxHeight: 100,
}}
testID="multiline_textinput"
multiline={true}
placeholder="Placeholder defines intrinsic size"
/>
</View>
<RNTesterText>Multiline TextInput with flex</RNTesterText>
<View>
<ExampleTextInput
style={{
fontSize: 16,
backgroundColor: '#eeeeee',
borderColor: '#666666',
borderWidth: 5,
borderTopWidth: 20,
borderRadius: 10,
borderBottomRightRadius: 20,
padding: 10,
paddingTop: 20,
}}
testID="multiline_textinput_with_flex"
multiline={true}
placeholder="Placeholder defines intrinsic size"
/>
</View>
</View>
);
},
},
{
title: 'Auto-expanding',
render: function (): React.Node {
return (
<View>
<ExampleTextInput
placeholder="height increases with content"
defaultValue="React Native enables you to build world-class application experiences on native platforms using a consistent developer experience based on JavaScript and React. The focus of React Native is on developer efficiency across all the platforms you care about - learn once, write anywhere. Facebook uses React Native in multiple production apps and will continue investing in React Native."
multiline={true}
enablesReturnKeyAutomatically={true}
returnKeyType="go"
style={[styles.multiline, styles.multilineExpandable]}
/>
</View>
);
},
},
{
title: 'Auto-expanding',
render: function (): React.Node {
return (
<View>
<AutogrowingTextInputExample
enablesReturnKeyAutomatically={true}
returnKeyType="done"
multiline={true}
style={{
maxHeight: 400,
minHeight: 20,
paddingTop: 0,
backgroundColor: '#eeeeee',
color: 'blue',
}}>
<Text style={{fontSize: 30, color: 'green'}}>huge</Text>
generic generic generic
<Text style={{fontSize: 6, color: 'red'}}>
small small small small small small
</Text>
<Text>regular regular</Text>
<Text style={{fontSize: 30, color: 'green'}}>
huge huge huge huge huge
</Text>
generic generic generic
</AutogrowingTextInputExample>
</View>
);
},
},
{
title: 'TextInput maxLength',
render: function (): React.Node {
return (
<View>
<WithLabel label="maxLength: 5">
<ExampleTextInput maxLength={5} />
</WithLabel>
<WithLabel label="maxLength: 5 with placeholder">
<ExampleTextInput maxLength={5} placeholder="ZIP code entry" />
</WithLabel>
<WithLabel label="maxLength: 5 with default value already set">
<ExampleTextInput maxLength={5} defaultValue="94025" />
</WithLabel>
<WithLabel label="maxLength: 5 with very long default value already set">
<ExampleTextInput maxLength={5} defaultValue="9402512345" />
</WithLabel>
</View>
);
},
},
{
title: 'Text Auto Complete',
render: function (): React.Node {
return (
<View>
<WithLabel label="country">
<ExampleTextInput autoComplete="country" />
</WithLabel>
<WithLabel label="one-time-code">
<ExampleTextInput autoComplete="one-time-code" />
</WithLabel>
<WithLabel label="birthdate-full">
<ExampleTextInput autoComplete="birthdate-full" />
</WithLabel>
<WithLabel label="cc-name">
<ExampleTextInput autoComplete="cc-name" />
</WithLabel>
</View>
);
},
},
{
title: 'Text Content Type',
render: function (): React.Node {
return (
<View>
<WithLabel label="emailAddress">
<ExampleTextInput textContentType="emailAddress" />
</WithLabel>
<WithLabel label="name">
<ExampleTextInput textContentType="name" />
</WithLabel>
<WithLabel label="postalCode, when autoComplete set">
<ExampleTextInput
textContentType="postalCode"
autoComplete="email"
/>
</WithLabel>
<WithLabel label="creditCardExpiration">
<ExampleTextInput textContentType="creditCardExpiration" />
</WithLabel>
<WithLabel label="birthdate">
<ExampleTextInput textContentType="birthdate" />
</WithLabel>
<WithLabel label="dateTime">
<ExampleTextInput textContentType="dateTime" />
</WithLabel>
<WithLabel label="flightNumber">
<ExampleTextInput textContentType="flightNumber" />
</WithLabel>
<WithLabel label="shipmentTrackingNumber">
<ExampleTextInput textContentType="shipmentTrackingNumber" />
</WithLabel>
</View>
);
},
},
{
title: 'TextInput Placeholder Styles',
render: function (): React.Node {
return (
<View>
<WithLabel label="letterSpacing: 10 lineHeight: 20 textAlign: 'center'">
<ExampleTextInput
placeholder="multiline text input"
multiline={true}
style={[styles.multiline, styles.multilinePlaceholderStyles]}
/>
</WithLabel>
<WithLabel label="letterSpacing: 10 textAlign: 'center'">
<ExampleTextInput
placeholder="singleline"
style={styles.singlelinePlaceholderStyles}
/>
</WithLabel>
</View>
);
},
},
{
title: 'Line Break Strategy',
render: function (): React.Node {
const lineBreakStrategy = ['none', 'standard', 'hangul-word', 'push-out'];
const textByCode = {
en: 'lineBreakStrategy lineBreakStrategy lineBreakStrategy lineBreakStrategy',
ko: '한글개행한글개행 한글개행한글개행 한글개행한글개행 한글개행한글개행 한글개행한글개행 한글개행한글개행',
ja: 'かいぎょう かいぎょう かいぎょう かいぎょう かいぎょう かいぎょう',
cn: '改行 改行 改行 改行 改行 改行 改行 改行 改行 改行 改行 改行',
};
return (
<View>
{lineBreakStrategy.map(strategy => {
return (
<View key={strategy} style={{marginBottom: 12}}>
<Text
style={{
backgroundColor: 'lightgrey',
}}>{`Strategy: ${strategy}`}</Text>
{Object.keys(textByCode).map(code => {
return (
<View key={code}>
<RNTesterText
style={{
fontWeight: 'bold',
}}>{`[${code}]`}</RNTesterText>
<ExampleTextInput
multiline
lineBreakStrategyIOS={strategy}
defaultValue={textByCode[code]}
/>
</View>
);
})}
</View>
);
})}
</View>
);
},
},
{
title: 'iOS autoformatting behaviors',
render: function (): React.Node {
return (
<View>
<WithLabel label="smartInsertDelete: true | undefined">
<ExampleTextInput defaultValue="CopyAndPaste" />
</WithLabel>
<WithLabel label="smartInsertDelete: false">
<ExampleTextInput
smartInsertDelete={false}
defaultValue="CopyAndPaste"
/>
</WithLabel>
</View>
);
},
},
{
title: 'Auto scroll cursor into view when focusing',
render: function (): React.Node {
return <TextInputWithFocusButton />;
},
},
{
title: 'Line Break Mode',
render: function (): React.Node {
const lineBreakMode = [
'wordWrapping',
'char',
'clip',
'head',
'middle',
'tail',
];
const textByCode = {
en: 'verylongtext-dummydummydummydummydummydummydummydummydummydummydummydummy',
ko: '한글개행한글개행-한글개행한글개행한글개행한글개행한글개행한글개행한글개행한글개행한글개행한글개행',
};
return (
<View>
{lineBreakMode.map(strategy => {
return (
<View key={strategy} style={{marginBottom: 12}}>
<Text
style={{
backgroundColor: 'lightgrey',
}}>{`Mode: ${strategy}`}</Text>
{Object.keys(textByCode).map(code => {
return (
<View key={code}>
<RNTesterText
style={{
fontWeight: 'bold',
}}>{`[${code}]`}</RNTesterText>
<ExampleTextInput
lineBreakModeIOS={strategy}
defaultValue={textByCode[code]}
/>
</View>
);
})}
</View>
);
})}
</View>
);
},
},
];
module.exports = ({
displayName: (undefined: ?string),
title: 'TextInput',
documentationURL: 'https://reactnative.dev/docs/TextInput',
category: 'Basic',
description: 'Single and multi-line text inputs.',
examples: textInputExamples,
}: RNTesterModule);