Skip to content

Commit 47bc86d

Browse files
committed
Add most of the docs
1 parent 41f7f8d commit 47bc86d

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

lib/components/Keyboard/KeyboardInput/KeyboardAccessoryView.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,80 @@ import KeyboardUtils from './utils/KeyboardUtils';
1616
const IsIOS = Platform.OS === 'ios';
1717
const IsAndroid = Platform.OS === 'android';
1818

19+
/**
20+
* @description: View that allows replacing the default keyboard with other components
21+
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/nativeComponentScreens/keyboardInput/KeyboardInputViewScreen.js
22+
*/
1923
class KeyboardAccessoryView extends Component {
2024
static propTypes = {
25+
/**
26+
* Content to be rendered above the keyboard
27+
*/
2128
renderContent: PropTypes.func,
29+
/**
30+
* A callback for when the height is changed
31+
*/
2232
onHeightChanged: PropTypes.func,
2333
/**
2434
* iOS only.
2535
* The reference to the actual text input (or the keyboard may not reset when instructed to, etc.).
2636
* This is required.
2737
*/
2838
kbInputRef: PropTypes.object,
39+
/**
40+
* The keyboard ID (the componentID sent to KeyboardRegistry)
41+
*/
2942
kbComponent: PropTypes.string,
43+
/**
44+
* The props that will be sent to the KeyboardComponent
45+
*/
3046
kbInitialProps: PropTypes.object,
47+
/**
48+
* Callback that will be called when an item on the keyboard has been pressed.
49+
*/
3150
onItemSelected: PropTypes.func,
51+
/**
52+
* TODO: complete docs
53+
*/
3254
onRequestShowKeyboard: PropTypes.func,
55+
/**
56+
* Callback that will be called once the keyboard has been closed
57+
*/
3358
onKeyboardResigned: PropTypes.func,
59+
/**
60+
* iOS only.
61+
* The scrolling behavior, use NativeModules.KeyboardTrackingViewManager.X where X is:
62+
* KeyboardTrackingScrollBehaviorNone - 0,
63+
* KeyboardTrackingScrollBehaviorScrollToBottomInvertedOnly - 1,
64+
* KeyboardTrackingScrollBehaviorFixedOffset - 2
65+
*
66+
* KeyboardTrackingScrollBehaviorFixedOffset is the default
67+
*/
3468
iOSScrollBehavior: PropTypes.number,
69+
/**
70+
* iOS only.
71+
* TODO: complete docs
72+
*/
3573
revealKeyboardInteractive: PropTypes.bool,
74+
/**
75+
* iOS only.
76+
* TODO: complete docs
77+
*/
3678
manageScrollView: PropTypes.bool,
79+
/**
80+
* iOS only.
81+
* TODO: complete docs
82+
*/
3783
requiresSameParentToManageScrollView: PropTypes.bool,
84+
/**
85+
* iOS only.
86+
* TODO: complete docs
87+
*/
3888
addBottomView: PropTypes.bool,
89+
/**
90+
* iOS only.
91+
* TODO: complete docs
92+
*/
3993
allowHitsOutsideBounds: PropTypes.bool
4094
};
4195

lib/components/Keyboard/KeyboardInput/KeyboardRegistry.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,21 @@ const getKeyboardsWithIDs = keyboardIDs => {
1515
});
1616
};
1717

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+
*/
1822
export default class KeyboardRegistry {
23+
static displayName = 'KeyboardRegistry';
1924
static registeredKeyboards = {};
2025
static eventEmitter = new EventEmitterManager();
2126

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+
*/
2233
static registerKeyboard = (componentID, generator, params = {}) => {
2334
if (!_.isFunction(generator)) {
2435
console.error(`KeyboardRegistry.registerKeyboard: ${componentID} you must register a generator function`);
@@ -28,6 +39,10 @@ export default class KeyboardRegistry {
2839
AppRegistry.registerComponent(componentID, generator);
2940
};
3041

42+
/**
43+
* Get a specific keyboard
44+
* componentID (string) - the ID of the keyboard.
45+
*/
3146
static getKeyboard = componentID => {
3247
const res = KeyboardRegistry.registeredKeyboards[componentID];
3348
if (!res || !res.generator) {
@@ -37,37 +52,75 @@ export default class KeyboardRegistry {
3752
return res.generator();
3853
};
3954

55+
/**
56+
* Get keyboards by IDs
57+
* componentIDs (string[]) - the ID of the keyboard.
58+
*/
4059
static getKeyboards = (componentIDs = []) => {
4160
const validKeyboardIDs = _.intersection(componentIDs, Object.keys(KeyboardRegistry.registeredKeyboards));
4261
return getKeyboardsWithIDs(validKeyboardIDs);
4362
};
4463

64+
/**
65+
* Get all keyboards
66+
*/
4567
static getAllKeyboards = () => {
4668
return getKeyboardsWithIDs(Object.keys(KeyboardRegistry.registeredKeyboards));
4769
};
4870

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+
*/
4977
static addListener = (globalID, callback) => {
5078
KeyboardRegistry.eventEmitter.listenOn(globalID, callback);
5179
};
5280

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+
*/
5387
static notifyListeners = (globalID, args) => {
5488
KeyboardRegistry.eventEmitter.emitEvent(globalID, args);
5589
};
5690

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+
*/
5796
static removeListeners = globalID => {
5897
KeyboardRegistry.eventEmitter.removeListeners(globalID);
5998
};
6099

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+
*/
61106
static onItemSelected = (globalID, args) => {
62107
KeyboardRegistry.notifyListeners(`${globalID}.onItemSelected`, args);
63108
};
64109

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+
*/
65115
static requestShowKeyboard = globalID => {
66116
KeyboardRegistry.notifyListeners('onRequestShowKeyboard', {keyboardId: globalID});
67117
};
68118

69119
/**
70120
* 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')
71124
*/
72125
static toggleExpandedKeyboard = globalID => {
73126
KeyboardRegistry.notifyListeners('onToggleExpandedKeyboard', {keyboardId: globalID});

lib/components/Keyboard/KeyboardInput/utils/KeyboardUtils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
11
import {Keyboard} from 'react-native';
22
import TextInputKeyboardManager from '../TextInputKeyboardManager';
33

4+
/**
5+
* @description: util for managing the keyboard.
6+
* @example: https://github.com/wix/react-native-ui-lib/blob/master/demo/src/screens/nativeComponentScreens/keyboardInput/KeyboardInputViewScreen.js
7+
*/
48
export default class KeyboardUtils {
9+
static displayName = 'KeyboardUtils';
10+
/**
11+
* Used to dismiss (close) the keyboard.
12+
*/
513
static dismiss = () => {
614
Keyboard.dismiss();
715
TextInputKeyboardManager.dismissKeyboard();

0 commit comments

Comments
 (0)