react-native-snap-sheet 1.0.5 → 1.0.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-snap-sheet",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "homepage": "https://github.com/deflexable/react-native-snap-sheet#readme",
6
6
  "bugs": {
@@ -19,7 +19,7 @@
19
19
  "test": "echo \"Error: no test specified\" && exit 1"
20
20
  },
21
21
  "dependencies": {
22
- "react-native-dodge-keyboard": "^1.0.5",
22
+ "react-native-dodge-keyboard": "^1.0.6",
23
23
  "react-native-push-back": "^1.0.0"
24
24
  }
25
25
  }
package/src/snapsheet.js CHANGED
@@ -309,40 +309,40 @@ const SnapSheet = forwardRef(function SnapSheet({
309
309
 
310
310
  const instanceIdIterator = useRef(0);
311
311
  const prevKE = useRef();
312
- const prevLiftOffset = useRef(0);
313
312
  const isLifting = useRef();
313
+ const lastLiftInstance = useRef(0);
314
314
 
315
- const quicklyDodgeKeyboard = (offset, keyboardEvent) => {
316
- // console.log('quicklyDodgeKeyboard offset:', offset, ' keyboardEvent:', keyboardEvent);
315
+ const quicklyDodgeKeyboard = async (event) => {
316
+ let { liftUp, keyboardEvent } = event;
317
+ // console.log('quicklyDodgeKeyboard event:', event);
317
318
 
318
319
  if (!keyboardEvent) {
319
- if (!(keyboardEvent = prevKE.current)) {
320
- prevLiftOffset.current = offset;
321
- return;
322
- }
320
+ if (!(keyboardEvent = prevKE.current)) return;
323
321
  }
324
322
  if (keyboardEvent.endCoordinates.height) {
325
323
  prevKE.current = keyboardEvent;
326
324
  } else {
327
325
  if (prevKE.current) keyboardEvent = prevKE.current;
328
326
  }
327
+ const thisRef = ++lastLiftInstance.current;
329
328
 
330
- if (prevLiftOffset.current === offset) return;
331
- prevLiftOffset.current = offset;
329
+ const kh = keyboardEvent?.endCoordinates?.height || 0;
330
+ const realSnapPoint = initSnapPoints[lastSnapIndex.current];
332
331
 
333
- const newPosY = MODAL_HEIGHT - (initSnapPoints[lastSnapIndex.current] + offset);
334
- const newDuration = (Math.abs(newPosY - translateY._value) * keyboardEvent.duration) / keyboardEvent?.endCoordinates.height;
332
+ const newY = liftUp ? translateY._value - liftUp : (MODAL_HEIGHT - realSnapPoint);
333
+ const newDodgeOffset = (MODAL_HEIGHT - newY) - realSnapPoint;
334
+ const newDuration = kh > 0 ? (Math.min(Math.abs(liftUp), kh) / kh) * keyboardEvent.duration : 0;
335
335
 
336
- // console.log('newPosY:', newPosY, ' timing newDuration:', newDuration);
336
+ // console.log('newPosY:', newY, ' timing newDuration:', newDuration, ' newDodgeOffset:', newDodgeOffset);
337
337
  isLifting.current = true;
338
338
  Animated.timing(translateY, {
339
339
  duration: Math.max((newDuration || 0) - 70, 0),
340
- toValue: newPosY,
341
- useNativeDriver: false
340
+ toValue: newY,
341
+ useNativeDriver: true
342
342
  }).start(() => {
343
- if (offset === prevLiftOffset.current) {
343
+ if (thisRef === lastLiftInstance.current) {
344
344
  isLifting.current = false;
345
- setDodgeOffset(offset);
345
+ setDodgeOffset(newDodgeOffset);
346
346
  }
347
347
  });
348
348
  }
@@ -364,9 +364,7 @@ const SnapSheet = forwardRef(function SnapSheet({
364
364
  offset={keyboardDodgingOffset}
365
365
  disabled={!sameIndex || disableDodging}
366
366
  checkIfElementIsFocused={__checkIfElementIsFocused}
367
- onHandleDodging={({ liftUp, keyboardEvent }) => {
368
- quicklyDodgeKeyboard(liftUp, keyboardEvent);
369
- }}>
367
+ onHandleDodging={quicklyDodgeKeyboard}>
370
368
  {ReactHijacker({
371
369
  children,
372
370
  enableLocator: true,
@@ -435,6 +433,7 @@ const SnapSheet = forwardRef(function SnapSheet({
435
433
  }
436
434
  }}
437
435
  dodge_keyboard_input
436
+ dodge_keyboard_clipping
438
437
  style={styling.fakePlaceholder}
439
438
  /> : null}
440
439
  </DodgeKeyboard>
@@ -256,7 +256,9 @@ export const SnapSheetModalBase = forwardRef(function SnapSheetModalBase({
256
256
  ...isLift ? {
257
257
  __checkIfElementIsFocused: (r, refs) => {
258
258
  const realChecker = restProps?.__checkIfElementIsFocused;
259
- return !!r?.[CheckFocusedNode] && refs.some(v => realChecker ? realChecker?.(v) : v?.isFocused?.());
259
+ return !!r?.[CheckFocusedNode] &&
260
+ !willClose &&
261
+ refs.some(v => realChecker ? realChecker?.(v) : v?.isFocused?.());
260
262
  },
261
263
  keyboardDodgingBehaviour: 'optimum'
262
264
  } : {}
@@ -298,6 +300,7 @@ export const SnapSheetModalBase = forwardRef(function SnapSheetModalBase({
298
300
  }
299
301
  }}
300
302
  dodge_keyboard_input
303
+ dodge_keyboard_clipping
301
304
  style={styling.fakePlaceholder}
302
305
  /> : null}
303
306
  </View>}