react-native-snap-sheet 1.0.6 → 1.0.8
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 +29 -9
- package/src/snapsheet_modal.js +3 -3
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.8",
|
|
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.8",
|
|
23
23
|
"react-native-push-back": "^1.0.0"
|
|
24
24
|
}
|
|
25
25
|
}
|
package/src/snapsheet.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState, cloneElement } from "react";
|
|
2
2
|
import { Animated, PanResponder, StyleSheet, useAnimatedValue, View } from "react-native";
|
|
3
|
-
import DodgeKeyboard,
|
|
3
|
+
import { DodgeKeyboard, createHijackedElement, ReactHijacker, __HijackNode } from "react-native-dodge-keyboard";
|
|
4
4
|
import { doRendable, isNumber, isPositiveNumber } from "./utils";
|
|
5
5
|
import { styling } from "./styling";
|
|
6
6
|
|
|
@@ -55,7 +55,7 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
55
55
|
if (isLift) {
|
|
56
56
|
const realChecker = __checkIfElementIsFocused;
|
|
57
57
|
__checkIfElementIsFocused = (r, refs) => {
|
|
58
|
-
return !!r?.[CheckFocusedNode] && refs.some(v => realChecker ? realChecker?.(v) : v?.isFocused?.());
|
|
58
|
+
return !!r?.[CheckFocusedNode] && refs.some(v => realChecker ? realChecker?.(v, refs) : v?.isFocused?.());
|
|
59
59
|
};
|
|
60
60
|
if (keyboardDodgingOffset === undefined) {
|
|
61
61
|
keyboardDodgingOffset = 0;
|
|
@@ -69,8 +69,6 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
69
69
|
|
|
70
70
|
const [scrollEnabled, setScrollEnabled] = useState(false);
|
|
71
71
|
const [dodgeOffset, setDodgeOffset] = useState(0);
|
|
72
|
-
const [currentIndex, setCurrentIndex] = useState(initialSnapIndex);
|
|
73
|
-
const [finishedIndex, setFinishedIndex] = useState(initialSnapIndex);
|
|
74
72
|
const [prefferedAnchor, setPrefferedAnchor] = useState();
|
|
75
73
|
|
|
76
74
|
snapPoints = snapPoints.map(v => v + dodgeOffset);
|
|
@@ -100,6 +98,7 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
100
98
|
* @type {import("react").RefObject<{[key: string]: { ref: import('react-native').ScrollView, scrollY: 0, location: number[], anchorId: boolean }}>}
|
|
101
99
|
*/
|
|
102
100
|
const scrollRefObj = useRef({});
|
|
101
|
+
const dodgeRef = useRef();
|
|
103
102
|
const lastOffset = useRef(translateY._value);
|
|
104
103
|
const lastSnapIndex = useRef(initialSnapIndex);
|
|
105
104
|
const instantPrefferAnchor = useRef();
|
|
@@ -120,6 +119,9 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
120
119
|
}
|
|
121
120
|
|
|
122
121
|
const snapToIndex = useRef();
|
|
122
|
+
const stillSnapping = useRef();
|
|
123
|
+
const lastSnappingInstance = useRef(0);
|
|
124
|
+
const shouldRefreshDodge = useRef();
|
|
123
125
|
|
|
124
126
|
snapToIndex.current = (index, force, velocity, onFinish) => {
|
|
125
127
|
if (disabled && !force) return;
|
|
@@ -133,7 +135,6 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
133
135
|
|
|
134
136
|
const prevY = translateY._value;
|
|
135
137
|
setScrollEnabled(index === snapPoints.length - 1);
|
|
136
|
-
setCurrentIndex(index);
|
|
137
138
|
|
|
138
139
|
// console.log('snapping:', index);
|
|
139
140
|
let wasFinished;
|
|
@@ -147,6 +148,8 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
147
148
|
const timeout = pixel * PixelRate;
|
|
148
149
|
|
|
149
150
|
const timer = setTimeout(guessFinish, Math.max(300, timeout));
|
|
151
|
+
const thisRef = ++lastSnappingInstance.current;
|
|
152
|
+
stillSnapping.current = true;
|
|
150
153
|
|
|
151
154
|
// console.log('snapTimer:', { timeout, pixel }, ' newY:', newY, ' snapPoint:', initSnapPoints, ' snapTrans:', snapTranslateValues);
|
|
152
155
|
|
|
@@ -156,8 +159,16 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
156
159
|
useNativeDriver: true
|
|
157
160
|
}).start(() => {
|
|
158
161
|
clearTimeout(timer);
|
|
159
|
-
setFinishedIndex(index);
|
|
160
162
|
guessFinish();
|
|
163
|
+
if (thisRef === lastSnappingInstance.current) {
|
|
164
|
+
requestIdleCallback(() => {
|
|
165
|
+
stillSnapping.current = false;
|
|
166
|
+
if (shouldRefreshDodge.current) {
|
|
167
|
+
isLifting.current = false;
|
|
168
|
+
if (dodgeRef.current) dodgeRef.current.trigger();
|
|
169
|
+
}
|
|
170
|
+
}, { timeout: 700 });
|
|
171
|
+
}
|
|
161
172
|
});
|
|
162
173
|
|
|
163
174
|
lastOffset.current = newY;
|
|
@@ -305,7 +316,6 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
305
316
|
}), [handleColor]);
|
|
306
317
|
|
|
307
318
|
const disableDodging = keyboardDodgingBehaviour === 'off';
|
|
308
|
-
const sameIndex = currentIndex === finishedIndex;
|
|
309
319
|
|
|
310
320
|
const instanceIdIterator = useRef(0);
|
|
311
321
|
const prevKE = useRef();
|
|
@@ -324,6 +334,16 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
324
334
|
} else {
|
|
325
335
|
if (prevKE.current) keyboardEvent = prevKE.current;
|
|
326
336
|
}
|
|
337
|
+
isLifting.current = true;
|
|
338
|
+
if (stillSnapping.current) {
|
|
339
|
+
if (!liftUp) {
|
|
340
|
+
isLifting.current = false;
|
|
341
|
+
setDodgeOffset(0);
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
344
|
+
shouldRefreshDodge.current = true;
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
327
347
|
const thisRef = ++lastLiftInstance.current;
|
|
328
348
|
|
|
329
349
|
const kh = keyboardEvent?.endCoordinates?.height || 0;
|
|
@@ -334,7 +354,6 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
334
354
|
const newDuration = kh > 0 ? (Math.min(Math.abs(liftUp), kh) / kh) * keyboardEvent.duration : 0;
|
|
335
355
|
|
|
336
356
|
// console.log('newPosY:', newY, ' timing newDuration:', newDuration, ' newDodgeOffset:', newDodgeOffset);
|
|
337
|
-
isLifting.current = true;
|
|
338
357
|
Animated.timing(translateY, {
|
|
339
358
|
duration: Math.max((newDuration || 0) - 70, 0),
|
|
340
359
|
toValue: newY,
|
|
@@ -361,8 +380,9 @@ const SnapSheet = forwardRef(function SnapSheet({
|
|
|
361
380
|
)}
|
|
362
381
|
<View style={styling.flexer}>
|
|
363
382
|
<DodgeKeyboard
|
|
383
|
+
ref={dodgeRef}
|
|
364
384
|
offset={keyboardDodgingOffset}
|
|
365
|
-
disabled={
|
|
385
|
+
disabled={disableDodging}
|
|
366
386
|
checkIfElementIsFocused={__checkIfElementIsFocused}
|
|
367
387
|
onHandleDodging={quicklyDodgeKeyboard}>
|
|
368
388
|
{ReactHijacker({
|
package/src/snapsheet_modal.js
CHANGED
|
@@ -78,6 +78,7 @@ export const SnapSheetModalBase = forwardRef(function SnapSheetModalBase({
|
|
|
78
78
|
useMemo(makeSizingPromise, []);
|
|
79
79
|
|
|
80
80
|
const sizingReady = !centered || (contentHeight !== undefined && viewHeight !== undefined);
|
|
81
|
+
const hasClosed = futureState === 'closed' && currentState === 'closed';
|
|
81
82
|
|
|
82
83
|
useEffect(() => {
|
|
83
84
|
if (sizingReady) {
|
|
@@ -103,7 +104,6 @@ export const SnapSheetModalBase = forwardRef(function SnapSheetModalBase({
|
|
|
103
104
|
|
|
104
105
|
const willClose = futureState === 'closed';
|
|
105
106
|
const isOpened = futureState !== 'closed';
|
|
106
|
-
const hasClosed = futureState === 'closed' && currentState === 'closed';
|
|
107
107
|
|
|
108
108
|
const sheetRef = useRef();
|
|
109
109
|
const inputRefs = useRef({});
|
|
@@ -179,7 +179,7 @@ export const SnapSheetModalBase = forwardRef(function SnapSheetModalBase({
|
|
|
179
179
|
onClosed?.();
|
|
180
180
|
} else onOpened?.();
|
|
181
181
|
hasMountOpened.current = true;
|
|
182
|
-
}, [
|
|
182
|
+
}, [futureState, currentState]);
|
|
183
183
|
|
|
184
184
|
useBackButton(() => {
|
|
185
185
|
snapModal.current(0);
|
|
@@ -258,7 +258,7 @@ export const SnapSheetModalBase = forwardRef(function SnapSheetModalBase({
|
|
|
258
258
|
const realChecker = restProps?.__checkIfElementIsFocused;
|
|
259
259
|
return !!r?.[CheckFocusedNode] &&
|
|
260
260
|
!willClose &&
|
|
261
|
-
refs.some(v => realChecker ? realChecker?.(v) : v?.isFocused?.());
|
|
261
|
+
refs.some(v => realChecker ? realChecker?.(v, refs) : v?.isFocused?.());
|
|
262
262
|
},
|
|
263
263
|
keyboardDodgingBehaviour: 'optimum'
|
|
264
264
|
} : {}
|