react-native-dodge-keyboard 1.0.6 → 1.0.7

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.
Files changed (2) hide show
  1. package/index.js +18 -5
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { Children, cloneElement, createElement, forwardRef, isValidElement, memo, useEffect, useMemo, useRef, useState } from "react";
1
+ import { Children, cloneElement, createElement, forwardRef, isValidElement, memo, useEffect, useMemo, useRef, useState, useImperativeHandle } from "react";
2
2
  import { Animated, Dimensions, findNodeHandle, Keyboard, Platform, StyleSheet, UIManager, useAnimatedValue } from "react-native";
3
3
 
4
- export default function ({ children, offset = 10, disabled, onHandleDodging, disableTagCheck, checkIfElementIsFocused }) {
4
+ const DodgeKeyboard = forwardRef(({ children, offset = 10, disabled, onHandleDodging, disableTagCheck, checkIfElementIsFocused }, ref) => {
5
5
  if (checkIfElementIsFocused !== undefined) {
6
6
  if (typeof checkIfElementIsFocused !== 'function')
7
7
  throw 'checkIfElementIsFocused should be a function';
@@ -97,7 +97,7 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
97
97
  if (!eventContext?.fromTimer && resizerTimer.current === undefined)
98
98
  resizerTimer.current = setTimeout(() => {
99
99
  doDodgeKeyboard.current(undefined, undefined, { fromTimer: true });
100
- }, 700);
100
+ }, 500);
101
101
  }
102
102
 
103
103
  const checkFocused = checkIfElementIsFocused || (r => r?.isFocused?.());
@@ -224,7 +224,14 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
224
224
  useEffect(() => {
225
225
  if (currentPaddedScroller) {
226
226
  const ref = viewRefsMap.current[paddedId]?.scrollRef;
227
- tryPerformScroll(ref, paddedScroll, false);
227
+ if (Platform.OS === 'android') {
228
+ tryPerformScroll(ref, paddedScroll, false);
229
+ } else {
230
+ // this seem to be removing `the flash bang` on IOS
231
+ setTimeout(() => {
232
+ tryPerformScroll(ref, paddedScroll, false);
233
+ }, 1);
234
+ }
228
235
  }
229
236
  }, [currentPaddedScroller]);
230
237
 
@@ -232,6 +239,10 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
232
239
  doDodgeKeyboard.current();
233
240
  }, [offset, !disabled]);
234
241
 
242
+ useImperativeHandle(ref, () => ({
243
+ trigger: () => doDodgeKeyboard.current()
244
+ }), []);
245
+
235
246
  useEffect(() => {
236
247
  if (disabled) return;
237
248
  const frameListener = Keyboard.addListener('keyboardDidChangeFrame', e => doDodgeKeyboard.current(e));
@@ -424,7 +435,9 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
424
435
  {children}
425
436
  </ReactHijacker>
426
437
  );
427
- };
438
+ });
439
+
440
+ export default DodgeKeyboard;
428
441
 
429
442
  const niceFunction = (func, message) => {
430
443
  return (...args) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-dodge-keyboard",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "react-native-dodge-keyboard is a tiny library designed to flawlessly move your UI out of the way of the keyboard",
5
5
  "keywords": [
6
6
  "react-native",