Skip to content

Commit 00ab489

Browse files
committed
fix: bug fixes after last change
1 parent bbfb3ce commit 00ab489

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/index.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -121,16 +121,10 @@ export class PersistentBottomSheet extends GridLayout {
121121
// }
122122
}
123123
shouldStartGesture(data) {
124-
// if (this.scrollView) {
125124
const safeAreatop = Utils.layout.toDeviceIndependentPixels(this.getSafeAreaInsets().top);
126-
// if (global.isIOS) {
127-
// // why do we get need :s
128-
// safeAreatop -= 10;
129-
// }
130-
// const y = data.y - safeAreatop;
131125
const y = data.y - safeAreatop;
132126
// console.log('shouldStartGesture ', safeAreatop, data, y, this.viewHeight - (this.translationMaxOffset - this.translationY), this.translationY, this.translationMaxOffset, this.viewHeight);
133-
if (y < this.viewHeight - (this.translationMaxOffset - this.translationY)) {
127+
if (y < this.viewHeight - (this.bottomViewHeight - this.translationY)) {
134128
return false;
135129
}
136130
if (this._scrollView) {
@@ -282,7 +276,7 @@ export class PersistentBottomSheet extends GridLayout {
282276
newValue.iosOverflowSafeAreaEnabled = false;
283277
newValue.verticalAlignment = 'bottom';
284278
newValue.on('layoutChanged', this.onBottomLayoutChange, this);
285-
let index;
279+
let index;
286280
if (!newValue.parent) {
287281
index = this.getChildrenCount();
288282
this.addChild(newValue);
@@ -299,8 +293,11 @@ export class PersistentBottomSheet extends GridLayout {
299293
}
300294

301295
computeTranslationData(height) {
296+
const max = this.translationMaxOffset;
297+
const diff = height - max;
302298
const value = this._translationY;
303-
const progress = 1 - value / height;
299+
const progress = 1 - (this._translationY - diff) / max;
300+
// console.log('computeTranslationData', value, max, diff, progress);
304301
if (this.translationFunction) {
305302
return this.translationFunction(height, value, progress);
306303
}
@@ -418,7 +415,7 @@ export class PersistentBottomSheet extends GridLayout {
418415
// const viewY = this.translationY - height;
419416
const y = touchY - (this.lastTouchY || touchY);
420417
const trY = this.constrainY(this.translationY + y);
421-
const height = this.translationMaxOffset;
418+
const height = this.bottomViewHeight;
422419
// console.log('constraining on touch event', touchY, this.lastTouchY, y, trY);
423420
this.translationY = trY;
424421
const trData = this.computeTranslationData(height);
@@ -456,22 +453,24 @@ export class PersistentBottomSheet extends GridLayout {
456453
}
457454

458455
computeAndAnimateEndGestureAnimation(totalDelta: number) {
459-
const viewHeight = this.translationMaxOffset;
456+
const viewHeight = this.bottomViewHeight;
460457
const steps = this.steps;
461458
let stepIndex = 0;
462459
let destSnapPoint = viewHeight - steps[stepIndex];
460+
let distance = Math.abs(destSnapPoint - totalDelta);
463461
for (let i = 0; i < steps.length; i++) {
464462
const snapPoint = viewHeight - steps[i];
465463
const distFromSnap = Math.abs(snapPoint - totalDelta);
466464
if (distFromSnap <= Math.abs(destSnapPoint - totalDelta)) {
467465
destSnapPoint = snapPoint;
468466
stepIndex = i;
467+
distance = distFromSnap;
469468
}
470469
}
471470
// stepIndexProperty.nativeValueChange
472471
// this.stepIndex = stepIndex;
473472
stepIndexProperty.nativeValueChange(this, stepIndex);
474-
this.animateToPosition(viewHeight - destSnapPoint);
473+
this.animateToPosition(viewHeight - destSnapPoint, Math.min(distance, OPEN_DURATION));
475474
}
476475
onGestureTouch(args: GestureTouchEventData) {
477476
const data = args.data;
@@ -485,8 +484,9 @@ export class PersistentBottomSheet extends GridLayout {
485484
}
486485
const y = deltaY - this.prevDeltaY;
487486
const trY = this.constrainY(this.translationY + y);
487+
console.log(this.translationY, y, trY);
488488
this.translationY = trY;
489-
const height = this.translationMaxOffset;
489+
const height = this.bottomViewHeight;
490490
const trData = this.computeTranslationData(height);
491491
this.applyTrData(trData);
492492
this.prevDeltaY = deltaY;
@@ -505,7 +505,7 @@ export class PersistentBottomSheet extends GridLayout {
505505
}
506506

507507
constrainY(y) {
508-
return Math.max(Math.min(y, this.translationMaxOffset), 0);
508+
return Math.max(Math.min(y, this.bottomViewHeight), this.bottomViewHeight - this.translationMaxOffset);
509509
}
510510

511511
async animateToPosition(position, duration = OPEN_DURATION) {

0 commit comments

Comments
 (0)