react-native-dodge-keyboard 1.0.1 → 1.0.2

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 (3) hide show
  1. package/TODO +1 -0
  2. package/index.js +17 -6
  3. package/package.json +1 -1
package/TODO ADDED
@@ -0,0 +1 @@
1
+ keyboard not dodging in state changes
package/index.js CHANGED
@@ -41,7 +41,7 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
41
41
  const keyboardInfo = Keyboard.metrics();
42
42
  const { width: windowWidth, height: windowHeight } = Dimensions.get('window');
43
43
 
44
- console.log('doDodgeKeyboard');
44
+ // console.log('doDodgeKeyboard');
45
45
  if (
46
46
  isKeyboardVisible.current &&
47
47
  keyboardInfo &&
@@ -97,7 +97,7 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
97
97
  const scrollLift = Math.max(0, (sy + sh + (thisOffset >= 0 ? thisOffset : 0)) - keyboardInfo.screenY);
98
98
  const newScrollY = Math.min(requiredScrollY, t);
99
99
 
100
- console.log('scrolling-to:', requiredScrollY, ' scrollLift:', scrollLift);
100
+ // console.log('scrolling-to:', requiredScrollY, ' scrollLift:', scrollLift);
101
101
  if (scrollLift) {
102
102
  setCurrentPaddedScroller([scrollId, scrollLift, newScrollY]);
103
103
  } else {
@@ -195,6 +195,14 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
195
195
  const rootKeyExtractor = node.prop?.keyExtractor;
196
196
  const hasInternalList = !isStandalone && (typeof rootRenderItem === 'function' && !node.props?.children);
197
197
 
198
+ const doRefCleanup = () => {
199
+ if (
200
+ viewRefsMap.current[scrollId]?.scrollRef ||
201
+ Object.keys(viewRefsMap.current[scrollId]?.inputRef || {}).length
202
+ ) return;
203
+ delete viewRefsMap.current[scrollId];
204
+ }
205
+
198
206
  const injectChild = (children, childPath) =>
199
207
  ReactHijacker({
200
208
  children,
@@ -232,6 +240,7 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
232
240
  viewRefsMap.current[scrollId].inputRef[inputId].ref = r;
233
241
  } else if (viewRefsMap.current[scrollId]?.inputRef?.[inputId]) {
234
242
  delete viewRefsMap.current[scrollId].inputRef[inputId];
243
+ doRefCleanup();
235
244
  }
236
245
 
237
246
  const thatRef = inputNode.props?.ref;
@@ -259,7 +268,8 @@ export default function ({ children, offset = 10, disabled, onHandleDodging, dis
259
268
  initNode();
260
269
  viewRefsMap.current[scrollId].scrollRef = r;
261
270
  } else if (viewRefsMap.current[scrollId]) {
262
- delete viewRefsMap.current[scrollId];
271
+ viewRefsMap.current[scrollId].scrollRef = undefined;
272
+ doRefCleanup();
263
273
  }
264
274
 
265
275
  const thatRef = node.props?.ref;
@@ -325,14 +335,15 @@ export function ReactHijacker({ children, doHijack, path }) {
325
335
  const instantDoHijack = useRef();
326
336
  instantDoHijack.current = doHijack;
327
337
 
328
- const injectIntoTree = (node, path = [], wasArray) => {
338
+ const injectIntoTree = (node, path = [], arrayIndex) => {
329
339
  if (!node) return node;
330
340
  if (Array.isArray(node)) {
331
- return Children.map(node, (v, i) => injectIntoTree(v, [...path, i], true));
341
+ path = [...path, ...arrayIndex === undefined ? [0] : [arrayIndex]];
342
+ return Children.map(node, (v, i) => injectIntoTree(v, path, i));
332
343
  }
333
344
  if (!isValidElement(node)) return node;
334
345
 
335
- path = [...path, ...wasArray ? [] : [0], getNodeId(node)];
346
+ path = [...path, ...arrayIndex === undefined ? [0] : [arrayIndex], getNodeId(node)];
336
347
 
337
348
  let thisObj;
338
349
  if (thisObj = instantDoHijack.current?.(node, path)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-dodge-keyboard",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
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",