Skip to content

Commit 63fef75

Browse files
committed
fix: translationFunction parameters fix to (delta, max, progress)
1 parent b7e678b commit 63fef75

File tree

1 file changed

+24
-18
lines changed

1 file changed

+24
-18
lines changed

src/ui-persistent-bottomsheet/index.ts

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,31 @@ import {
44
GestureState,
55
GestureStateEventData,
66
GestureTouchEventData,
7-
HandlerType, install as installGestures, Manager,
7+
HandlerType,
8+
Manager,
89
PanGestureHandler,
9-
PanGestureHandlerOptions
10+
PanGestureHandlerOptions,
11+
install as installGestures
1012
} from '@nativescript-community/gesturehandler';
1113
import {
1214
AbsoluteLayout,
1315
Animation,
14-
AnimationDefinition, booleanConverter, Color,
15-
CoreTypes, CSSType, EventData,
16+
AnimationDefinition,
17+
CSSType,
18+
Color,
19+
CoreTypes,
20+
EventData,
1621
GridLayout,
1722
Property,
1823
ScrollEventData,
1924
ScrollView,
2025
TouchGestureEventData,
2126
Utils,
22-
View
27+
View,
28+
booleanConverter
2329
} from '@nativescript/core';
2430
const OPEN_DURATION = 200;
25-
const CLOSE_DURATION = 200;
2631
export let PAN_GESTURE_TAG = 12400;
27-
// export const NATIVE_GESTURE_TAG = 12421;
28-
const DEFAULT_TRIGGER_WIDTH = 20;
2932
const SWIPE_DISTANCE_MINIMUM = 10;
3033

3134
function transformAnimationValues(values) {
@@ -121,7 +124,7 @@ export class PersistentBottomSheet extends AbsoluteLayout {
121124
}
122125

123126
// nativeGestureHandler: PanGestureHandler;
124-
translationFunction?: (height: number, delta: number, progress: number) => { bottomSheet?: AnimationDefinition; backDrop?: AnimationDefinition };
127+
translationFunction?: (delta: number, max: number, progress: number) => { bottomSheet?: AnimationDefinition; backDrop?: AnimationDefinition };
125128
protected initGestures() {
126129
const manager = Manager.getInstance();
127130
const options = { gestureId: PAN_GESTURE_TAG++, ...this.panGestureOptions };
@@ -219,7 +222,11 @@ export class PersistentBottomSheet extends AbsoluteLayout {
219222
}
220223
}
221224
protected addBackdropView(index: number) {
222-
this.backDrop = new GridLayout();
225+
this.backDrop = new AbsoluteLayout();
226+
this.backDrop.width = this.backDrop.height = {
227+
unit: '%',
228+
value: 100
229+
};
223230
this.backDrop.backgroundColor = this.backdropColor;
224231
this.backDrop.opacity = 0;
225232
this.backDrop.isUserInteractionEnabled = false;
@@ -297,18 +304,17 @@ export class PersistentBottomSheet extends AbsoluteLayout {
297304
}
298305
}
299306

300-
computeTranslationData(ty) {
307+
computeTranslationData() {
301308
const max = this.translationMaxOffset;
302309
let value = this._translationY;
303-
const diff = max - ty;
304-
const progress = ty / max;
310+
const progress = -value / max;
305311
if (__IOS__ && progress === 0 && !this.iosIgnoreSafeArea) {
306312
// if this is the 0 steop ensure it gets hidden even with safeArea
307313
const safeArea = this.getSafeAreaInsets();
308314
value += Utils.layout.toDeviceIndependentPixels(safeArea.bottom);
309315
}
310316
if (this.translationFunction) {
311-
return this.translationFunction(ty, value, progress);
317+
return this.translationFunction(value, max, progress);
312318
}
313319
return {
314320
bottomSheet: {
@@ -334,7 +340,7 @@ export class PersistentBottomSheet extends AbsoluteLayout {
334340
const step = steps[this.stepIndex];
335341
const ty = step;
336342
this.translationY = -ty;
337-
const data = this.computeTranslationData(ty);
343+
const data = this.computeTranslationData();
338344
this.applyTrData(data);
339345
}
340346
}
@@ -400,7 +406,7 @@ export class PersistentBottomSheet extends AbsoluteLayout {
400406
const y = touchY - (this.lastTouchY || touchY);
401407
const trY = this.constrainY(this.translationY + y);
402408
this.translationY = trY;
403-
const trData = this.computeTranslationData(-trY);
409+
const trData = this.computeTranslationData();
404410
this.applyTrData(trData);
405411
}
406412
this.lastTouchY = touchY;
@@ -462,7 +468,7 @@ export class PersistentBottomSheet extends AbsoluteLayout {
462468
const y = deltaY - this.prevDeltaY;
463469
const trY = this.constrainY(this.translationY + y);
464470
this.translationY = trY;
465-
const trData = this.computeTranslationData(-trY);
471+
const trData = this.computeTranslationData();
466472
this.applyTrData(trData);
467473
this.prevDeltaY = deltaY;
468474
}
@@ -502,7 +508,7 @@ export class PersistentBottomSheet extends AbsoluteLayout {
502508
}
503509
// const height = this.bottomViewHeight;
504510
this.translationY = -position;
505-
const trData = this.computeTranslationData(position);
511+
const trData = this.computeTranslationData();
506512
const params = Object.keys(trData)
507513
.map((k) => {
508514
const data = trData[k];

0 commit comments

Comments
 (0)