@@ -15,10 +15,21 @@ const getKeyboardsWithIDs = keyboardIDs => {
15
15
} ) ;
16
16
} ;
17
17
18
+ /**
19
+ * @description : used for registering keyboards and performing certain actions on the keyboards.
20
+ * @example : https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/nativeComponentScreens/keyboardInput/demoKeyboards.js
21
+ */
18
22
export default class KeyboardRegistry {
23
+ static displayName = 'KeyboardRegistry' ;
19
24
static registeredKeyboards = { } ;
20
25
static eventEmitter = new EventEmitterManager ( ) ;
21
26
27
+ /**
28
+ * Register a new keyboard.
29
+ * componentID (string) - the ID of the keyboard.
30
+ * generator (function) - a function for the creation of the keyboard.
31
+ * params (object) - to be returned when using other methods (i.e. getKeyboards and getAllKeyboards).
32
+ */
22
33
static registerKeyboard = ( componentID , generator , params = { } ) => {
23
34
if ( ! _ . isFunction ( generator ) ) {
24
35
console . error ( `KeyboardRegistry.registerKeyboard: ${ componentID } you must register a generator function` ) ;
@@ -28,6 +39,10 @@ export default class KeyboardRegistry {
28
39
AppRegistry . registerComponent ( componentID , generator ) ;
29
40
} ;
30
41
42
+ /**
43
+ * Get a specific keyboard
44
+ * componentID (string) - the ID of the keyboard.
45
+ */
31
46
static getKeyboard = componentID => {
32
47
const res = KeyboardRegistry . registeredKeyboards [ componentID ] ;
33
48
if ( ! res || ! res . generator ) {
@@ -37,37 +52,75 @@ export default class KeyboardRegistry {
37
52
return res . generator ( ) ;
38
53
} ;
39
54
55
+ /**
56
+ * Get keyboards by IDs
57
+ * componentIDs (string[]) - the ID of the keyboard.
58
+ */
40
59
static getKeyboards = ( componentIDs = [ ] ) => {
41
60
const validKeyboardIDs = _ . intersection ( componentIDs , Object . keys ( KeyboardRegistry . registeredKeyboards ) ) ;
42
61
return getKeyboardsWithIDs ( validKeyboardIDs ) ;
43
62
} ;
44
63
64
+ /**
65
+ * Get all keyboards
66
+ */
45
67
static getAllKeyboards = ( ) => {
46
68
return getKeyboardsWithIDs ( Object . keys ( KeyboardRegistry . registeredKeyboards ) ) ;
47
69
} ;
48
70
71
+ /**
72
+ * Add a listener for a callback.
73
+ * globalID (string) - ID that includes the componentID and the event name
74
+ * (i.e. if componentID='kb1' globalID='kb1.onItemSelected')
75
+ * callback (function) - the callback to be called when the said event happens
76
+ */
49
77
static addListener = ( globalID , callback ) => {
50
78
KeyboardRegistry . eventEmitter . listenOn ( globalID , callback ) ;
51
79
} ;
52
80
81
+ /**
82
+ * Notify that an event has occurred.
83
+ * globalID (string) - ID that includes the componentID and the event name
84
+ * (i.e. if componentID='kb1' globalID='kb1.onItemSelected')
85
+ * args (object) - data to be sent to the listener.
86
+ */
53
87
static notifyListeners = ( globalID , args ) => {
54
88
KeyboardRegistry . eventEmitter . emitEvent ( globalID , args ) ;
55
89
} ;
56
90
91
+ /**
92
+ * Remove a listener for a callback.
93
+ * globalID (string) - ID that includes the componentID and the event name
94
+ * (i.e. if componentID='kb1' globalID='kb1.onItemSelected')
95
+ */
57
96
static removeListeners = globalID => {
58
97
KeyboardRegistry . eventEmitter . removeListeners ( globalID ) ;
59
98
} ;
60
99
100
+ /**
101
+ * Default event to be used for when an item on the keyboard has been pressed.
102
+ * globalID (string) - ID that includes the componentID and the event name
103
+ * (i.e. if componentID='kb1' globalID='kb1.onItemSelected')
104
+ * args (object) - data to be sent to the listener.
105
+ */
61
106
static onItemSelected = ( globalID , args ) => {
62
107
KeyboardRegistry . notifyListeners ( `${ globalID } .onItemSelected` , args ) ;
63
108
} ;
64
109
110
+ /**
111
+ * TODO: complete docs
112
+ * globalID (string) - ID that includes the componentID and the event name
113
+ * (i.e. if componentID='kb1' globalID='kb1.onItemSelected')
114
+ */
65
115
static requestShowKeyboard = globalID => {
66
116
KeyboardRegistry . notifyListeners ( 'onRequestShowKeyboard' , { keyboardId : globalID } ) ;
67
117
} ;
68
118
69
119
/**
70
120
* iOS only
121
+ * TODO: complete docs
122
+ * globalID (string) - ID that includes the componentID and the event name
123
+ * (i.e. if componentID='kb1' globalID='kb1.onItemSelected')
71
124
*/
72
125
static toggleExpandedKeyboard = globalID => {
73
126
KeyboardRegistry . notifyListeners ( 'onToggleExpandedKeyboard' , { keyboardId : globalID } ) ;
0 commit comments