1
1
import React , { PureComponent } from 'react' ;
2
2
import { ScrollView , StyleSheet , TextInput } from 'react-native' ;
3
- import { Keyboard , Text , View , Colors , Spacings , Constants , Typography , Button , Switch } from 'react-native-ui-lib' ;
3
+ import {
4
+ Keyboard ,
5
+ Text ,
6
+ View ,
7
+ Colors ,
8
+ Spacings ,
9
+ Constants ,
10
+ Typography ,
11
+ Button ,
12
+ Switch ,
13
+ Assets
14
+ } from 'react-native-ui-lib' ;
15
+ import _ from 'lodash' ;
16
+ import './demoKeyboards' ;
17
+
4
18
const KeyboardAccessoryView = Keyboard . KeyboardAccessoryView ;
5
19
const KeyboardUtils = Keyboard . KeyboardUtils ;
6
- import { _ } from 'lodash' ;
7
-
8
- import './demoKeyboards' ;
9
20
const KeyboardRegistry = Keyboard . KeyboardRegistry ;
10
-
11
21
const TrackInteractive = true ;
12
22
23
+ const keyboards = [
24
+ {
25
+ id : 'unicorn.ImagesKeyboard' ,
26
+ icon : Assets . icons . demo . image
27
+ } ,
28
+ {
29
+ id : 'unicorn.CustomKeyboard' ,
30
+ icon : Assets . icons . demo . dashboard
31
+ }
32
+ ] ;
33
+
13
34
export default class KeyboardInputViewScreen extends PureComponent {
14
35
state = {
15
36
customKeyboard : {
@@ -22,48 +43,28 @@ export default class KeyboardInputViewScreen extends PureComponent {
22
43
} ;
23
44
24
45
onKeyboardItemSelected = ( keyboardId , params ) => {
25
- const receivedKeyboardData = `onItemSelected from "${ keyboardId } "\nreceived params: ${ JSON . stringify ( params ) } ` ;
46
+ const receivedKeyboardData = `onItemSelected from "${ keyboardId } "\nreceived params: ${ JSON . stringify (
47
+ params
48
+ ) } `;
26
49
this . setState ( { receivedKeyboardData} ) ;
27
50
} ;
28
51
29
52
onKeyboardResigned = ( ) => {
30
53
this . resetKeyboardView ( ) ;
31
54
} ;
32
55
33
- getToolbarButtons ( ) {
34
- const keyboards = KeyboardRegistry . getAllKeyboards ( ) ;
35
- const buttons = [ ] ;
36
- for ( let index = 0 ; index < keyboards . length ; ++ index ) {
37
- const string = `Show KB ${ index + 1 } ` ;
38
- const title = `Title ${ index + 1 } (passed prop)` ;
39
- buttons . push ( {
40
- text : string ,
41
- testID : string ,
42
- onPress : ( ) => this . showKeyboardView ( keyboards [ index ] . id , title )
43
- } ) ;
44
- }
45
-
46
- buttons . push ( {
47
- text : 'reset' ,
48
- testID : 'reset' ,
49
- onPress : ( ) => this . resetKeyboardView ( )
50
- } ) ;
51
-
52
- return buttons ;
53
- }
54
-
55
56
isCustomKeyboardOpen = ( ) => {
56
57
const { keyboardOpenState, customKeyboard} = this . state ;
57
58
return keyboardOpenState && ! _ . isEmpty ( customKeyboard ) ;
58
- }
59
+ } ;
59
60
60
61
resetKeyboardView = ( ) => {
61
62
this . setState ( { customKeyboard : { } } ) ;
62
63
} ;
63
64
64
65
dismissKeyboard = ( ) => {
65
66
KeyboardUtils . dismiss ( ) ;
66
- }
67
+ } ;
67
68
68
69
toggleUseSafeArea = ( ) => {
69
70
const { useSafeArea} = this . state ;
@@ -97,42 +98,58 @@ export default class KeyboardInputViewScreen extends PureComponent {
97
98
} ) ;
98
99
}
99
100
100
- onHeightChanged = keyboardAccessoryViewHeight => {
101
+ onHeightChanged = ( keyboardAccessoryViewHeight ) => {
101
102
if ( Constants . isIOS ) {
102
103
this . setState ( { keyboardAccessoryViewHeight} ) ;
103
104
}
104
105
} ;
105
106
106
- keyboardAccessoryViewContent = ( ) => {
107
+ renderKeyboardAccessoryViewContent = ( ) => {
107
108
return (
108
- < View style = { styles . keyboardContainer } >
109
- < View row padding-s5 >
109
+ < View style = { styles . keyboardContainer } paddingV-s4 >
110
+ < View row paddingH-s4 >
110
111
< TextInput
111
- maxHeight = { 200 }
112
112
style = { styles . textInput }
113
- ref = { r => {
113
+ ref = { ( r ) => {
114
114
this . textInputRef = r ;
115
115
} }
116
116
placeholder = { 'Message' }
117
117
underlineColorAndroid = "transparent"
118
118
onFocus = { this . resetKeyboardView }
119
119
/>
120
- < Button label = "Close" link onPress = { KeyboardUtils . dismiss } style = { styles . button } />
120
+ < Button
121
+ link
122
+ grey10
123
+ iconSource = { Assets . icons . demo . close }
124
+ onPress = { KeyboardUtils . dismiss }
125
+ marginL-s2
126
+ />
121
127
</ View >
122
- < View row >
123
- { this . getToolbarButtons ( ) . map ( ( button , index ) => (
124
- < Button label = { button . text } link onPress = { button . onPress } key = { index } style = { styles . button } />
125
- ) ) }
128
+ < View row paddingH-s4 marginT-s2 spread >
129
+ < View row >
130
+ { keyboards . map ( ( keyboard ) => (
131
+ < Button
132
+ key = { keyboard . id }
133
+ grey10
134
+ link
135
+ iconSource = { keyboard . icon }
136
+ onPress = { ( ) => this . showKeyboardView ( keyboard . id ) }
137
+ marginR-s2
138
+ />
139
+ ) ) }
140
+ </ View >
141
+
142
+ < Button grey10 label = "Reset" link onPress = { this . resetKeyboardView } />
126
143
</ View >
127
144
</ View >
128
145
) ;
129
146
} ;
130
147
131
148
requestShowKeyboard = ( ) => {
132
- KeyboardRegistry . requestShowKeyboard ( 'KeyboardView1 ' ) ;
149
+ KeyboardRegistry . requestShowKeyboard ( 'unicorn.ImagesKeyboard ' ) ;
133
150
} ;
134
151
135
- onRequestShowKeyboard = componentID => {
152
+ onRequestShowKeyboard = ( componentID ) => {
136
153
this . setState ( {
137
154
customKeyboard : {
138
155
component : componentID ,
@@ -142,21 +159,27 @@ export default class KeyboardInputViewScreen extends PureComponent {
142
159
} ;
143
160
144
161
safeAreaSwitchToggle = ( ) => {
145
- if ( ! Constants . isIOS ) {
162
+ if ( ! Constants . isIOS ) {
146
163
return ;
147
164
}
148
165
const { useSafeArea} = this . state ;
149
- return (
166
+ return (
150
167
< View column center >
151
- < View style = { styles . separatorLine } />
168
+ < View style = { styles . separatorLine } />
152
169
< View centerV row margin-10 >
153
- < Text text80 dark40 > Safe Area Enabled:</ Text >
154
- < Switch value = { useSafeArea } onValueChange = { this . toggleUseSafeArea } marginL-14 />
170
+ < Text text80 dark40 >
171
+ Safe Area Enabled:
172
+ </ Text >
173
+ < Switch
174
+ value = { useSafeArea }
175
+ onValueChange = { this . toggleUseSafeArea }
176
+ marginL-14
177
+ />
155
178
</ View >
156
- < View style = { styles . separatorLine } />
179
+ < View style = { styles . separatorLine } />
157
180
</ View >
158
181
) ;
159
- }
182
+ } ;
160
183
161
184
render ( ) {
162
185
const { message} = this . props ;
@@ -171,12 +194,17 @@ export default class KeyboardInputViewScreen extends PureComponent {
171
194
{ message || 'Keyboards example' }
172
195
</ Text >
173
196
< Text testID = { 'demo-message' } > { receivedKeyboardData } </ Text >
174
- < Button label = { 'Open keyboard #1' } link onPress = { this . requestShowKeyboard } style = { styles . button } />
175
- { this . safeAreaSwitchToggle ( ) }
197
+ < Button
198
+ label = { 'Open Images Keyboard' }
199
+ link
200
+ onPress = { this . requestShowKeyboard }
201
+ style = { styles . button }
202
+ />
203
+ { this . safeAreaSwitchToggle ( ) }
176
204
</ ScrollView >
177
205
178
206
< KeyboardAccessoryView
179
- renderContent = { this . keyboardAccessoryViewContent }
207
+ renderContent = { this . renderKeyboardAccessoryViewContent }
180
208
onHeightChanged = { this . onHeightChanged }
181
209
trackInteractive = { TrackInteractive }
182
210
kbInputRef = { this . textInputRef }
@@ -201,8 +229,12 @@ const styles = StyleSheet.create({
201
229
} ,
202
230
textInput : {
203
231
flex : 1 ,
204
- padding : Spacings . s1 ,
205
- ...Typography . text70
232
+ paddingVertical : Spacings . s2 ,
233
+ paddingHorizontal : Spacings . s3 ,
234
+ ...Typography . text70 ,
235
+ lineHeight : undefined ,
236
+ backgroundColor : Colors . grey60 ,
237
+ borderRadius : 8
206
238
} ,
207
239
button : {
208
240
padding : Spacings . s2
@@ -211,9 +243,9 @@ const styles = StyleSheet.create({
211
243
backgroundColor : Colors . white ,
212
244
borderWidth : 1 ,
213
245
borderColor : Colors . dark60
214
- } ,
246
+ } ,
215
247
separatorLine : {
216
- flex : 1 ,
248
+ flex : 1 ,
217
249
height : 1 ,
218
250
backgroundColor : Colors . dark80
219
251
}
0 commit comments