react-native-dodge-keyboard 1.0.4 → 1.0.5
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/index.js +27 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -28,6 +28,7 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
|
|
|
28
28
|
const previousLift = useRef();
|
|
29
29
|
const wasVisible = useRef();
|
|
30
30
|
const pendingIdleTask = useRef();
|
|
31
|
+
const resizerTimer = useRef();
|
|
31
32
|
const lastKeyboardEvent = useRef();
|
|
32
33
|
|
|
33
34
|
const clearPreviousDodge = (scrollId) => {
|
|
@@ -45,9 +46,9 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
|
|
|
45
46
|
/**
|
|
46
47
|
* @param {import('react-native').KeyboardEvent | undefined} event
|
|
47
48
|
* @param {boolean} visible
|
|
48
|
-
* @param {boolean}
|
|
49
|
+
* @param {{ fromIdle?: boolean, fromTimer?: boolean } | undefined} eventContext
|
|
49
50
|
*/
|
|
50
|
-
doDodgeKeyboard.current = (event, visible,
|
|
51
|
+
doDodgeKeyboard.current = (event, visible, eventContext) => {
|
|
51
52
|
if (Platform.OS === 'ios' && event && !event?.isEventFromThisApp) return;
|
|
52
53
|
|
|
53
54
|
if (typeof visible !== 'boolean') {
|
|
@@ -68,6 +69,10 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
|
|
|
68
69
|
cancelIdleCallback(pendingIdleTask.current);
|
|
69
70
|
pendingIdleTask.current = undefined;
|
|
70
71
|
|
|
72
|
+
if (resizerTimer.current !== undefined)
|
|
73
|
+
clearTimeout(resizerTimer.current);
|
|
74
|
+
resizerTimer.current = undefined;
|
|
75
|
+
|
|
71
76
|
if (
|
|
72
77
|
visible &&
|
|
73
78
|
keyboardInfo &&
|
|
@@ -84,10 +89,15 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
|
|
|
84
89
|
).flat();
|
|
85
90
|
|
|
86
91
|
const initIdleTask = () => {
|
|
87
|
-
if (!
|
|
92
|
+
if (!eventContext && pendingIdleTask.current === undefined)
|
|
88
93
|
pendingIdleTask.current = requestIdleCallback(() => {
|
|
89
|
-
doDodgeKeyboard.current(undefined, undefined, true);
|
|
90
|
-
});
|
|
94
|
+
doDodgeKeyboard.current(undefined, undefined, { fromIdle: true });
|
|
95
|
+
}, { timeout: 300 });
|
|
96
|
+
|
|
97
|
+
if (!eventContext?.fromTimer && resizerTimer.current === undefined)
|
|
98
|
+
resizerTimer.current = setTimeout(() => {
|
|
99
|
+
doDodgeKeyboard.current(undefined, undefined, { fromTimer: true });
|
|
100
|
+
}, 500);
|
|
91
101
|
}
|
|
92
102
|
|
|
93
103
|
const checkFocused = checkIfElementIsFocused || (r => r?.isFocused?.());
|
|
@@ -218,11 +228,19 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
|
|
|
218
228
|
if (disabled) return;
|
|
219
229
|
const frameListener = Keyboard.addListener('keyboardDidChangeFrame', e => doDodgeKeyboard.current(e));
|
|
220
230
|
const showListener = Keyboard.addListener(
|
|
221
|
-
|
|
231
|
+
'keyboardWillShow',
|
|
222
232
|
e => doDodgeKeyboard.current(e, true)
|
|
223
233
|
);
|
|
224
234
|
const hiddenListener = Keyboard.addListener(
|
|
225
|
-
|
|
235
|
+
'keyboardWillHide',
|
|
236
|
+
e => doDodgeKeyboard.current(e, false)
|
|
237
|
+
);
|
|
238
|
+
const didShowListener = Keyboard.addListener(
|
|
239
|
+
'keyboardDidShow',
|
|
240
|
+
e => doDodgeKeyboard.current(e, true)
|
|
241
|
+
);
|
|
242
|
+
const didHideListener = Keyboard.addListener(
|
|
243
|
+
'keyboardDidHide',
|
|
226
244
|
e => doDodgeKeyboard.current(e, false)
|
|
227
245
|
);
|
|
228
246
|
|
|
@@ -230,6 +248,8 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
|
|
|
230
248
|
frameListener.remove();
|
|
231
249
|
showListener.remove();
|
|
232
250
|
hiddenListener.remove();
|
|
251
|
+
didShowListener.remove();
|
|
252
|
+
didHideListener.remove();
|
|
233
253
|
}
|
|
234
254
|
}, [!disabled]);
|
|
235
255
|
|
package/package.json
CHANGED