@@ -12,182 +12,27 @@ import type {RNTesterModuleExample} from '../../types/RNTesterTypes';
1212
1313import RNTesterText from '../../components/RNTesterText' ;
1414import * as React from 'react' ;
15- import {
16- Button ,
17- Platform ,
18- ScrollView ,
19- StyleSheet ,
20- TextInput ,
21- View ,
22- } from 'react-native' ;
15+ import { StyleSheet , View } from 'react-native' ;
2316
2417function Playground ( ) {
25- const textInputRef = React . useRef < React . ElementRef < typeof TextInput > | null > (
26- null ,
27- ) ;
28- const [ refStatus , setRefStatus ] = React . useState < string > ( 'pending...' ) ;
29- const [ log , setLog ] = React . useState < string > ( '' ) ;
30-
31- React . useEffect ( ( ) => {
32- const status =
33- textInputRef . current != null ? 'REF OK' : 'REF IS NULL' ;
34- setRefStatus ( status ) ;
35- } , [ ] ) ;
36-
37- const appendLog = React . useCallback ( ( message : string ) => {
38- setLog ( prev => ( prev ? prev + '\n' : '' ) + message ) ;
39- } , [ ] ) ;
40-
41- const runCommand = React . useCallback (
42- ( name : string , fn : ( ref : React . ElementRef < typeof TextInput > ) => void ) => {
43- try {
44- if ( textInputRef . current == null ) {
45- appendLog ( `${ name } : FAILED - ref is null` ) ;
46- return ;
47- }
48- fn ( textInputRef . current ) ;
49- appendLog ( `${ name } : OK` ) ;
50- } catch ( e : mixed ) {
51- const message = e instanceof Error ? e . message : String ( e ) ;
52- appendLog ( `${ name } : ERROR - ${ message } ` ) ;
53- }
54- } ,
55- [ appendLog ] ,
56- ) ;
57-
5818 return (
59- < ScrollView style = { styles . container } >
60- < RNTesterText style = { styles . header } >
61- TextInput Ref & Commands Test
19+ < View style = { styles . container } >
20+ < RNTesterText >
21+ Edit "RNTesterPlayground.js" to change this file
6222 </ RNTesterText >
63-
64- < RNTesterText style = { styles . status } >
65- Ref status: { refStatus }
66- </ RNTesterText >
67-
68- < TextInput
69- ref = { textInputRef }
70- style = { styles . textInput }
71- defaultValue = "Hello World TextInput"
72- multiline = { false }
73- />
74-
75- < View style = { styles . buttonRow } >
76- < Button
77- title = "Focus"
78- onPress = { ( ) => runCommand ( 'focus' , ref => ref . focus ( ) ) }
79- />
80- < Button
81- title = "Blur"
82- onPress = { ( ) => runCommand ( 'blur' , ref => ref . blur ( ) ) }
83- />
84- < Button
85- title = "Clear"
86- onPress = { ( ) => runCommand ( 'clear' , ref => ref . clear ( ) ) }
87- />
88- </ View >
89-
90- < View style = { styles . buttonRow } >
91- < Button
92- title = "Set Selection (0, 5)"
93- onPress = { ( ) =>
94- runCommand ( 'setSelection(0,5)' , ref => ref . setSelection ( 0 , 5 ) )
95- }
96- />
97- < Button
98- title = "isFocused?"
99- onPress = { ( ) =>
100- runCommand ( 'isFocused' , ref =>
101- appendLog ( ` -> isFocused: ${ String ( ref . isFocused ( ) ) } ` ) ,
102- )
103- }
104- />
105- </ View >
106-
107- { Platform . OS === 'macos' ? (
108- < View style = { styles . buttonRow } >
109- < Button
110- title = "Set Ghost Text"
111- onPress = { ( ) =>
112- runCommand ( 'setGhostText' , ref =>
113- // $FlowFixMe[prop-missing]
114- ref . setGhostText ( 'ghost suggestion' ) ,
115- )
116- }
117- />
118- < Button
119- title = "Clear Ghost Text"
120- onPress = { ( ) =>
121- // $FlowFixMe[prop-missing]
122- runCommand ( 'clearGhostText' , ref => ref . setGhostText ( null ) )
123- }
124- />
125- </ View >
126- ) : null }
127-
128- < Button title = "Clear Log" onPress = { ( ) => setLog ( '' ) } />
129-
130- < RNTesterText style = { styles . logHeader } > Log:</ RNTesterText >
131- < View style = { styles . logContainer } >
132- < RNTesterText style = { styles . logText } >
133- { log || '(no commands run yet)' }
134- </ RNTesterText >
135- </ View >
136- </ ScrollView >
23+ </ View >
13724 ) ;
13825}
13926
14027const styles = StyleSheet . create ( {
14128 container : {
14229 padding : 10 ,
14330 } ,
144- header : {
145- fontSize : 16 ,
146- fontWeight : 'bold' ,
147- marginBottom : 10 ,
148- } ,
149- status : {
150- fontSize : 14 ,
151- fontWeight : 'bold' ,
152- marginBottom : 8 ,
153- } ,
154- textInput : {
155- height : 40 ,
156- borderColor : '#999' ,
157- borderWidth : 1 ,
158- borderRadius : 4 ,
159- paddingHorizontal : 8 ,
160- marginBottom : 10 ,
161- fontSize : 14 ,
162- } ,
163- buttonRow : {
164- flexDirection : 'row' ,
165- flexWrap : 'wrap' ,
166- gap : 8 ,
167- marginBottom : 8 ,
168- } ,
169- logHeader : {
170- fontSize : 12 ,
171- fontWeight : 'bold' ,
172- marginTop : 10 ,
173- marginBottom : 4 ,
174- } ,
175- logContainer : {
176- backgroundColor : '#f0f0f0' ,
177- borderRadius : 4 ,
178- padding : 8 ,
179- minHeight : 60 ,
180- } ,
181- logText : {
182- fontSize : 11 ,
183- fontFamily : Platform . OS === 'macos' ? 'Menlo' : 'monospace' ,
184- } ,
18531} ) ;
18632
18733export default ( {
18834 title : 'Playground' ,
18935 name : 'playground' ,
190- description :
191- 'TextInput ref and commands verification test for macOS Fabric.' ,
36+ description : 'Test out new features and ideas.' ,
19237 render : ( ) : React . Node => < Playground / > ,
19338} : RNTesterModuleExample ) ;
0 commit comments