Skip to content

Commit d16935e

Browse files
committed
fix: sonme fixes
1 parent 944206f commit d16935e

File tree

1 file changed

+37
-34
lines changed

1 file changed

+37
-34
lines changed

src/index.ts

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export class PersistentBottomSheet extends GridLayout {
9494
initGestures() {
9595
const manager = Manager.getInstance();
9696
const gestureHandler = manager.createGestureHandler(HandlerType.PAN, PAN_GESTURE_TAG, {
97-
shouldStartGesture: (data) => this.shouldStartGesture(data),
97+
shouldStartGesture: this.shouldStartGesture.bind(this),
9898
// waitFor: [NATIVE_GESTURE_TAG],
9999
// disallowInterruption: true,
100100
simultaneousHandlers: [NATIVE_GESTURE_TAG],
@@ -114,26 +114,19 @@ export class PersistentBottomSheet extends GridLayout {
114114
shouldStartGesture(data) {
115115
// if (this.scrollView) {
116116
const safeAreatop = Utils.layout.toDeviceIndependentPixels(this.getSafeAreaInsets().top);
117+
// if (global.isIOS) {
118+
// // why do we get need :s
119+
// safeAreatop -= 10;
120+
// }
121+
// const y = data.y - safeAreatop;
117122
const y = data.y - safeAreatop;
118-
// console.log(
119-
// 'shouldStartGesture ',
120-
// data.positions,
121-
// data.absoluteX,
122-
// data.y,
123-
// y,
124-
// this.viewHeight - (this.translationMaxOffset - this.translationY),
125-
// this.viewHeight,
126-
// this.translationMaxOffset,
127-
// this.translationY
128-
// );
123+
// console.log('shouldStartGesture ', safeAreatop, data, y, this.viewHeight - (this.translationMaxOffset - this.translationY), this.translationY, this.translationMaxOffset, this.viewHeight);
129124
if (y < this.viewHeight - (this.translationMaxOffset - this.translationY)) {
130-
// console.log('shouldStartGesture no go on background');
131125
return false;
132126
}
133127
if (this._scrollView) {
134128
const posY = this._scrollView && this.scrollView.getLocationRelativeTo(this).y - safeAreatop;
135129
if (y >= posY && y <= posY + this.scrollView.getMeasuredHeight()) {
136-
// console.log('shouldStartGesture no go on scrollview', this.scrollView.isScrollEnabled);
137130
return false;
138131
}
139132
}
@@ -165,6 +158,7 @@ export class PersistentBottomSheet extends GridLayout {
165158
return this._translationY;
166159
}
167160
set translationY(value: number) {
161+
// console.log('set translationY', value)
168162
if (this._translationY !== -1) {
169163
this.isScrollEnabled = value === 0;
170164
}
@@ -174,7 +168,6 @@ export class PersistentBottomSheet extends GridLayout {
174168
return this.steps[this.steps.length - 1];
175169
}
176170
initNativeView() {
177-
// this.iosOverflowSafeAreaEnabled = false;
178171
super.initNativeView();
179172
if (this.scrollView) {
180173
this.scrollView.on('scroll', this.onScroll, this);
@@ -246,10 +239,11 @@ export class PersistentBottomSheet extends GridLayout {
246239
this.scrollView.off('touch', this.onTouch, this);
247240
}
248241
this._scrollView = value;
242+
249243
if (value) {
250-
if (global.isIOS) {
251-
(value.nativeViewProtected as UIScrollView).delaysContentTouches = true;
252-
}
244+
// if (global.isIOS) {
245+
// (value.nativeViewProtected as UIScrollView).delaysContentTouches = true;
246+
// }
253247
value.on('scroll', this.onScroll, this);
254248
value.on('touch', this.onTouch, this);
255249
}
@@ -277,8 +271,13 @@ export class PersistentBottomSheet extends GridLayout {
277271
if (newValue) {
278272
newValue.iosOverflowSafeAreaEnabled = false;
279273
newValue.verticalAlignment = 'bottom';
280-
const index = this.getChildrenCount();
281-
this.addChild(newValue);
274+
let index;
275+
if (!newValue.parent) {
276+
index = this.getChildrenCount();
277+
this.addChild(newValue);
278+
} else {
279+
index = this.getChildIndex(newValue);
280+
}
282281
if (!this.backDrop && this.backdropColor) {
283282
this.addBackdropView(index);
284283
}
@@ -309,7 +308,6 @@ export class PersistentBottomSheet extends GridLayout {
309308
const height = Math.round(Utils.layout.toDeviceIndependentPixels(contentView.getMeasuredHeight()));
310309
this.viewHeight = height;
311310
if (this.translationY === -1) {
312-
// console.log('onLayoutChange', this.stepIndex);
313311
const step = this.steps[this.stepIndex];
314312
const ty = this.translationMaxOffset - step;
315313
this.translationY = ty;
@@ -353,21 +351,25 @@ export class PersistentBottomSheet extends GridLayout {
353351
} else {
354352
touchY = (event.ios.touches.anyObject() as UITouch).locationInView(null).y;
355353
}
356-
// console.log('onToucht', event.action, this.lastScrollY, touchY);
354+
// console.log('onToucht', event.action, this.lastTouchY, touchY);
357355
if (event.action === 'down') {
358-
this.scrollViewTouched = true;
359-
this.lastScrollY = this.scrollViewVerticalOffset;
360-
this.scrollViewAtTop = this.lastScrollY === 0;
361-
if (this.scrollViewAtTop) {
362-
this.panGestureHandler.cancel();
363-
}
356+
// this.scrollViewTouched = true;
357+
// this.lastScrollY = this.scrollViewVerticalOffset;
358+
// this.scrollViewAtTop = this.lastScrollY === 0;
359+
// if (this.scrollViewAtTop) {
360+
// this.panGestureHandler.cancel();
361+
// }
364362
} else if (event.action === 'up' || event.action === 'cancel') {
365-
this.scrollViewTouched = false;
366-
if (this.scrollViewAtTop) {
367-
this.scrollViewAtTop = this.scrollView.verticalOffset === 0;
368-
const y = touchY - (this.lastTouchY || touchY);
369-
const totalDelta = this.translationY + y;
370-
this.computeAndAnimateEndGestureAnimation(totalDelta);
363+
if (this.scrollViewTouched) {
364+
this.scrollViewTouched = false;
365+
if (this.scrollViewAtTop) {
366+
this.scrollViewAtTop = this.scrollView.verticalOffset === 0;
367+
const y = touchY - (this.lastTouchY || touchY);
368+
if (y !== 0) {
369+
const totalDelta = this.translationY + y;
370+
this.computeAndAnimateEndGestureAnimation(totalDelta);
371+
}
372+
}
371373
}
372374
this.isScrollEnabled = true;
373375
} else if ((!this.scrollViewTouched || this.scrollViewAtTop) && event.action === 'move') {
@@ -472,6 +474,7 @@ export class PersistentBottomSheet extends GridLayout {
472474
}
473475

474476
async animateToPosition(position, duration = OPEN_DURATION) {
477+
// console.log('animateToPosition', position, new Error().stack);
475478
if (this._scrollView && global.isAndroid) {
476479
// on android we get unwanted scroll effect while "swipping the view"
477480
// cancel the views touches before animation to prevent that

0 commit comments

Comments
 (0)