react-native-snap-sheet 1.0.4 → 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 +2 -2
- package/src/snapsheet.js +26 -13
- package/src/snapsheet_modal.js +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-snap-sheet",
|
|
3
|
-
"version": "1.0.
|
|
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.
|
|
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
|
@@ -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,9 +309,13 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
309
309
|
|
|
310
310
|
const instanceIdIterator = useRef(0);
|
|
311
311
|
const prevKE = useRef();
|
|
312
|
+
const isLifting = useRef();
|
|
313
|
+
const lastLiftInstance = useRef(0);
|
|
314
|
+
|
|
315
|
+
const quicklyDodgeKeyboard = async (event) => {
|
|
316
|
+
let { liftUp, keyboardEvent } = event;
|
|
317
|
+
// console.log('quicklyDodgeKeyboard event:', event);
|
|
312
318
|
|
|
313
|
-
const quicklyDodgeKeyboard = (offset, keyboardEvent) => {
|
|
314
|
-
// console.log('quicklyDodgeKeyboard offset:', offset, ' keyboardEvent:', keyboardEvent);
|
|
315
319
|
if (!keyboardEvent) {
|
|
316
320
|
if (!(keyboardEvent = prevKE.current)) return;
|
|
317
321
|
}
|
|
@@ -320,16 +324,27 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
320
324
|
} else {
|
|
321
325
|
if (prevKE.current) keyboardEvent = prevKE.current;
|
|
322
326
|
}
|
|
327
|
+
const thisRef = ++lastLiftInstance.current;
|
|
328
|
+
|
|
329
|
+
const kh = keyboardEvent?.endCoordinates?.height || 0;
|
|
330
|
+
const realSnapPoint = initSnapPoints[lastSnapIndex.current];
|
|
323
331
|
|
|
324
|
-
const
|
|
325
|
-
const
|
|
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;
|
|
326
335
|
|
|
327
|
-
// console.log('newPosY:',
|
|
336
|
+
// console.log('newPosY:', newY, ' timing newDuration:', newDuration, ' newDodgeOffset:', newDodgeOffset);
|
|
337
|
+
isLifting.current = true;
|
|
328
338
|
Animated.timing(translateY, {
|
|
329
|
-
duration: newDuration || 0,
|
|
330
|
-
toValue:
|
|
339
|
+
duration: Math.max((newDuration || 0) - 70, 0),
|
|
340
|
+
toValue: newY,
|
|
331
341
|
useNativeDriver: true
|
|
332
|
-
}).start()
|
|
342
|
+
}).start(() => {
|
|
343
|
+
if (thisRef === lastLiftInstance.current) {
|
|
344
|
+
isLifting.current = false;
|
|
345
|
+
setDodgeOffset(newDodgeOffset);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
333
348
|
}
|
|
334
349
|
|
|
335
350
|
return (
|
|
@@ -349,10 +364,7 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
349
364
|
offset={keyboardDodgingOffset}
|
|
350
365
|
disabled={!sameIndex || disableDodging}
|
|
351
366
|
checkIfElementIsFocused={__checkIfElementIsFocused}
|
|
352
|
-
onHandleDodging={
|
|
353
|
-
quicklyDodgeKeyboard(liftUp, keyboardEvent);
|
|
354
|
-
setDodgeOffset(liftUp);
|
|
355
|
-
}}>
|
|
367
|
+
onHandleDodging={quicklyDodgeKeyboard}>
|
|
356
368
|
{ReactHijacker({
|
|
357
369
|
children,
|
|
358
370
|
enableLocator: true,
|
|
@@ -421,6 +433,7 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
421
433
|
}
|
|
422
434
|
}}
|
|
423
435
|
dodge_keyboard_input
|
|
436
|
+
dodge_keyboard_clipping
|
|
424
437
|
style={styling.fakePlaceholder}
|
|
425
438
|
/> : null}
|
|
426
439
|
</DodgeKeyboard>
|
package/src/snapsheet_modal.js
CHANGED
|
@@ -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] &&
|
|
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>}
|
|
@@ -309,9 +312,9 @@ export const SnapSheetModalBase = forwardRef(function SnapSheetModalBase({
|
|
|
309
312
|
const flatStyle = StyleSheet.flatten(containerStyle);
|
|
310
313
|
|
|
311
314
|
return {
|
|
312
|
-
zIndex: hasClosed ? -99 :
|
|
313
|
-
elevation: hasClosed ? 0 :
|
|
314
|
-
...hasClosed ? { opacity: 0
|
|
315
|
+
zIndex: hasClosed ? -99 : 9999,
|
|
316
|
+
elevation: hasClosed ? 0 : 9999,
|
|
317
|
+
...hasClosed ? { opacity: 0 } : {},
|
|
315
318
|
...flatStyle,
|
|
316
319
|
position: 'absolute',
|
|
317
320
|
width: '100%',
|