@codeleap/mobile 2.0.1 → 2.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ActionIcon/index.js +2 -1
- package/dist/components/ActionIcon/index.js.map +1 -1
- package/dist/components/ActionIcon/styles.d.ts +58 -58
- package/dist/components/Backdrop/index.js +1 -1
- package/dist/components/Backdrop/index.js.map +1 -1
- package/dist/components/Button/index.d.ts +109 -109
- package/dist/components/Button/index.js +5 -7
- package/dist/components/Button/index.js.map +1 -1
- package/dist/components/Button/styles.d.ts +60 -55
- package/dist/components/Button/styles.js +4 -2
- package/dist/components/Button/styles.js.map +1 -1
- package/dist/components/Checkbox/index.js +4 -2
- package/dist/components/Checkbox/index.js.map +1 -1
- package/dist/components/Checkbox/styles.d.ts +1 -1
- package/dist/components/Checkbox/styles.js +4 -0
- package/dist/components/Checkbox/styles.js.map +1 -1
- package/dist/components/FileInput/index.d.ts +1 -1
- package/dist/components/Image/index.js +3 -0
- package/dist/components/Image/index.js.map +1 -1
- package/dist/components/Modal/index.js +1 -1
- package/dist/components/Modal/index.js.map +1 -1
- package/dist/components/MultiSelect/styles.js +1 -4
- package/dist/components/MultiSelect/styles.js.map +1 -1
- package/dist/components/Navigation/utils.js +0 -1
- package/dist/components/Navigation/utils.js.map +1 -1
- package/dist/components/Pager/styles.js +13 -11
- package/dist/components/Pager/styles.js.map +1 -1
- package/dist/components/RadioInput/index.js +3 -1
- package/dist/components/RadioInput/index.js.map +1 -1
- package/dist/components/RadioInput/styles.d.ts +1 -1
- package/dist/components/RadioInput/styles.js +1 -0
- package/dist/components/RadioInput/styles.js.map +1 -1
- package/dist/components/SegmentedControl/index.d.ts +10 -1
- package/dist/components/SegmentedControl/index.js +27 -27
- package/dist/components/SegmentedControl/index.js.map +1 -1
- package/dist/components/SegmentedControl/styles.d.ts +56 -51
- package/dist/components/SegmentedControl/styles.js +10 -3
- package/dist/components/SegmentedControl/styles.js.map +1 -1
- package/dist/components/Select/index.js +1 -2
- package/dist/components/Select/index.js.map +1 -1
- package/dist/components/Select/styles.d.ts +1 -1
- package/dist/components/Select/styles.js +4 -1
- package/dist/components/Select/styles.js.map +1 -1
- package/dist/components/Switch/index.js +1 -1
- package/dist/components/Switch/index.js.map +1 -1
- package/dist/components/Text/index.d.ts +2 -0
- package/dist/components/Text/index.js +43 -3
- package/dist/components/Text/index.js.map +1 -1
- package/dist/components/Text/styles.d.ts +57 -52
- package/dist/components/Text/styles.js +11 -3
- package/dist/components/Text/styles.js.map +1 -1
- package/dist/components/TextInput/index.d.ts +8 -4
- package/dist/components/TextInput/index.js +37 -17
- package/dist/components/TextInput/index.js.map +1 -1
- package/dist/components/TextInput/styles.d.ts +1 -1
- package/dist/components/TextInput/styles.js +11 -3
- package/dist/components/TextInput/styles.js.map +1 -1
- package/dist/components/Touchable/index.d.ts +1 -1
- package/dist/components/Touchable/index.js +81 -43
- package/dist/components/Touchable/index.js.map +1 -1
- package/dist/components/Touchable/styles.d.ts +56 -51
- package/dist/components/Touchable/styles.js +6 -1
- package/dist/components/Touchable/styles.js.map +1 -1
- package/dist/components/defaultStyles.d.ts +263 -263
- package/dist/utils/KeyboardAware/lib/KeyboardAwareHOC.d.ts +2 -0
- package/dist/utils/KeyboardAware/lib/KeyboardAwareHOC.js +287 -286
- package/dist/utils/KeyboardAware/lib/KeyboardAwareHOC.js.map +1 -1
- package/dist/utils/OSAlert.d.ts +6 -5
- package/dist/utils/OSAlert.js +7 -6
- package/dist/utils/OSAlert.js.map +1 -1
- package/dist/utils/hooks.d.ts +34 -1
- package/dist/utils/hooks.js +54 -1
- package/dist/utils/hooks.js.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +2 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/notifications.js +4 -4
- package/dist/utils/notifications.js.map +1 -1
- package/package.json +1 -1
- package/src/components/ActionIcon/index.tsx +2 -1
- package/src/components/Backdrop/index.tsx +1 -1
- package/src/components/Button/index.tsx +7 -11
- package/src/components/Button/styles.ts +34 -10
- package/src/components/Checkbox/index.tsx +4 -1
- package/src/components/Checkbox/styles.ts +5 -0
- package/src/components/Image/index.tsx +3 -0
- package/src/components/Modal/index.tsx +1 -1
- package/src/components/MultiSelect/styles.ts +1 -8
- package/src/components/Navigation/utils.tsx +0 -2
- package/src/components/Pager/styles.ts +16 -11
- package/src/components/RadioInput/index.tsx +3 -1
- package/src/components/RadioInput/styles.ts +2 -1
- package/src/components/SegmentedControl/index.tsx +31 -18
- package/src/components/SegmentedControl/styles.ts +29 -7
- package/src/components/Select/index.tsx +2 -1
- package/src/components/Select/styles.ts +12 -2
- package/src/components/Switch/index.tsx +1 -1
- package/src/components/Text/index.tsx +57 -7
- package/src/components/Text/styles.ts +25 -9
- package/src/components/TextInput/index.tsx +48 -9
- package/src/components/TextInput/styles.ts +14 -4
- package/src/components/Touchable/index.tsx +90 -36
- package/src/components/Touchable/styles.ts +15 -3
- package/src/utils/KeyboardAware/lib/KeyboardAwareHOC.tsx +34 -24
- package/src/utils/OSAlert.ts +10 -10
- package/src/utils/hooks.ts +82 -2
- package/src/utils/index.ts +2 -2
- package/src/utils/notifications.ts +4 -4
|
@@ -26,7 +26,9 @@ export declare type KeyboardAwareHOCProps = {
|
|
|
26
26
|
update?: Function;
|
|
27
27
|
contentContainerStyle?: any;
|
|
28
28
|
enableOnAndroid?: boolean;
|
|
29
|
+
Scrollable: any;
|
|
29
30
|
innerRef?: Function;
|
|
31
|
+
hocOptions?: any;
|
|
30
32
|
} & typeof keyboardAwareHOCTypeEvents;
|
|
31
33
|
export declare type KeyboardAwareHOCState = {
|
|
32
34
|
keyboardSpace: number;
|
|
@@ -137,301 +137,302 @@ var ScrollIntoViewDefaultOptions = {
|
|
|
137
137
|
}
|
|
138
138
|
},
|
|
139
139
|
};
|
|
140
|
-
function
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
140
|
+
var KeyboardAwareScrollable = /** @class */ (function (_super) {
|
|
141
|
+
__extends(KeyboardAwareScrollable, _super);
|
|
142
|
+
function KeyboardAwareScrollable(props) {
|
|
143
|
+
var _this = _super.call(this, props) || this;
|
|
144
|
+
_this.getScrollResponder = function () {
|
|
145
|
+
return (_this._rnkasv_keyboardView &&
|
|
146
|
+
_this._rnkasv_keyboardView.getScrollResponder &&
|
|
147
|
+
_this._rnkasv_keyboardView.getScrollResponder());
|
|
148
|
+
};
|
|
149
|
+
_this.scrollToPosition = function (x, y, animated) {
|
|
150
|
+
if (animated === void 0) { animated = true; }
|
|
151
|
+
var responder = _this.getScrollResponder();
|
|
152
|
+
if (!responder) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
if (responder.scrollResponderScrollTo) {
|
|
156
|
+
// React Native < 0.65
|
|
157
|
+
responder.scrollResponderScrollTo({ x: x, y: y, animated: animated });
|
|
158
|
+
}
|
|
159
|
+
else if (responder.scrollTo) {
|
|
160
|
+
// React Native >= 0.65
|
|
161
|
+
responder.scrollTo({ x: x, y: y, animated: animated });
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
_this.scrollToEnd = function (animated) {
|
|
165
|
+
if (animated === void 0) { animated = true; }
|
|
166
|
+
var responder = _this.getScrollResponder();
|
|
167
|
+
if (!responder) {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
if (responder.scrollResponderScrollToEnd) {
|
|
171
|
+
// React Native < 0.65
|
|
172
|
+
responder.scrollResponderScrollToEnd({ animated: animated });
|
|
173
|
+
}
|
|
174
|
+
else if (responder.scrollToEnd) {
|
|
175
|
+
// React Native >= 0.65
|
|
176
|
+
responder.scrollToEnd({ animated: animated });
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
_this.scrollForExtraHeightOnAndroid = function (extraHeight) {
|
|
180
|
+
_this.scrollToPosition(0, _this.position.y + extraHeight, true);
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* @param keyboardOpeningTime: takes a different keyboardOpeningTime in consideration.
|
|
184
|
+
* @param extraHeight: takes an extra height in consideration.
|
|
185
|
+
*/
|
|
186
|
+
_this.scrollToFocusedInput = function (reactNode, extraHeight, keyboardOpeningTime) {
|
|
187
|
+
if (extraHeight === undefined) {
|
|
188
|
+
extraHeight = _this.props.extraHeight || 0;
|
|
189
|
+
}
|
|
190
|
+
if (keyboardOpeningTime === undefined) {
|
|
191
|
+
keyboardOpeningTime = _this.props.keyboardOpeningTime || 0;
|
|
192
|
+
}
|
|
193
|
+
setTimeout(function () {
|
|
194
|
+
if (!_this.mountedComponent) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
var responder = _this.getScrollResponder();
|
|
198
|
+
responder &&
|
|
199
|
+
responder.scrollResponderScrollNativeHandleToKeyboard(reactNode, extraHeight, true);
|
|
200
|
+
}, keyboardOpeningTime);
|
|
201
|
+
};
|
|
202
|
+
_this.scrollIntoView = function (element, options) {
|
|
203
|
+
if (options === void 0) { options = {}; }
|
|
204
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
205
|
+
var _a, parentLayout, childLayout, getScrollPosition, _b, x, y, animated;
|
|
206
|
+
return __generator(this, function (_c) {
|
|
207
|
+
switch (_c.label) {
|
|
208
|
+
case 0:
|
|
209
|
+
if (!this._rnkasv_keyboardView || !element) {
|
|
210
|
+
return [2 /*return*/];
|
|
211
|
+
}
|
|
212
|
+
return [4 /*yield*/, Promise.all([
|
|
213
|
+
this._measureElement(this._rnkasv_keyboardView),
|
|
214
|
+
this._measureElement(element),
|
|
215
|
+
])];
|
|
216
|
+
case 1:
|
|
217
|
+
_a = _c.sent(), parentLayout = _a[0], childLayout = _a[1];
|
|
218
|
+
getScrollPosition = options.getScrollPosition || this._defaultGetScrollPosition;
|
|
219
|
+
_b = getScrollPosition(parentLayout, childLayout, this.position), x = _b.x, y = _b.y, animated = _b.animated;
|
|
220
|
+
this.scrollToPosition(x, y, animated);
|
|
221
|
+
return [2 /*return*/];
|
|
196
222
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
223
|
+
});
|
|
224
|
+
});
|
|
225
|
+
};
|
|
226
|
+
_this._defaultGetScrollPosition = function (parentLayout, childLayout, contentOffset) {
|
|
227
|
+
return {
|
|
228
|
+
x: 0,
|
|
229
|
+
y: Math.max(0, childLayout.y - parentLayout.y + contentOffset.y),
|
|
230
|
+
animated: true,
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
_this._measureElement = function (element) {
|
|
234
|
+
var node = (0, react_native_1.findNodeHandle)(element);
|
|
235
|
+
return new Promise(function (resolve) {
|
|
236
|
+
react_native_1.UIManager.measureInWindow(node, function (x, y, width, height) {
|
|
237
|
+
resolve({ x: x, y: y, width: width, height: height });
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
};
|
|
241
|
+
// Keyboard actions
|
|
242
|
+
_this._updateKeyboardSpace = function (frames) {
|
|
243
|
+
// Automatically scroll to focused TextInput
|
|
244
|
+
if (_this.props.enableAutomaticScroll) {
|
|
245
|
+
var keyboardSpace_1 = frames.endCoordinates.height + _this.props.extraScrollHeight;
|
|
246
|
+
if (_this.props.viewIsInsideTabBar) {
|
|
247
|
+
keyboardSpace_1 -= _KAM_DEFAULT_TAB_BAR_HEIGHT;
|
|
248
|
+
}
|
|
249
|
+
_this.setState({ keyboardSpace: keyboardSpace_1 });
|
|
250
|
+
var currentlyFocusedField_1 = react_native_1.TextInput.State.currentlyFocusedInput ?
|
|
251
|
+
(0, react_native_1.findNodeHandle)(react_native_1.TextInput.State.currentlyFocusedInput()) : react_native_1.TextInput.State.currentlyFocusedField();
|
|
252
|
+
var responder = _this.getScrollResponder();
|
|
253
|
+
if (!currentlyFocusedField_1 || !responder) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
// @ts-ignore
|
|
257
|
+
react_native_1.UIManager.viewIsDescendantOf(currentlyFocusedField_1, responder.getInnerViewNode(), function (isAncestor) {
|
|
258
|
+
if (isAncestor) {
|
|
259
|
+
// Check if the TextInput will be hidden by the keyboard
|
|
260
|
+
react_native_1.UIManager.measureInWindow(currentlyFocusedField_1, function (x, y, width, height) {
|
|
261
|
+
var textInputBottomPosition = y + height;
|
|
262
|
+
var keyboardPosition = frames.endCoordinates.screenY;
|
|
263
|
+
var totalExtraHeight = _this.props.extraScrollHeight + _this.props.extraHeight;
|
|
264
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
265
|
+
if (textInputBottomPosition >
|
|
266
|
+
keyboardPosition - totalExtraHeight) {
|
|
267
|
+
_this._scrollToFocusedInputWithNodeHandle(currentlyFocusedField_1);
|
|
268
|
+
}
|
|
226
269
|
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
// Keyboard actions
|
|
246
|
-
_this._updateKeyboardSpace = function (frames) {
|
|
247
|
-
// Automatically scroll to focused TextInput
|
|
248
|
-
if (_this.props.enableAutomaticScroll) {
|
|
249
|
-
var keyboardSpace_1 = frames.endCoordinates.height + _this.props.extraScrollHeight;
|
|
250
|
-
if (_this.props.viewIsInsideTabBar) {
|
|
251
|
-
keyboardSpace_1 -= _KAM_DEFAULT_TAB_BAR_HEIGHT;
|
|
252
|
-
}
|
|
253
|
-
_this.setState({ keyboardSpace: keyboardSpace_1 });
|
|
254
|
-
var currentlyFocusedField_1 = react_native_1.TextInput.State.currentlyFocusedInput ?
|
|
255
|
-
(0, react_native_1.findNodeHandle)(react_native_1.TextInput.State.currentlyFocusedInput()) : react_native_1.TextInput.State.currentlyFocusedField();
|
|
256
|
-
var responder = _this.getScrollResponder();
|
|
257
|
-
if (!currentlyFocusedField_1 || !responder) {
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
// @ts-ignore
|
|
261
|
-
react_native_1.UIManager.viewIsDescendantOf(currentlyFocusedField_1, responder.getInnerViewNode(), function (isAncestor) {
|
|
262
|
-
if (isAncestor) {
|
|
263
|
-
// Check if the TextInput will be hidden by the keyboard
|
|
264
|
-
react_native_1.UIManager.measureInWindow(currentlyFocusedField_1, function (x, y, width, height) {
|
|
265
|
-
var textInputBottomPosition = y + height;
|
|
266
|
-
var keyboardPosition = frames.endCoordinates.screenY;
|
|
267
|
-
var totalExtraHeight = _this.props.extraScrollHeight + _this.props.extraHeight;
|
|
268
|
-
if (react_native_1.Platform.OS === 'ios') {
|
|
269
|
-
if (textInputBottomPosition >
|
|
270
|
-
keyboardPosition - totalExtraHeight) {
|
|
271
|
-
_this._scrollToFocusedInputWithNodeHandle(currentlyFocusedField_1);
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
else {
|
|
275
|
-
// On android, the system would scroll the text input just
|
|
276
|
-
// above the keyboard so we just neet to scroll the extra
|
|
277
|
-
// height part
|
|
278
|
-
if (textInputBottomPosition > keyboardPosition) {
|
|
279
|
-
// Since the system already scrolled the whole view up
|
|
280
|
-
// we should reduce that amount
|
|
281
|
-
keyboardSpace_1 =
|
|
282
|
-
keyboardSpace_1 -
|
|
283
|
-
(textInputBottomPosition - keyboardPosition);
|
|
284
|
-
_this.setState({ keyboardSpace: keyboardSpace_1 });
|
|
285
|
-
_this.scrollForExtraHeightOnAndroid(totalExtraHeight);
|
|
286
|
-
}
|
|
287
|
-
else if (textInputBottomPosition >
|
|
288
|
-
keyboardPosition - totalExtraHeight) {
|
|
289
|
-
_this.scrollForExtraHeightOnAndroid(totalExtraHeight -
|
|
290
|
-
(keyboardPosition - textInputBottomPosition));
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
});
|
|
270
|
+
else {
|
|
271
|
+
// On android, the system would scroll the text input just
|
|
272
|
+
// above the keyboard so we just neet to scroll the extra
|
|
273
|
+
// height part
|
|
274
|
+
if (textInputBottomPosition > keyboardPosition) {
|
|
275
|
+
// Since the system already scrolled the whole view up
|
|
276
|
+
// we should reduce that amount
|
|
277
|
+
keyboardSpace_1 =
|
|
278
|
+
keyboardSpace_1 -
|
|
279
|
+
(textInputBottomPosition - keyboardPosition);
|
|
280
|
+
_this.setState({ keyboardSpace: keyboardSpace_1 });
|
|
281
|
+
_this.scrollForExtraHeightOnAndroid(totalExtraHeight);
|
|
282
|
+
}
|
|
283
|
+
else if (textInputBottomPosition >
|
|
284
|
+
keyboardPosition - totalExtraHeight) {
|
|
285
|
+
_this.scrollForExtraHeightOnAndroid(totalExtraHeight -
|
|
286
|
+
(keyboardPosition - textInputBottomPosition));
|
|
287
|
+
}
|
|
294
288
|
}
|
|
295
289
|
});
|
|
296
290
|
}
|
|
297
|
-
|
|
298
|
-
if (!_this.defaultResetScrollToCoords) {
|
|
299
|
-
_this.defaultResetScrollToCoords = _this.position;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
_this._resetKeyboardSpace = function () {
|
|
304
|
-
var keyboardSpace = _this.props.viewIsInsideTabBar
|
|
305
|
-
? _KAM_DEFAULT_TAB_BAR_HEIGHT
|
|
306
|
-
: 0;
|
|
307
|
-
_this.setState({ keyboardSpace: keyboardSpace });
|
|
308
|
-
// Reset scroll position after keyboard dismissal
|
|
309
|
-
if (_this.props.enableResetScrollToCoords === false) {
|
|
310
|
-
_this.defaultResetScrollToCoords = null;
|
|
311
|
-
return;
|
|
312
|
-
}
|
|
313
|
-
else if (_this.props.resetScrollToCoords) {
|
|
314
|
-
_this.scrollToPosition(_this.props.resetScrollToCoords.x, _this.props.resetScrollToCoords.y, true);
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
if (_this.defaultResetScrollToCoords) {
|
|
318
|
-
_this.scrollToPosition(_this.defaultResetScrollToCoords.x, _this.defaultResetScrollToCoords.y, true);
|
|
319
|
-
_this.defaultResetScrollToCoords = null;
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
_this.scrollToPosition(0, 0, true);
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
_this._scrollToFocusedInputWithNodeHandle = function (nodeID, extraHeight, keyboardOpeningTime) {
|
|
327
|
-
if (extraHeight === undefined) {
|
|
328
|
-
extraHeight = _this.props.extraHeight;
|
|
329
|
-
}
|
|
330
|
-
var reactNode = (0, react_native_1.findNodeHandle)(nodeID);
|
|
331
|
-
_this.scrollToFocusedInput(reactNode, extraHeight + _this.props.extraScrollHeight, keyboardOpeningTime !== undefined
|
|
332
|
-
? keyboardOpeningTime
|
|
333
|
-
: _this.props.keyboardOpeningTime || 0);
|
|
334
|
-
};
|
|
335
|
-
_this._handleOnScroll = function (e) {
|
|
336
|
-
_this.position = e.nativeEvent.contentOffset;
|
|
337
|
-
};
|
|
338
|
-
_this._handleRef = function (ref) {
|
|
339
|
-
_this._rnkasv_keyboardView = ref ? hocOptions.extractNativeRef(ref) : ref;
|
|
340
|
-
if (_this.props.innerRef) {
|
|
341
|
-
_this.props.innerRef(_this._rnkasv_keyboardView);
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
_this.update = function () {
|
|
345
|
-
var currentlyFocusedField = react_native_1.TextInput.State.currentlyFocusedInput ?
|
|
346
|
-
(0, react_native_1.findNodeHandle)(react_native_1.TextInput.State.currentlyFocusedInput()) : react_native_1.TextInput.State.currentlyFocusedField();
|
|
347
|
-
var responder = _this.getScrollResponder();
|
|
348
|
-
if (!currentlyFocusedField || !responder) {
|
|
349
|
-
return;
|
|
350
|
-
}
|
|
351
|
-
_this._scrollToFocusedInputWithNodeHandle(currentlyFocusedField);
|
|
352
|
-
};
|
|
353
|
-
_this.keyboardWillShowEvent = undefined;
|
|
354
|
-
_this.keyboardWillHideEvent = undefined;
|
|
355
|
-
_this.callbacks = {};
|
|
356
|
-
_this.position = { x: 0, y: 0 };
|
|
357
|
-
_this.defaultResetScrollToCoords = null;
|
|
358
|
-
var keyboardSpace = props.viewIsInsideTabBar
|
|
359
|
-
? _KAM_DEFAULT_TAB_BAR_HEIGHT
|
|
360
|
-
: 0;
|
|
361
|
-
_this.state = { keyboardSpace: keyboardSpace };
|
|
362
|
-
return _this;
|
|
291
|
+
});
|
|
363
292
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
// Keyboard events
|
|
368
|
-
if (react_native_1.Platform.OS === 'ios') {
|
|
369
|
-
this.keyboardWillShowEvent = react_native_1.Keyboard.addListener('keyboardWillShow', this._updateKeyboardSpace);
|
|
370
|
-
this.keyboardWillHideEvent = react_native_1.Keyboard.addListener('keyboardWillHide', this._resetKeyboardSpace);
|
|
293
|
+
if (!_this.props.resetScrollToCoords) {
|
|
294
|
+
if (!_this.defaultResetScrollToCoords) {
|
|
295
|
+
_this.defaultResetScrollToCoords = _this.position;
|
|
371
296
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
_this._resetKeyboardSpace = function () {
|
|
300
|
+
var keyboardSpace = _this.props.viewIsInsideTabBar
|
|
301
|
+
? _KAM_DEFAULT_TAB_BAR_HEIGHT
|
|
302
|
+
: 0;
|
|
303
|
+
_this.setState({ keyboardSpace: keyboardSpace });
|
|
304
|
+
// Reset scroll position after keyboard dismissal
|
|
305
|
+
if (_this.props.enableResetScrollToCoords === false) {
|
|
306
|
+
_this.defaultResetScrollToCoords = null;
|
|
307
|
+
return;
|
|
308
|
+
}
|
|
309
|
+
else if (_this.props.resetScrollToCoords) {
|
|
310
|
+
_this.scrollToPosition(_this.props.resetScrollToCoords.x, _this.props.resetScrollToCoords.y, true);
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
if (_this.defaultResetScrollToCoords) {
|
|
314
|
+
_this.scrollToPosition(_this.defaultResetScrollToCoords.x, _this.defaultResetScrollToCoords.y, true);
|
|
315
|
+
_this.defaultResetScrollToCoords = null;
|
|
391
316
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
this.mountedComponent = false;
|
|
395
|
-
this.keyboardWillShowEvent && this.keyboardWillShowEvent.remove();
|
|
396
|
-
this.keyboardWillHideEvent && this.keyboardWillHideEvent.remove();
|
|
397
|
-
Object.values(this.callbacks).forEach(function (callback) { return callback.remove(); });
|
|
398
|
-
};
|
|
399
|
-
class_1.prototype.render = function () {
|
|
400
|
-
var _a;
|
|
401
|
-
var _b = this.props, enableOnAndroid = _b.enableOnAndroid, contentContainerStyle = _b.contentContainerStyle, onScroll = _b.onScroll;
|
|
402
|
-
var newContentContainerStyle;
|
|
403
|
-
if (react_native_1.Platform.OS === 'android' && enableOnAndroid) {
|
|
404
|
-
newContentContainerStyle = [].concat(contentContainerStyle).concat({
|
|
405
|
-
paddingBottom: ((contentContainerStyle || {}).paddingBottom || 0) +
|
|
406
|
-
this.state.keyboardSpace,
|
|
407
|
-
});
|
|
317
|
+
else {
|
|
318
|
+
_this.scrollToPosition(0, 0, true);
|
|
408
319
|
}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
_this._scrollToFocusedInputWithNodeHandle = function (nodeID, extraHeight, keyboardOpeningTime) {
|
|
323
|
+
if (extraHeight === undefined) {
|
|
324
|
+
extraHeight = _this.props.extraHeight;
|
|
325
|
+
}
|
|
326
|
+
var reactNode = (0, react_native_1.findNodeHandle)(nodeID);
|
|
327
|
+
_this.scrollToFocusedInput(reactNode, extraHeight + _this.props.extraScrollHeight, keyboardOpeningTime !== undefined
|
|
328
|
+
? keyboardOpeningTime
|
|
329
|
+
: _this.props.keyboardOpeningTime || 0);
|
|
330
|
+
};
|
|
331
|
+
_this._handleOnScroll = function (e) {
|
|
332
|
+
_this.position = e.nativeEvent.contentOffset;
|
|
333
|
+
};
|
|
334
|
+
_this._handleRef = function (ref) {
|
|
335
|
+
_this._rnkasv_keyboardView = ref ? _this.props.hocOptions.extractNativeRef(ref) : ref;
|
|
336
|
+
if (_this.props.innerRef) {
|
|
337
|
+
_this.props.innerRef(_this._rnkasv_keyboardView);
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
_this.update = function () {
|
|
341
|
+
var currentlyFocusedField = react_native_1.TextInput.State.currentlyFocusedInput ?
|
|
342
|
+
(0, react_native_1.findNodeHandle)(react_native_1.TextInput.State.currentlyFocusedInput()) : react_native_1.TextInput.State.currentlyFocusedField();
|
|
343
|
+
var responder = _this.getScrollResponder();
|
|
344
|
+
if (!currentlyFocusedField || !responder) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
_this._scrollToFocusedInputWithNodeHandle(currentlyFocusedField);
|
|
348
|
+
};
|
|
349
|
+
_this.keyboardWillShowEvent = undefined;
|
|
350
|
+
_this.keyboardWillHideEvent = undefined;
|
|
351
|
+
_this.callbacks = {};
|
|
352
|
+
_this.position = { x: 0, y: 0 };
|
|
353
|
+
_this.defaultResetScrollToCoords = null;
|
|
354
|
+
var keyboardSpace = props.viewIsInsideTabBar
|
|
355
|
+
? _KAM_DEFAULT_TAB_BAR_HEIGHT
|
|
356
|
+
: 0;
|
|
357
|
+
_this.state = { keyboardSpace: keyboardSpace };
|
|
358
|
+
return _this;
|
|
359
|
+
}
|
|
360
|
+
KeyboardAwareScrollable.prototype.componentDidMount = function () {
|
|
361
|
+
var _this = this;
|
|
362
|
+
this.mountedComponent = true;
|
|
363
|
+
// Keyboard events
|
|
364
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
365
|
+
this.keyboardWillShowEvent = react_native_1.Keyboard.addListener('keyboardWillShow', this._updateKeyboardSpace);
|
|
366
|
+
this.keyboardWillHideEvent = react_native_1.Keyboard.addListener('keyboardWillHide', this._resetKeyboardSpace);
|
|
367
|
+
}
|
|
368
|
+
else if (react_native_1.Platform.OS === 'android' && this.props.enableOnAndroid) {
|
|
369
|
+
this.keyboardWillShowEvent = react_native_1.Keyboard.addListener('keyboardDidShow', this._updateKeyboardSpace);
|
|
370
|
+
this.keyboardWillHideEvent = react_native_1.Keyboard.addListener('keyboardDidHide', this._resetKeyboardSpace);
|
|
371
|
+
}
|
|
372
|
+
supportedKeyboardEvents.forEach(function (eventName) {
|
|
373
|
+
var callbackName = keyboardEventToCallbackName(eventName);
|
|
374
|
+
if (_this.props[callbackName]) {
|
|
375
|
+
_this.callbacks[eventName] = react_native_1.Keyboard.addListener(eventName, _this.props[callbackName]);
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
};
|
|
379
|
+
KeyboardAwareScrollable.prototype.componentDidUpdate = function (prevProps) {
|
|
380
|
+
if (this.props.viewIsInsideTabBar !== prevProps.viewIsInsideTabBar) {
|
|
381
|
+
var keyboardSpace = this.props.viewIsInsideTabBar
|
|
382
|
+
? _KAM_DEFAULT_TAB_BAR_HEIGHT
|
|
383
|
+
: 0;
|
|
384
|
+
if (this.state.keyboardSpace !== keyboardSpace) {
|
|
385
|
+
this.setState({ keyboardSpace: keyboardSpace });
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
KeyboardAwareScrollable.prototype.componentWillUnmount = function () {
|
|
390
|
+
this.mountedComponent = false;
|
|
391
|
+
this.keyboardWillShowEvent && this.keyboardWillShowEvent.remove();
|
|
392
|
+
this.keyboardWillHideEvent && this.keyboardWillHideEvent.remove();
|
|
393
|
+
Object.values(this.callbacks).forEach(function (callback) { return callback.remove(); });
|
|
394
|
+
};
|
|
395
|
+
KeyboardAwareScrollable.prototype.render = function () {
|
|
396
|
+
var _a;
|
|
397
|
+
var _b = this.props, enableOnAndroid = _b.enableOnAndroid, contentContainerStyle = _b.contentContainerStyle, onScroll = _b.onScroll, Scrollable = _b.Scrollable;
|
|
398
|
+
var newContentContainerStyle;
|
|
399
|
+
if (react_native_1.Platform.OS === 'android' && enableOnAndroid) {
|
|
400
|
+
newContentContainerStyle = [].concat(contentContainerStyle).concat({
|
|
401
|
+
paddingBottom: ((contentContainerStyle || {}).paddingBottom || 0) +
|
|
402
|
+
this.state.keyboardSpace,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
var refProps = (_a = {}, _a[this.props.hocOptions.refPropName] = this._handleRef, _a);
|
|
406
|
+
return (<Scrollable {...refProps} keyboardDismissMode='interactive' contentInset={{ bottom: this.state.keyboardSpace }} automaticallyAdjustContentInsets={false} showsVerticalScrollIndicator={true} scrollEventThrottle={1} {...this.props} contentContainerStyle={newContentContainerStyle || contentContainerStyle} keyboardSpace={this.state.keyboardSpace} getScrollResponder={this.getScrollResponder} scrollToPosition={this.scrollToPosition} scrollToEnd={this.scrollToEnd} scrollForExtraHeightOnAndroid={this.scrollForExtraHeightOnAndroid} scrollToFocusedInput={this.scrollToFocusedInput} scrollIntoView={this.scrollIntoView} resetKeyboardSpace={this._resetKeyboardSpace} handleOnScroll={this._handleOnScroll} update={this.update}
|
|
407
|
+
// @ts-ignore
|
|
408
|
+
onScroll={react_native_1.Animated.forkEvent(onScroll, this._handleOnScroll)}/>);
|
|
409
|
+
};
|
|
410
|
+
KeyboardAwareScrollable.displayName = "KeyboardAware";
|
|
411
|
+
KeyboardAwareScrollable.propTypes = __assign({ viewIsInsideTabBar: prop_types_1.default.bool, resetScrollToCoords: prop_types_1.default.shape({
|
|
412
|
+
x: prop_types_1.default.number.isRequired,
|
|
413
|
+
y: prop_types_1.default.number.isRequired,
|
|
414
|
+
}), enableResetScrollToCoords: prop_types_1.default.bool, enableAutomaticScroll: prop_types_1.default.bool, extraHeight: prop_types_1.default.number, extraScrollHeight: prop_types_1.default.number, keyboardOpeningTime: prop_types_1.default.number, onScroll: prop_types_1.default.oneOfType([
|
|
415
|
+
prop_types_1.default.func,
|
|
416
|
+
prop_types_1.default.object, // Animated.event listener
|
|
417
|
+
]), update: prop_types_1.default.func, contentContainerStyle: prop_types_1.default.any, enableOnAndroid: prop_types_1.default.bool, innerRef: prop_types_1.default.func }, keyboardEventPropTypes);
|
|
418
|
+
// HOC options are used to init default props, so that these options can be overriden with component props
|
|
419
|
+
KeyboardAwareScrollable.defaultProps = {
|
|
420
|
+
enableAutomaticScroll: ScrollIntoViewDefaultOptions.enableAutomaticScroll,
|
|
421
|
+
extraHeight: ScrollIntoViewDefaultOptions.extraHeight,
|
|
422
|
+
extraScrollHeight: ScrollIntoViewDefaultOptions.extraScrollHeight,
|
|
423
|
+
enableResetScrollToCoords: ScrollIntoViewDefaultOptions.enableResetScrollToCoords,
|
|
424
|
+
keyboardOpeningTime: ScrollIntoViewDefaultOptions.keyboardOpeningTime,
|
|
425
|
+
viewIsInsideTabBar: ScrollIntoViewDefaultOptions.viewIsInsideTabBar,
|
|
426
|
+
enableOnAndroid: ScrollIntoViewDefaultOptions.enableOnAndroid,
|
|
427
|
+
};
|
|
428
|
+
return KeyboardAwareScrollable;
|
|
429
|
+
}(react_1.default.Component));
|
|
430
|
+
function KeyboardAwareHOC(ScrollableComponent, userOptions) {
|
|
431
|
+
if (userOptions === void 0) { userOptions = ScrollIntoViewDefaultOptions; }
|
|
432
|
+
var hocOptions = __assign(__assign({}, ScrollIntoViewDefaultOptions), userOptions);
|
|
433
|
+
return react_1.default.forwardRef(function (props, ref) { return <KeyboardAwareScrollable hocOptions={hocOptions}
|
|
434
|
+
// @ts-ignore
|
|
435
|
+
ref={ref} Scrollable={ScrollableComponent} {...props}/>; });
|
|
435
436
|
}
|
|
436
437
|
// Allow to pass options, without breaking change, and curried for composition
|
|
437
438
|
// listenToKeyboardEvents(ScrollView);
|