@draftbit/core 48.7.0 → 49.0.0

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 (62) hide show
  1. package/lib/commonjs/components/BottomSheet/BottomSheet.js +1 -1
  2. package/lib/commonjs/components/Config.js +1 -1
  3. package/lib/commonjs/components/DatePicker/DatePicker.js +1 -1
  4. package/lib/commonjs/components/Progress/CircularProgress/CircularProgress.js +1 -1
  5. package/lib/commonjs/components/Progress/IndeterminateProgress.js +1 -1
  6. package/lib/commonjs/components/Progress/LinearProgress/LinearProgress.js +1 -1
  7. package/lib/commonjs/components/SectionList/SectionList.js +1 -1
  8. package/lib/commonjs/components/StepIndicator.js +1 -1
  9. package/lib/commonjs/utilities.js +1 -1
  10. package/lib/typescript/src/Provider.d.ts +1 -1
  11. package/lib/typescript/src/components/AccordionGroup.d.ts +1 -1
  12. package/lib/typescript/src/components/ActionSheet/ActionSheet.d.ts +1 -1
  13. package/lib/typescript/src/components/BottomSheet/BottomSheet.d.ts +5 -3
  14. package/lib/typescript/src/components/BottomSheet/BottomSheet.js +56 -47
  15. package/lib/typescript/src/components/BottomSheet/BottomSheet.js.map +1 -1
  16. package/lib/typescript/src/components/DatePicker/DatePickerComponent.web.d.ts +2574 -2223
  17. package/lib/typescript/src/components/DeckSwiper/DeckSwiper.d.ts +1 -1
  18. package/lib/typescript/src/components/FormRow.d.ts +1 -1
  19. package/lib/typescript/src/components/Image.js +1 -1
  20. package/lib/typescript/src/components/Image.js.map +1 -1
  21. package/lib/typescript/src/components/Portal/Portal.d.ts +1 -1
  22. package/lib/typescript/src/components/Portal/PortalHost.d.ts +1 -1
  23. package/lib/typescript/src/components/Portal/PortalManager.d.ts +1 -1
  24. package/lib/typescript/src/components/Pressable.d.ts +2 -2
  25. package/lib/typescript/src/components/ScreenContainer.d.ts +1 -1
  26. package/lib/typescript/src/components/SectionList/SectionHeader.d.ts +1 -1
  27. package/lib/typescript/src/components/SectionList/SectionList.d.ts +2 -2
  28. package/lib/typescript/src/components/Slider.d.ts +1 -1
  29. package/lib/typescript/src/components/StepIndicator.d.ts +7 -7
  30. package/lib/typescript/src/components/SwipeableItem/SwipeableList.d.ts +1 -1
  31. package/lib/typescript/src/components/Swiper/Swiper.d.ts +1 -1
  32. package/lib/typescript/src/components/Swiper/SwiperItem.d.ts +1 -1
  33. package/lib/typescript/src/components/Switch.d.ts +2 -2
  34. package/lib/typescript/src/components/Table/Table.d.ts +1 -1
  35. package/lib/typescript/src/components/Text.d.ts +1 -1
  36. package/lib/typescript/src/components/TextField.d.ts +1 -1
  37. package/lib/typescript/src/components/Touchable.d.ts +2 -2
  38. package/lib/typescript/src/components/Typography.d.ts +3 -3
  39. package/lib/typescript/src/deprecated-components/AccordionItem.d.ts +1 -1
  40. package/lib/typescript/src/deprecated-components/Card.d.ts +1 -1
  41. package/lib/typescript/src/deprecated-components/CircularProgress.d.ts +1 -1
  42. package/lib/typescript/src/deprecated-components/Layout.d.ts +6 -6
  43. package/lib/typescript/src/deprecated-components/ProgressBar.d.ts +1 -1
  44. package/lib/typescript/src/deprecated-components/ProgressBar.js.map +1 -1
  45. package/lib/typescript/src/styles/DefaultTheme.d.ts +858 -741
  46. package/lib/typescript/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +11 -10
  48. package/src/components/BottomSheet/BottomSheet.js +56 -47
  49. package/src/components/BottomSheet/BottomSheet.js.map +1 -1
  50. package/src/components/BottomSheet/BottomSheet.tsx +82 -73
  51. package/src/components/Image.js +1 -1
  52. package/src/components/Image.js.map +1 -1
  53. package/src/components/Image.tsx +10 -1
  54. package/src/deprecated-components/ProgressBar.js.map +1 -1
  55. package/src/deprecated-components/ProgressBar.tsx +1 -1
  56. package/lib/commonjs/components/BottomSheet/BottomSheetComponent.js +0 -1
  57. package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.d.ts +0 -169
  58. package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.js +0 -438
  59. package/lib/typescript/src/components/BottomSheet/BottomSheetComponent.js.map +0 -1
  60. package/src/components/BottomSheet/BottomSheetComponent.js +0 -438
  61. package/src/components/BottomSheet/BottomSheetComponent.js.map +0 -1
  62. package/src/components/BottomSheet/BottomSheetComponent.tsx +0 -895
@@ -1,895 +0,0 @@
1
- /**
2
- * Slightly modfied version as taken from https://github.com/rgommezz/react-native-scroll-bottom-sheet
3
- * Main previously breaking change:
4
- * const node = this.props.innerRef.current?.getNode() ==> const node = this.props.innerRef.current as any
5
- */
6
-
7
- /**
8
- * Copyright (c) 2020 Raul Gomez Acuna
9
- *
10
- * This source code is licensed under the MIT license found in the
11
- * LICENSE file in the root directory of this source tree.
12
- *
13
- */
14
-
15
- import React, { Component, RefObject } from "react";
16
- import {
17
- Dimensions,
18
- FlatList,
19
- FlatListProps,
20
- Platform,
21
- ScrollView,
22
- ScrollViewProps,
23
- SectionList,
24
- SectionListProps,
25
- StyleSheet,
26
- View,
27
- ViewStyle,
28
- } from "react-native";
29
- import Animated, {
30
- abs,
31
- add,
32
- and,
33
- call,
34
- Clock,
35
- clockRunning,
36
- cond,
37
- Easing as EasingDeprecated,
38
- // @ts-ignore: this property is only present in Reanimated 2
39
- EasingNode,
40
- eq,
41
- event,
42
- Extrapolate,
43
- greaterOrEq,
44
- greaterThan,
45
- multiply,
46
- not,
47
- onChange,
48
- or,
49
- set,
50
- startClock,
51
- stopClock,
52
- sub,
53
- spring,
54
- timing,
55
- Value,
56
- } from "react-native-reanimated";
57
- import {
58
- NativeViewGestureHandler,
59
- PanGestureHandler,
60
- PanGestureHandlerProperties,
61
- State as GestureState,
62
- TapGestureHandler,
63
- } from "react-native-gesture-handler";
64
- import { Assign } from "utility-types";
65
-
66
- const {
67
- //@ts-ignore
68
- interpolate: interpolateDeprecated,
69
- // @ts-ignore: this property is only present in Reanimated 2
70
- interpolateNode,
71
- } = Animated;
72
-
73
- const interpolate: typeof interpolateDeprecated =
74
- interpolateNode ?? interpolateDeprecated;
75
- //@ts-ignore
76
- const Easing: typeof EasingDeprecated = EasingNode ?? EasingDeprecated;
77
-
78
- const FlatListComponentType = "FlatList" as const;
79
- const ScrollViewComponentType = "ScrollView" as const;
80
- const SectionListComponentType = "SectionList" as const;
81
- const TimingAnimationType = "timing" as const;
82
- const SpringAnimationType = "spring" as const;
83
-
84
- const DEFAULT_SPRING_PARAMS = {
85
- damping: 50,
86
- mass: 0.3,
87
- stiffness: 121.6,
88
- overshootClamping: true,
89
- restSpeedThreshold: 0.3,
90
- restDisplacementThreshold: 0.3,
91
- };
92
-
93
- const { height: windowHeight } = Dimensions.get("window");
94
- const IOS_NORMAL_DECELERATION_RATE = 0.998;
95
- const ANDROID_NORMAL_DECELERATION_RATE = 0.985;
96
- const DEFAULT_ANIMATION_DURATION = 250;
97
- const DEFAULT_EASING = Easing.inOut(Easing.linear);
98
- const imperativeScrollOptions = {
99
- [FlatListComponentType]: {
100
- method: "scrollToIndex",
101
- args: {
102
- index: 0,
103
- viewPosition: 0,
104
- viewOffset: 1000,
105
- animated: true,
106
- },
107
- },
108
- [ScrollViewComponentType]: {
109
- method: "scrollTo",
110
- args: {
111
- x: 0,
112
- y: 0,
113
- animated: true,
114
- },
115
- },
116
- [SectionListComponentType]: {
117
- method: "scrollToLocation",
118
- args: {
119
- itemIndex: 0,
120
- sectionIndex: 0,
121
- viewPosition: 0,
122
- viewOffset: 1000,
123
- animated: true,
124
- },
125
- },
126
- };
127
-
128
- type AnimatedScrollableComponent = FlatList | ScrollView | SectionList;
129
-
130
- type FlatListOption<T> = Assign<
131
- { componentType: typeof FlatListComponentType },
132
- FlatListProps<T>
133
- >;
134
- type ScrollViewOption = Assign<
135
- { componentType: typeof ScrollViewComponentType },
136
- ScrollViewProps
137
- >;
138
- type SectionListOption<T> = Assign<
139
- { componentType: typeof SectionListComponentType },
140
- SectionListProps<T>
141
- >;
142
-
143
- interface TimingParams {
144
- clock: Animated.Clock;
145
- from: Animated.Node<number>;
146
- to: Animated.Node<number>;
147
- position: Animated.Value<number>;
148
- finished: Animated.Value<number>;
149
- frameTime: Animated.Value<number>;
150
- velocity: Animated.Node<number>;
151
- }
152
-
153
- type CommonProps = {
154
- /**
155
- * Array of numbers that indicate the different resting positions of the bottom sheet (in dp or %), starting from the top.
156
- * If a percentage is used, that would translate to the relative amount of the total window height.
157
- * For instance, if 50% is used, that'd be windowHeight * 0.5. If you wanna take into account safe areas during
158
- * the calculation, such as status bars and notches, please use 'topInset' prop
159
- */
160
- snapPoints: Array<string | number>;
161
- /**
162
- * Index that references the initial resting position of the drawer, starting from the top
163
- */
164
- initialSnapIndex: number;
165
- /**
166
- * Render prop for the handle
167
- */
168
- renderHandle: () => React.ReactNode;
169
- /**
170
- * Callback that is executed right after the drawer settles on one of the snapping points.
171
- * The new index is provided on the callback
172
- * @param index
173
- */
174
- onSettle?: (index: number) => void;
175
- /**
176
- * Animated value that tracks the position of the drawer, being:
177
- * 0 => closed
178
- * 1 => fully opened
179
- */
180
- animatedPosition?: Animated.Value<number>;
181
- /**
182
- * This value is useful if you want to take into consideration safe area insets
183
- * when applying percentages for snapping points. We recommend using react-native-safe-area-context
184
- * library for that.
185
- * @see https://github.com/th3rdwave/react-native-safe-area-context#usage, insets.top
186
- */
187
- topInset: number;
188
- /**
189
- * Reference to FlatList, ScrollView or SectionList in order to execute its imperative methods.
190
- */
191
- innerRef: RefObject<FlatList | ScrollView | SectionList>;
192
- /*
193
- * Style to be applied to the container.
194
- */
195
- containerStyle?: Animated.AnimateStyle<ViewStyle>;
196
- /*
197
- * Factor of resistance when the gesture is released. A value of 0 offers maximum
198
- * acceleration, whereas 1 acts as the opposite. Defaults to 0.95
199
- */
200
- friction: number;
201
- /*
202
- * Allow drawer to be dragged beyond lowest snap point
203
- */
204
- enableOverScroll: boolean;
205
- };
206
-
207
- type TimingAnimationProps = {
208
- animationType: typeof TimingAnimationType;
209
- /**
210
- * Configuration for the timing reanimated function
211
- */
212
- animationConfig?: Partial<Animated.TimingConfig>;
213
- };
214
-
215
- type SpringAnimationProps = {
216
- animationType: typeof SpringAnimationType;
217
- /**
218
- * Configuration for the spring reanimated function
219
- */
220
- animationConfig?: Partial<Animated.SpringConfig>;
221
- };
222
-
223
- type Props<T> = CommonProps &
224
- (FlatListOption<T> | ScrollViewOption | SectionListOption<T>) &
225
- (TimingAnimationProps | SpringAnimationProps);
226
-
227
- export class ScrollBottomSheet<T extends any> extends Component<Props<T>> {
228
- static defaultProps = {
229
- topInset: 0,
230
- friction: 0.95,
231
- animationType: "timing",
232
- innerRef: React.createRef<AnimatedScrollableComponent>(),
233
- enableOverScroll: false,
234
- };
235
-
236
- /**
237
- * Gesture Handler references
238
- */
239
- private masterDrawer = React.createRef<TapGestureHandler>();
240
- private drawerHandleRef = React.createRef<PanGestureHandler>();
241
- private drawerContentRef = React.createRef<PanGestureHandler>();
242
- private scrollComponentRef = React.createRef<NativeViewGestureHandler>();
243
-
244
- /**
245
- * ScrollView prop
246
- */
247
- private onScrollBeginDrag: ScrollViewProps["onScrollBeginDrag"];
248
- /**
249
- * Pan gesture handler events for drawer handle and content
250
- */
251
- private onHandleGestureEvent: PanGestureHandlerProperties["onGestureEvent"];
252
- private onDrawerGestureEvent: PanGestureHandlerProperties["onGestureEvent"];
253
- /**
254
- * Main Animated Value that drives the top position of the UI drawer at any point in time
255
- */
256
- private translateY: Animated.Node<number>;
257
- /**
258
- * Animated value that keeps track of the position: 0 => closed, 1 => opened
259
- */
260
- private position: Animated.Node<number>;
261
- /**
262
- * Flag to indicate imperative snapping
263
- */
264
- private isManuallySetValue: Animated.Value<number> = new Value(0);
265
- /**
266
- * Manual snapping amount
267
- */
268
- private manualYOffset: Animated.Value<number> = new Value(0);
269
- /**
270
- * Keeps track of the current index
271
- */
272
- private nextSnapIndex: Animated.Value<number>;
273
- /**
274
- * Deceleration rate of the scroll component. This is used only on Android to
275
- * compensate the unexpected glide it gets sometimes.
276
- */
277
- private decelerationRate: Animated.Value<number>;
278
- private prevSnapIndex = -1;
279
- private dragY = new Value(0);
280
- private prevDragY = new Value(0);
281
- private tempDestSnapPoint = new Value(0);
282
- private isAndroid = new Value(Number(Platform.OS === "android"));
283
- private animationClock = new Clock();
284
- private animationPosition = new Value(0);
285
- private animationFinished = new Value(0);
286
- private animationFrameTime = new Value(0);
287
- private velocityY = new Value(0);
288
- private lastStartScrollY: Animated.Value<number> = new Value(0);
289
- private prevTranslateYOffset: Animated.Value<number>;
290
- private translationY: Animated.Value<number>;
291
- private destSnapPoint = new Value(0);
292
-
293
- private lastSnap: Animated.Value<number>;
294
- private dragWithHandle = new Value(0);
295
- private scrollUpAndPullDown = new Value(0);
296
- private didGestureFinish: Animated.Node<0 | 1>;
297
- private didScrollUpAndPullDown: Animated.Node<number>;
298
- private setTranslationY: Animated.Node<number>;
299
- private extraOffset: Animated.Node<number>;
300
- private calculateNextSnapPoint: (
301
- i?: number
302
- ) => number | Animated.Node<number>;
303
-
304
- private scrollComponent: React.ComponentType<
305
- FlatListProps<T> | ScrollViewProps | SectionListProps<T>
306
- >;
307
-
308
- convertPercentageToDp = (str: string) =>
309
- (Number(str.split("%")[0]) * (windowHeight - this.props.topInset)) / 100;
310
-
311
- constructor(props: Props<T>) {
312
- super(props);
313
- const { initialSnapIndex, animationType } = props;
314
-
315
- const animationDriver = animationType === "timing" ? 0 : 1;
316
- const animationDuration =
317
- (props.animationType === "timing" && props.animationConfig?.duration) ||
318
- DEFAULT_ANIMATION_DURATION;
319
-
320
- const ScrollComponent = this.getScrollComponent();
321
- // @ts-ignore
322
- this.scrollComponent = Animated.createAnimatedComponent(ScrollComponent);
323
-
324
- const snapPoints = this.getNormalisedSnapPoints();
325
- const openPosition = snapPoints[0];
326
- const closedPosition = this.props.enableOverScroll
327
- ? windowHeight
328
- : snapPoints[snapPoints.length - 1];
329
- const initialSnap = snapPoints[initialSnapIndex];
330
- this.nextSnapIndex = new Value(initialSnapIndex);
331
-
332
- const initialDecelerationRate = Platform.select({
333
- android:
334
- props.initialSnapIndex === 0 ? ANDROID_NORMAL_DECELERATION_RATE : 0,
335
- ios: IOS_NORMAL_DECELERATION_RATE,
336
- });
337
- this.decelerationRate = new Value(initialDecelerationRate);
338
-
339
- //@ts-ignore
340
- const handleGestureState = new Value<GestureState>(-1);
341
- //@ts-ignore
342
- const handleOldGestureState = new Value<GestureState>(-1);
343
- //@ts-ignore
344
- const drawerGestureState = new Value<GestureState>(-1);
345
- //@ts-ignore
346
- const drawerOldGestureState = new Value<GestureState>(-1);
347
-
348
- const lastSnapInRange = new Value(1);
349
- this.prevTranslateYOffset = new Value(initialSnap);
350
- this.translationY = new Value(initialSnap);
351
-
352
- this.lastSnap = new Value(initialSnap);
353
-
354
- this.onHandleGestureEvent = event([
355
- {
356
- nativeEvent: {
357
- translationY: this.dragY,
358
- oldState: handleOldGestureState,
359
- state: handleGestureState,
360
- velocityY: this.velocityY,
361
- },
362
- },
363
- ]);
364
- this.onDrawerGestureEvent = event([
365
- {
366
- nativeEvent: {
367
- translationY: this.dragY,
368
- oldState: drawerOldGestureState,
369
- state: drawerGestureState,
370
- velocityY: this.velocityY,
371
- },
372
- },
373
- ]);
374
- this.onScrollBeginDrag = event([
375
- {
376
- nativeEvent: {
377
- contentOffset: { y: this.lastStartScrollY },
378
- },
379
- },
380
- ]);
381
-
382
- const didHandleGestureBegin = eq(handleGestureState, GestureState.ACTIVE);
383
-
384
- const isAnimationInterrupted = and(
385
- or(
386
- eq(handleGestureState, GestureState.BEGAN),
387
- eq(drawerGestureState, GestureState.BEGAN),
388
- and(
389
- eq(this.isAndroid, 0),
390
- eq(animationDriver, 1),
391
- or(
392
- eq(drawerGestureState, GestureState.ACTIVE),
393
- eq(handleGestureState, GestureState.ACTIVE)
394
- )
395
- )
396
- ),
397
- clockRunning(this.animationClock)
398
- );
399
-
400
- this.didGestureFinish = or(
401
- and(
402
- eq(handleOldGestureState, GestureState.ACTIVE),
403
- eq(handleGestureState, GestureState.END)
404
- ),
405
- and(
406
- eq(drawerOldGestureState, GestureState.ACTIVE),
407
- eq(drawerGestureState, GestureState.END)
408
- )
409
- );
410
-
411
- // Function that determines if the last snap point is in the range {snapPoints}
412
- // In the case of interruptions in the middle of an animation, we'll get
413
- // lastSnap values outside the range
414
- const isLastSnapPointInRange = (i: number = 0): Animated.Node<number> =>
415
- i === snapPoints.length
416
- ? lastSnapInRange
417
- : cond(
418
- eq(this.lastSnap, snapPoints[i]),
419
- [set(lastSnapInRange, 1)],
420
- isLastSnapPointInRange(i + 1)
421
- );
422
-
423
- const scrollY = [
424
- set(lastSnapInRange, 0),
425
- isLastSnapPointInRange(),
426
- cond(
427
- or(
428
- didHandleGestureBegin,
429
- and(
430
- this.isManuallySetValue,
431
- not(eq(this.manualYOffset, snapPoints[0]))
432
- )
433
- ),
434
- [set(this.dragWithHandle, 1), 0]
435
- ),
436
- cond(
437
- // This is to account for a continuous scroll on the drawer from a snap point
438
- // Different than top, bringing the drawer to the top position, so that if we
439
- // change scroll direction without releasing the gesture, it doesn't pull down the drawer again
440
- and(
441
- eq(this.dragWithHandle, 1),
442
- greaterThan(snapPoints[0], add(this.lastSnap, this.dragY)),
443
- and(not(eq(this.lastSnap, snapPoints[0])), lastSnapInRange)
444
- ),
445
- [
446
- set(this.lastSnap, snapPoints[0]),
447
- set(this.dragWithHandle, 0),
448
- this.lastStartScrollY,
449
- ],
450
- cond(eq(this.dragWithHandle, 1), 0, this.lastStartScrollY)
451
- ),
452
- ];
453
-
454
- this.didScrollUpAndPullDown = cond(
455
- and(
456
- greaterOrEq(this.dragY, this.lastStartScrollY),
457
- greaterThan(this.lastStartScrollY, 0)
458
- ),
459
- set(this.scrollUpAndPullDown, 1)
460
- );
461
-
462
- this.setTranslationY = cond(
463
- and(
464
- not(this.dragWithHandle),
465
- not(greaterOrEq(this.dragY, this.lastStartScrollY))
466
- ),
467
- set(this.translationY, sub(this.dragY, this.lastStartScrollY)),
468
- set(this.translationY, this.dragY)
469
- );
470
-
471
- this.extraOffset = cond(
472
- eq(this.scrollUpAndPullDown, 1),
473
- this.lastStartScrollY,
474
- 0
475
- );
476
- const endOffsetY = add(
477
- this.lastSnap,
478
- this.translationY,
479
- multiply(1 - props.friction, this.velocityY)
480
- );
481
-
482
- this.calculateNextSnapPoint = (i = 0): Animated.Node<number> | number =>
483
- i === snapPoints.length
484
- ? this.tempDestSnapPoint
485
- : cond(
486
- greaterThan(
487
- abs(sub(this.tempDestSnapPoint, endOffsetY)),
488
- abs(sub(add(snapPoints[i], this.extraOffset), endOffsetY))
489
- ),
490
- [
491
- set(this.tempDestSnapPoint, add(snapPoints[i], this.extraOffset)),
492
- set(this.nextSnapIndex, i),
493
- this.calculateNextSnapPoint(i + 1),
494
- ],
495
- this.calculateNextSnapPoint(i + 1)
496
- );
497
-
498
- const runAnimation = ({
499
- clock,
500
- from,
501
- to,
502
- position,
503
- finished,
504
- velocity,
505
- frameTime,
506
- }: TimingParams) => {
507
- const state = {
508
- finished,
509
- velocity: new Value(0),
510
- position,
511
- time: new Value(0),
512
- frameTime,
513
- };
514
-
515
- const timingConfig = {
516
- duration: animationDuration,
517
- easing:
518
- (props.animationType === "timing" && props.animationConfig?.easing) ||
519
- DEFAULT_EASING,
520
- toValue: new Value(0),
521
- };
522
-
523
- const springConfig = {
524
- ...DEFAULT_SPRING_PARAMS,
525
- ...((props.animationType === "spring" && props.animationConfig) || {}),
526
- toValue: new Value(0),
527
- };
528
-
529
- return [
530
- cond(and(not(clockRunning(clock)), not(eq(finished, 1))), [
531
- // If the clock isn't running, we reset all the animation params and start the clock
532
- set(state.finished, 0),
533
- set(state.velocity, velocity),
534
- set(state.time, 0),
535
- set(state.position, from),
536
- set(state.frameTime, 0),
537
- set(timingConfig.toValue, to),
538
- set(springConfig.toValue, to),
539
- startClock(clock),
540
- ]),
541
- // We run the step here that is going to update position
542
- cond(
543
- eq(animationDriver, 0),
544
- //@ts-ignore
545
- timing(clock, state, timingConfig),
546
- spring(clock, state, springConfig)
547
- ),
548
- cond(
549
- state.finished,
550
- [
551
- call([this.nextSnapIndex], ([value]) => {
552
- if (value !== this.prevSnapIndex) {
553
- this.props.onSettle?.(value);
554
- }
555
- this.prevSnapIndex = value;
556
- }),
557
- // Resetting appropriate values
558
- set(drawerOldGestureState, GestureState.END),
559
- set(handleOldGestureState, GestureState.END),
560
- set(this.prevTranslateYOffset, state.position),
561
- cond(eq(this.scrollUpAndPullDown, 1), [
562
- set(
563
- this.prevTranslateYOffset,
564
- sub(this.prevTranslateYOffset, this.lastStartScrollY)
565
- ),
566
- set(this.lastStartScrollY, 0),
567
- set(this.scrollUpAndPullDown, 0),
568
- ]),
569
- cond(eq(this.destSnapPoint, snapPoints[0]), [
570
- set(this.dragWithHandle, 0),
571
- ]),
572
- set(this.isManuallySetValue, 0),
573
- set(this.manualYOffset, 0),
574
- stopClock(clock),
575
- this.prevTranslateYOffset,
576
- ],
577
- // We made the block return the updated position,
578
- state.position
579
- ),
580
- ];
581
- };
582
-
583
- const translateYOffset = cond(
584
- isAnimationInterrupted,
585
- [
586
- // set(prevTranslateYOffset, animationPosition) should only run if we are
587
- // interrupting an animation when the drawer is currently in a different
588
- // position than the top
589
- cond(
590
- or(
591
- this.dragWithHandle,
592
- greaterOrEq(abs(this.prevDragY), this.lastStartScrollY)
593
- ),
594
- set(this.prevTranslateYOffset, this.animationPosition)
595
- ),
596
- set(this.animationFinished, 1),
597
- set(this.translationY, 0),
598
- // Resetting appropriate values
599
- set(drawerOldGestureState, GestureState.END),
600
- set(handleOldGestureState, GestureState.END),
601
- // By forcing that frameTime exceeds duration, it has the effect of stopping the animation
602
- set(this.animationFrameTime, add(animationDuration, 1000)),
603
- set(this.velocityY, 0),
604
- stopClock(this.animationClock),
605
- this.prevTranslateYOffset,
606
- ],
607
- cond(
608
- or(
609
- this.didGestureFinish,
610
- this.isManuallySetValue,
611
- clockRunning(this.animationClock)
612
- ),
613
- [
614
- runAnimation({
615
- clock: this.animationClock,
616
- from: cond(
617
- this.isManuallySetValue,
618
- this.prevTranslateYOffset,
619
- add(this.prevTranslateYOffset, this.translationY)
620
- ),
621
- to: this.destSnapPoint,
622
- position: this.animationPosition,
623
- finished: this.animationFinished,
624
- frameTime: this.animationFrameTime,
625
- velocity: this.velocityY,
626
- }),
627
- ],
628
- [
629
- set(this.animationFrameTime, 0),
630
- set(this.animationFinished, 0),
631
- // @ts-ignore
632
- this.prevTranslateYOffset,
633
- ]
634
- )
635
- );
636
-
637
- this.translateY = interpolate(
638
- add(translateYOffset, this.dragY, multiply(scrollY, -1)),
639
- {
640
- inputRange: [openPosition, closedPosition],
641
- outputRange: [openPosition, closedPosition],
642
- extrapolate: Extrapolate.CLAMP,
643
- }
644
- );
645
-
646
- this.position = interpolate(this.translateY, {
647
- inputRange: [openPosition, snapPoints[snapPoints.length - 1]],
648
- outputRange: [1, 0],
649
- extrapolate: Extrapolate.CLAMP,
650
- });
651
- }
652
-
653
- private getNormalisedSnapPoints = () => {
654
- return this.props.snapPoints.map((p) => {
655
- if (typeof p === "string") {
656
- return this.convertPercentageToDp(p);
657
- } else if (typeof p === "number") {
658
- return p;
659
- }
660
-
661
- throw new Error(
662
- `Invalid type for value ${p}: ${typeof p}. It should be either a percentage string or a number`
663
- );
664
- });
665
- };
666
-
667
- private getScrollComponent = () => {
668
- switch (this.props.componentType) {
669
- case "FlatList":
670
- return FlatList;
671
- case "ScrollView":
672
- return ScrollView;
673
- case "SectionList":
674
- return SectionList;
675
- default:
676
- throw new Error(
677
- "Component type not supported: it should be one of `FlatList`, `ScrollView` or `SectionList`"
678
- );
679
- }
680
- };
681
-
682
- snapTo = (index: number) => {
683
- const snapPoints = this.getNormalisedSnapPoints();
684
- this.isManuallySetValue.setValue(1);
685
- this.manualYOffset.setValue(snapPoints[index]);
686
- this.nextSnapIndex.setValue(index);
687
- };
688
-
689
- render() {
690
- const { renderHandle, initialSnapIndex, containerStyle, ...rest } =
691
- this.props;
692
- const AnimatedScrollableComponent = this.scrollComponent;
693
- const normalisedSnapPoints = this.getNormalisedSnapPoints();
694
- const initialSnap = normalisedSnapPoints[initialSnapIndex];
695
-
696
- const Content = (
697
- <Animated.View
698
- style={[
699
- StyleSheet.absoluteFillObject,
700
- containerStyle,
701
- // @ts-ignore
702
- {
703
- transform: [{ translateY: this.translateY }],
704
- },
705
- ]}
706
- >
707
- <PanGestureHandler
708
- ref={this.drawerHandleRef}
709
- shouldCancelWhenOutside={false}
710
- simultaneousHandlers={this.masterDrawer}
711
- onGestureEvent={this.onHandleGestureEvent}
712
- onHandlerStateChange={this.onHandleGestureEvent}
713
- >
714
- <Animated.View>{renderHandle()}</Animated.View>
715
- </PanGestureHandler>
716
- <PanGestureHandler
717
- ref={this.drawerContentRef}
718
- simultaneousHandlers={[this.scrollComponentRef, this.masterDrawer]}
719
- shouldCancelWhenOutside={false}
720
- onGestureEvent={this.onDrawerGestureEvent}
721
- onHandlerStateChange={this.onDrawerGestureEvent}
722
- >
723
- <Animated.View style={styles.container}>
724
- <NativeViewGestureHandler
725
- ref={this.scrollComponentRef}
726
- waitFor={this.masterDrawer}
727
- simultaneousHandlers={this.drawerContentRef}
728
- >
729
- <AnimatedScrollableComponent
730
- overScrollMode="never"
731
- bounces={false}
732
- {...rest}
733
- ref={this.props.innerRef}
734
- // @ts-ignore
735
- decelerationRate={this.decelerationRate}
736
- onScrollBeginDrag={this.onScrollBeginDrag}
737
- scrollEventThrottle={1}
738
- contentContainerStyle={[
739
- rest.contentContainerStyle,
740
- { paddingBottom: this.getNormalisedSnapPoints()[0] },
741
- ]}
742
- />
743
- </NativeViewGestureHandler>
744
- </Animated.View>
745
- </PanGestureHandler>
746
- {this.props.animatedPosition && (
747
- <Animated.Code
748
- exec={onChange(
749
- this.position,
750
- set(this.props.animatedPosition, this.position)
751
- )}
752
- />
753
- )}
754
- <Animated.Code
755
- exec={onChange(
756
- this.dragY,
757
- cond(not(eq(this.dragY, 0)), set(this.prevDragY, this.dragY))
758
- )}
759
- />
760
- <Animated.Code
761
- exec={onChange(
762
- this.didGestureFinish,
763
- cond(this.didGestureFinish, [
764
- this.didScrollUpAndPullDown,
765
- this.setTranslationY,
766
- set(
767
- this.tempDestSnapPoint,
768
- add(normalisedSnapPoints[0], this.extraOffset)
769
- ),
770
- set(this.nextSnapIndex, 0),
771
- set(this.destSnapPoint, this.calculateNextSnapPoint()),
772
- cond(
773
- and(
774
- greaterThan(this.dragY, this.lastStartScrollY),
775
- this.isAndroid,
776
- not(this.dragWithHandle)
777
- ),
778
- call([], () => {
779
- // This prevents the scroll glide from happening on Android when pulling down with inertia.
780
- // It's not perfect, but does the job for now
781
- const { method, args } =
782
- imperativeScrollOptions[this.props.componentType];
783
- // @ts-ignore
784
- const node = this.props.innerRef.current as any;
785
-
786
- if (
787
- node &&
788
- node[method] &&
789
- ((this.props.componentType === "FlatList" &&
790
- (this.props?.data?.length || 0) > 0) ||
791
- (this.props.componentType === "SectionList" &&
792
- this.props.sections.length > 0) ||
793
- this.props.componentType === "ScrollView")
794
- ) {
795
- node[method](args);
796
- }
797
- })
798
- ),
799
- set(this.dragY, 0),
800
- set(this.velocityY, 0),
801
- set(
802
- this.lastSnap,
803
- sub(
804
- this.destSnapPoint,
805
- cond(
806
- eq(this.scrollUpAndPullDown, 1),
807
- this.lastStartScrollY,
808
- 0
809
- )
810
- )
811
- ),
812
- call([this.lastSnap], ([value]) => {
813
- // This is the TapGHandler trick
814
- // @ts-ignore
815
- this.masterDrawer?.current?.setNativeProps({
816
- maxDeltaY: value - this.getNormalisedSnapPoints()[0],
817
- });
818
- }),
819
- set(
820
- this.decelerationRate,
821
- cond(
822
- eq(this.isAndroid, 1),
823
- cond(
824
- eq(this.lastSnap, normalisedSnapPoints[0]),
825
- ANDROID_NORMAL_DECELERATION_RATE,
826
- 0
827
- ),
828
- IOS_NORMAL_DECELERATION_RATE
829
- )
830
- ),
831
- ])
832
- )}
833
- />
834
- <Animated.Code
835
- exec={onChange(this.isManuallySetValue, [
836
- cond(
837
- this.isManuallySetValue,
838
- [
839
- set(this.destSnapPoint, this.manualYOffset),
840
- set(this.animationFinished, 0),
841
- set(this.lastSnap, this.manualYOffset),
842
- call([this.lastSnap], ([value]) => {
843
- // This is the TapGHandler trick
844
- // @ts-ignore
845
- this.masterDrawer?.current?.setNativeProps({
846
- maxDeltaY: value - this.getNormalisedSnapPoints()[0],
847
- });
848
- }),
849
- ],
850
- [set(this.nextSnapIndex, 0)]
851
- ),
852
- ])}
853
- />
854
- </Animated.View>
855
- );
856
-
857
- // On Android, having an intermediary view with pointerEvents="box-none", breaks the
858
- // waitFor logic
859
- if (Platform.OS === "android") {
860
- return (
861
- <TapGestureHandler
862
- maxDurationMs={100000}
863
- ref={this.masterDrawer}
864
- maxDeltaY={initialSnap - this.getNormalisedSnapPoints()[0]}
865
- shouldCancelWhenOutside={false}
866
- >
867
- {Content}
868
- </TapGestureHandler>
869
- );
870
- }
871
-
872
- // On iOS, We need to wrap the content on a view with PointerEvents box-none
873
- // So that we can start scrolling automatically when reaching the top without
874
- // Stopping the gesture
875
- return (
876
- <TapGestureHandler
877
- maxDurationMs={100000}
878
- ref={this.masterDrawer}
879
- maxDeltaY={initialSnap - this.getNormalisedSnapPoints()[0]}
880
- >
881
- <View style={StyleSheet.absoluteFillObject} pointerEvents="box-none">
882
- {Content}
883
- </View>
884
- </TapGestureHandler>
885
- );
886
- }
887
- }
888
-
889
- export default ScrollBottomSheet;
890
-
891
- const styles = StyleSheet.create({
892
- container: {
893
- flex: 1,
894
- },
895
- });