Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 49 additions & 2 deletions packages/rn-tester/js/examples/Playground/RNTesterPlayground.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,69 @@ import type {RNTesterModuleExample} from '../../types/RNTesterTypes';

import RNTesterText from '../../components/RNTesterText';
import * as React from 'react';
import {StyleSheet, View} from 'react-native';
import {useState} from 'react';
import {Button, StyleSheet, TextInput, View} from 'react-native';

// Type into each input. Then either change the OS text size while the app
// runs (Settings > Accessibility > Display & Text Size > Larger Text, or
// `xcrun simctl ui booted content_size accessibility-large`) or press
// "Toggle text color".
// Expected: every input keeps the text you typed.
// Actual on iOS: the uncontrolled inputs drop the typed text (to "" or to
// defaultValue). The controlled input keeps it.
function Playground() {
const [controlledValue, setControlledValue] = useState('');
const [red, setRed] = useState(false);
const inputStyle = [styles.input, red && styles.red];
return (
<View style={styles.container}>
<RNTesterText>
Edit "RNTesterPlayground.js" to change this file
Type into each input, then change the OS text size or press &quot;Toggle
text color&quot;. Every input must keep its text.
</RNTesterText>
<Button
testID="playground-toggle-color"
title="Toggle text color"
onPress={() => setRed(value => !value)}
/>
<RNTesterText>Uncontrolled single-line</RNTesterText>
<TextInput testID="playground-uncontrolled" style={inputStyle} />
<RNTesterText>Uncontrolled multiline</RNTesterText>
<TextInput
testID="playground-uncontrolled-multiline"
multiline={true}
style={inputStyle}
/>
<RNTesterText>Uncontrolled with defaultValue</RNTesterText>
<TextInput
testID="playground-default-value"
defaultValue="default"
style={inputStyle}
/>
<RNTesterText>Controlled</RNTesterText>
<TextInput
testID="playground-controlled"
value={controlledValue}
onChangeText={setControlledValue}
style={inputStyle}
/>
</View>
);
}

const styles = StyleSheet.create({
container: {
gap: 12,
padding: 10,
},
input: {
borderWidth: 1,
fontSize: 18,
padding: 8,
},
red: {
color: 'red',
},
});

export default {
Expand Down
Loading