Skip to content

Commit 2a0a999

Browse files
markuswindalvaromb
authored andcommitted
added keyboardOpeningTime property (APSL#75)
* added keyboardOpeningTime property * added keyboardOpeningTime in README
1 parent dcb3568 commit 2a0a999

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ All the `ScrollView`/`ListView` props will be passed.
103103
| `extraHeight` | `number` | Adds an extra offset when focusing the `TextInput`s. |
104104
| `extraScrollHeight` | `number` | Adds an extra offset to the keyboard. Useful if you want to stick elements above the keyboard. |
105105
| `enableResetScrollToCoords` | `boolean` | Lets the user enable or disable automatic resetScrollToCoords. |
106-
107-
### Methods
106+
| `keyboardOpeningTime` | `number` | Sets the delay time before scrolling to new position, default is 250 |
108107
109108
| **Method** | **Parameter** | **Description** |
110109
|------------|---------------|-----------------|

lib/KeyboardAwareMixin.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const KeyboardAwareMixin = {
1414
mixins: [TimerMixin],
1515
propTypes: {
1616
enableAutoAutomaticScroll: PropTypes.bool,
17+
keyboardOpeningTime: PropTypes.number,
1718
extraHeight: PropTypes.number,
1819
extraScrollHeight: PropTypes.number,
1920
enableResetScrollToCoords: PropTypes.bool,
@@ -25,6 +26,7 @@ const KeyboardAwareMixin = {
2526
extraHeight: _KAM_EXTRA_HEIGHT,
2627
extraScrollHeight: 0,
2728
enableResetScrollToCoords: true,
29+
keyboardOpeningTime: _KAM_KEYBOARD_OPENING_TIME,
2830
}
2931
},
3032

@@ -130,26 +132,37 @@ const KeyboardAwareMixin = {
130132
},
131133

132134
/**
135+
* @param keyboardOpeningTime: takes a different keyboardOpeningTime in consideration.
133136
* @param extraHeight: takes an extra height in consideration.
134137
*/
135-
scrollToFocusedInput: function (reactNode: Object, extraHeight: number) {
138+
scrollToFocusedInput: function (reactNode: Object, extraHeight: number, keyboardOpeningTime: number) {
136139
if (extraHeight === undefined) {
137140
extraHeight = this.props.extraHeight;
138141
}
142+
143+
if (keyboardOpeningTime === undefined) {
144+
keyboardOpeningTime = this.props.keyboardOpeningTime;
145+
}
146+
139147
this.setTimeout(() => {
140148
const responder = this.getScrollResponder();
141149
responder && responder.scrollResponderScrollNativeHandleToKeyboard(
142150
reactNode, extraHeight, true
143151
)
144-
}, _KAM_KEYBOARD_OPENING_TIME)
152+
}, keyboardOpeningTime)
145153
},
146154

147-
scrollToFocusedInputWithNodeHandle: function (nodeID: number, extraHeight: number) {
155+
scrollToFocusedInputWithNodeHandle: function (nodeID: number, extraHeight: number, keyboardOpeningTime: number) {
148156
if (extraHeight === undefined) {
149157
extraHeight = this.props.extraHeight;
150158
}
159+
160+
if (keyboardOpeningTime === undefined) {
161+
keyboardOpeningTime = this.props.keyboardOpeningTime;
162+
}
163+
151164
const reactNode = ReactNative.findNodeHandle(nodeID)
152-
this.scrollToFocusedInput(reactNode, extraHeight + this.props.extraScrollHeight)
165+
this.scrollToFocusedInput(reactNode, extraHeight + this.props.extraScrollHeight, keyboardOpeningTime)
153166
},
154167

155168
position: {x: 0, y: 0},

0 commit comments

Comments
 (0)