react-native-snap-sheet 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-snap-sheet",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
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.4",
22
+ "react-native-dodge-keyboard": "^1.0.5",
23
23
  "react-native-push-back": "^1.0.0"
24
24
  }
25
25
  }
package/src/snapsheet.js CHANGED
@@ -172,7 +172,7 @@ const SnapSheet = forwardRef(function SnapSheet({
172
172
  }));
173
173
 
174
174
  useEffect(() => {
175
- snapToIndex.current(Math.min(lastSnapIndex.current, snapPoints.length - 1), true);
175
+ if (!isLifting.current) snapToIndex.current(Math.min(lastSnapIndex.current, snapPoints.length - 1), true);
176
176
  }, [snapPointsKey]);
177
177
 
178
178
  const panResponder = useMemo(() => {
@@ -309,11 +309,17 @@ const SnapSheet = forwardRef(function SnapSheet({
309
309
 
310
310
  const instanceIdIterator = useRef(0);
311
311
  const prevKE = useRef();
312
+ const prevLiftOffset = useRef(0);
313
+ const isLifting = useRef();
312
314
 
313
315
  const quicklyDodgeKeyboard = (offset, keyboardEvent) => {
314
316
  // console.log('quicklyDodgeKeyboard offset:', offset, ' keyboardEvent:', keyboardEvent);
317
+
315
318
  if (!keyboardEvent) {
316
- if (!(keyboardEvent = prevKE.current)) return;
319
+ if (!(keyboardEvent = prevKE.current)) {
320
+ prevLiftOffset.current = offset;
321
+ return;
322
+ }
317
323
  }
318
324
  if (keyboardEvent.endCoordinates.height) {
319
325
  prevKE.current = keyboardEvent;
@@ -321,15 +327,24 @@ const SnapSheet = forwardRef(function SnapSheet({
321
327
  if (prevKE.current) keyboardEvent = prevKE.current;
322
328
  }
323
329
 
330
+ if (prevLiftOffset.current === offset) return;
331
+ prevLiftOffset.current = offset;
332
+
324
333
  const newPosY = MODAL_HEIGHT - (initSnapPoints[lastSnapIndex.current] + offset);
325
334
  const newDuration = (Math.abs(newPosY - translateY._value) * keyboardEvent.duration) / keyboardEvent?.endCoordinates.height;
326
335
 
327
336
  // console.log('newPosY:', newPosY, ' timing newDuration:', newDuration);
337
+ isLifting.current = true;
328
338
  Animated.timing(translateY, {
329
- duration: newDuration || 0,
339
+ duration: Math.max((newDuration || 0) - 70, 0),
330
340
  toValue: newPosY,
331
- useNativeDriver: true
332
- }).start();
341
+ useNativeDriver: false
342
+ }).start(() => {
343
+ if (offset === prevLiftOffset.current) {
344
+ isLifting.current = false;
345
+ setDodgeOffset(offset);
346
+ }
347
+ });
333
348
  }
334
349
 
335
350
  return (
@@ -351,7 +366,6 @@ const SnapSheet = forwardRef(function SnapSheet({
351
366
  checkIfElementIsFocused={__checkIfElementIsFocused}
352
367
  onHandleDodging={({ liftUp, keyboardEvent }) => {
353
368
  quicklyDodgeKeyboard(liftUp, keyboardEvent);
354
- setDodgeOffset(liftUp);
355
369
  }}>
356
370
  {ReactHijacker({
357
371
  children,
@@ -309,9 +309,9 @@ export const SnapSheetModalBase = forwardRef(function SnapSheetModalBase({
309
309
  const flatStyle = StyleSheet.flatten(containerStyle);
310
310
 
311
311
  return {
312
- zIndex: hasClosed ? -99 : isNumber(flatStyle?.zIndex) ? flatStyle?.zIndex : 9999,
313
- elevation: hasClosed ? 0 : isNumber(flatStyle?.elevation) ? flatStyle?.elevation : 9999,
314
- ...hasClosed ? { opacity: 0, display: 'none' } : {},
312
+ zIndex: hasClosed ? -99 : 9999,
313
+ elevation: hasClosed ? 0 : 9999,
314
+ ...hasClosed ? { opacity: 0 } : {},
315
315
  ...flatStyle,
316
316
  position: 'absolute',
317
317
  width: '100%',