Skip to content

Commit 92da261

Browse files
committed
chore: add TextInput event propagation scenario
1 parent 72142f1 commit 92da261

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as React from 'react';
2+
import { StyleSheet, SafeAreaView, TextInput, Pressable } from 'react-native';
3+
import { buildEventLogger } from '../utils/helpers';
4+
5+
const handlePressIn = buildEventLogger('pressIn');
6+
const handlePressOut = buildEventLogger('pressOut');
7+
const handleFocus = buildEventLogger('focus');
8+
const handleBlur = buildEventLogger('blur');
9+
const handleChange = buildEventLogger('change');
10+
const handleSubmitEditing = buildEventLogger('submitEditing');
11+
12+
const handlePressablePress = buildEventLogger('Pressable.press');
13+
14+
export function TextInputEventPropagation() {
15+
const [value, setValue] = React.useState('');
16+
17+
const handleChangeText = (value: string) => {
18+
setValue(value);
19+
console.log(`Event: changeText`, value);
20+
};
21+
22+
return (
23+
<SafeAreaView style={styles.container}>
24+
<Pressable onPress={handlePressablePress}>
25+
<TextInput
26+
style={styles.textInput}
27+
value={value}
28+
editable={true}
29+
onChangeText={handleChangeText}
30+
onPressIn={handlePressIn}
31+
onPressOut={handlePressOut}
32+
onFocus={handleFocus}
33+
onBlur={handleBlur}
34+
onChange={handleChange}
35+
onSubmitEditing={handleSubmitEditing}
36+
/>
37+
</Pressable>
38+
</SafeAreaView>
39+
);
40+
}
41+
42+
const styles = StyleSheet.create({
43+
container: {
44+
flex: 1,
45+
},
46+
textInput: {
47+
backgroundColor: 'white',
48+
margin: 20,
49+
padding: 8,
50+
fontSize: 18,
51+
borderWidth: 1,
52+
borderColor: 'grey',
53+
},
54+
});

experiments-app/src/Experiments/TextInputEvents.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
import * as React from 'react';
22
import { StyleSheet, SafeAreaView, TextInput } from 'react-native';
3-
import { buildEventLogger } from './helpers';
3+
import { buildEventLogger } from '../utils/helpers';
44

55
const handlePressIn = buildEventLogger('pressIn');
66
const handlePressOut = buildEventLogger('pressOut');
77
const handleFocus = buildEventLogger('focus');
88
const handleBlur = buildEventLogger('blur');
99
const handleChange = buildEventLogger('change');
10+
const handleSubmitEditing = buildEventLogger('submitEditing');
1011

1112
export function TextInputEvents() {
12-
const [value, setValue] = React.useState('Regular TextInput');
13+
const [value, setValue] = React.useState('');
1314

1415
const handleChangeText = (value: string) => {
1516
setValue(value);
@@ -21,13 +22,14 @@ export function TextInputEvents() {
2122
<TextInput
2223
style={styles.textInput}
2324
value={value}
25+
editable={true}
2426
onChangeText={handleChangeText}
25-
editable={false}
2627
onPressIn={handlePressIn}
2728
onPressOut={handlePressOut}
2829
onFocus={handleFocus}
2930
onBlur={handleBlur}
3031
onChange={handleChange}
32+
onSubmitEditing={handleSubmitEditing}
3133
/>
3234
</SafeAreaView>
3335
);

experiments-app/src/experiments.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import { TextInputEvents } from './Experiments/TextInputEvents';
1+
import { TextInputEventPropagation } from './experiments/TextInputEventPropagation';
2+
import { TextInputEvents } from './experiments/TextInputEvents';
23

34
export type Experiment = (typeof experiments)[number];
45

@@ -8,4 +9,9 @@ export const experiments = [
89
title: 'TextInput Events',
910
component: TextInputEvents,
1011
},
12+
{
13+
key: 'textInputEventPropagation',
14+
title: 'TextInput Event Propagation',
15+
component: TextInputEventPropagation,
16+
},
1117
];

0 commit comments

Comments
 (0)