@@ -12,21 +12,104 @@ import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
1212
1313import RNTesterText from '../../components/RNTesterText' ;
1414import * as React from 'react' ;
15- import { StyleSheet , View } from 'react-native' ;
15+ import { StyleSheet , TextInput , View } from 'react-native' ;
1616
1717function Playground ( ) {
18+ const [ events , setEvents ] = React . useState < Array < string >> ( [ ] ) ;
19+
20+ const appendEvent = React . useCallback ( ( label : string ) => {
21+ setEvents ( currentEvents => [ label , ...currentEvents ] . slice ( 0 , 12 ) ) ;
22+ } , [ ] ) ;
23+
1824 return (
1925 < View style = { styles . container } >
20- < RNTesterText >
21- Edit "RNTesterPlayground.js" to change this file
26+ < RNTesterText style = { styles . heading } > Local keyboard compat playground</ RNTesterText >
27+ < RNTesterText style = { styles . copy } >
28+ Tab into the focusable box or text input and try Enter, Tab, Shift+Enter,
29+ and random keys. Only the keys listed in validKeysDown should log.
2230 </ RNTesterText >
31+
32+ < View
33+ enableFocusRing = { true }
34+ focusable = { true }
35+ onKeyDown = { event => {
36+ appendEvent (
37+ `View onKeyDown: ${ event . nativeEvent . key } shift=${ String ( event . nativeEvent . shiftKey ) } ` ,
38+ ) ;
39+ } }
40+ style = { styles . focusTarget }
41+ validKeysDown = { [ 'Enter' , 'Tab' ] }
42+ >
43+ < RNTesterText > Focusable View using validKeysDown=["Enter", "Tab"]</ RNTesterText >
44+ </ View >
45+
46+ < TextInput
47+ defaultValue = "Focus me and try Enter or Shift+Enter"
48+ multiline = { true }
49+ onKeyDown = { event => {
50+ appendEvent (
51+ `TextInput onKeyDown: ${ event . nativeEvent . key } shift=${ String ( event . nativeEvent . shiftKey ) } ` ,
52+ ) ;
53+ } }
54+ style = { styles . input }
55+ validKeysDown = { [ 'Enter' ] }
56+ />
57+
58+ < View style = { styles . logPanel } >
59+ < RNTesterText style = { styles . logHeading } > Recent events</ RNTesterText >
60+ { events . length === 0 ? (
61+ < RNTesterText style = { styles . logLine } > No matching events yet.</ RNTesterText >
62+ ) : (
63+ events . map ( ( event , index ) => (
64+ < RNTesterText key = { `${ event } -${ index } ` } style = { styles . logLine } >
65+ { event }
66+ </ RNTesterText >
67+ ) )
68+ ) }
69+ </ View >
2370 </ View >
2471 ) ;
2572}
2673
2774const styles = StyleSheet . create ( {
2875 container : {
29- padding : 10 ,
76+ gap : 12 ,
77+ padding : 16 ,
78+ } ,
79+ heading : {
80+ fontSize : 18 ,
81+ fontWeight : '600' ,
82+ } ,
83+ copy : {
84+ lineHeight : 20 ,
85+ } ,
86+ focusTarget : {
87+ borderColor : '#888' ,
88+ borderRadius : 8 ,
89+ borderWidth : 1 ,
90+ minHeight : 64 ,
91+ padding : 12 ,
92+ } ,
93+ input : {
94+ borderColor : '#888' ,
95+ borderRadius : 8 ,
96+ borderWidth : 1 ,
97+ minHeight : 96 ,
98+ padding : 12 ,
99+ } ,
100+ logPanel : {
101+ borderColor : '#ddd' ,
102+ borderRadius : 8 ,
103+ borderWidth : 1 ,
104+ minHeight : 120 ,
105+ padding : 12 ,
106+ } ,
107+ logHeading : {
108+ fontWeight : '600' ,
109+ marginBottom : 8 ,
110+ } ,
111+ logLine : {
112+ marginBottom : 4 ,
30113 } ,
31114} ) ;
32115
0 commit comments