Skip to content

Commit 1207932

Browse files
committed
chore: refactoring for better doc
1 parent 8b901d3 commit 1207932

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

src/index.ts

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ export const scrollViewProperty = new Property<PersistentBottomSheet, string>({
3636
name: 'scrollViewId',
3737
defaultValue: undefined,
3838
valueChanged: (target, oldValue, newValue) => {
39-
target._onScrollViewIdChanged(oldValue, newValue);
39+
(target as any)._onScrollViewIdChanged(oldValue, newValue);
4040
},
4141
});
4242
export const bottomSheetProperty = new Property<PersistentBottomSheet, View>({
4343
name: 'bottomSheet',
4444
defaultValue: undefined,
4545
valueChanged: (target, oldValue, newValue) => {
46-
target._onBottomSheetChanged(oldValue, newValue);
46+
(target as any)._onBottomSheetChanged(oldValue, newValue);
4747
},
4848
});
4949
export const gestureEnabledProperty = new Property<PersistentBottomSheet, boolean>({
@@ -75,7 +75,30 @@ export class PersistentBottomSheet extends GridLayout {
7575
// isPanning = false;
7676
backdropColor = null;
7777

78-
_steps: number[] = [70];
78+
panGestureHandler: PanGestureHandler;
79+
80+
private stepIndex = 0;
81+
82+
private _steps: number[] = [70];
83+
private isAnimating = false;
84+
private prevDeltaY = 0;
85+
private viewHeight = 0;
86+
private bottomViewHeight = 0;
87+
88+
private lastScrollY: number;
89+
private lastTouchY: number;
90+
private scrollViewTouched = false;
91+
private _translationY = -1;
92+
private gestureEnabled = true;
93+
private _scrollView: ScrollView;
94+
private _isScrollEnabled = true;
95+
private scrollViewAtTop: boolean = true;
96+
97+
constructor() {
98+
super();
99+
this.isPassThroughParentEnabled = true;
100+
this.on('layoutChanged', this.onLayoutChange, this);
101+
}
79102

80103
get steps() {
81104
const result = this._steps || (this.bottomSheet && (this.bottomSheet as any).steps);
@@ -84,22 +107,10 @@ export class PersistentBottomSheet extends GridLayout {
84107
set steps(value: number[]) {
85108
this._steps = value;
86109
}
87-
stepIndex = 0;
88-
89-
isAnimating = false;
90-
prevDeltaY = 0;
91-
viewHeight = 0;
92-
bottomViewHeight = 0;
93-
panGestureHandler: PanGestureHandler;
94-
95-
lastScrollY: number;
96-
lastTouchY: number;
97-
scrollViewTouched = false;
98110

99111
// nativeGestureHandler: PanGestureHandler;
100-
gestureEnabled = true;
101112
translationFunction?: (height: number, delta: number, progress: number) => { bottomSheet?: AnimationDefinition; backDrop?: AnimationDefinition };
102-
initGestures() {
113+
protected initGestures() {
103114
const manager = Manager.getInstance();
104115
const gestureHandler = manager.createGestureHandler(HandlerType.PAN, PAN_GESTURE_TAG, {
105116
shouldStartGesture: this.shouldStartGesture.bind(this),
@@ -116,7 +127,7 @@ export class PersistentBottomSheet extends GridLayout {
116127
gestureHandler.attachToView(this);
117128
this.panGestureHandler = gestureHandler as any;
118129
}
119-
shouldStartGesture(data) {
130+
protected shouldStartGesture(data) {
120131
const safeAreatop = Utils.layout.toDeviceIndependentPixels(this.getSafeAreaInsets().top);
121132
const y = data.y - safeAreatop;
122133
// console.log('shouldStartGesture ', safeAreatop, data, y, this.viewHeight - (this.translationMaxOffset - this.translationY), this.translationY, this.translationMaxOffset, this.viewHeight);
@@ -147,12 +158,6 @@ export class PersistentBottomSheet extends GridLayout {
147158
// // this.nativeGestureHandler.attachToView(newValue);
148159
// }
149160
// }
150-
constructor() {
151-
super();
152-
this.isPassThroughParentEnabled = true;
153-
this.on('layoutChanged', this.onLayoutChange, this);
154-
}
155-
_translationY = -1;
156161
get translationY() {
157162
return this._translationY;
158163
}
@@ -216,7 +221,7 @@ export class PersistentBottomSheet extends GridLayout {
216221
this.addBackdropView(index);
217222
}
218223
}
219-
addBackdropView(index: number) {
224+
protected addBackdropView(index: number) {
220225
// console.log('addBackdropView', index);
221226
this.backDrop = new GridLayout();
222227
this.backDrop.backgroundColor = this.backdropColor;
@@ -225,7 +230,6 @@ export class PersistentBottomSheet extends GridLayout {
225230
this.insertChild(this.backDrop, index);
226231
}
227232

228-
_scrollView: ScrollView;
229233

230234
get scrollView() {
231235
return this._scrollView;
@@ -248,7 +252,7 @@ export class PersistentBottomSheet extends GridLayout {
248252
value.on('touch', this.onTouch, this);
249253
}
250254
}
251-
public _onScrollViewIdChanged(oldValue: string, newValue: string) {
255+
private _onScrollViewIdChanged(oldValue: string, newValue: string) {
252256
if (newValue && this.bottomSheet) {
253257
if (this.bottomSheet.isLoaded) {
254258
const view: ScrollView = this.bottomSheet.getViewById(newValue);
@@ -264,7 +268,7 @@ export class PersistentBottomSheet extends GridLayout {
264268
}
265269
}
266270

267-
public _onBottomSheetChanged(oldValue: View, newValue: View) {
271+
private _onBottomSheetChanged(oldValue: View, newValue: View) {
268272
if (oldValue) {
269273
this.removeChild(oldValue);
270274
}
@@ -306,7 +310,7 @@ export class PersistentBottomSheet extends GridLayout {
306310
},
307311
};
308312
}
309-
onLayoutChange(event: EventData) {
313+
private onLayoutChange(event: EventData) {
310314
const contentView = event.object as GridLayout;
311315
const height = Math.round(Utils.layout.toDeviceIndependentPixels(contentView.getMeasuredHeight()));
312316
this.viewHeight = height;
@@ -320,7 +324,7 @@ export class PersistentBottomSheet extends GridLayout {
320324
this.applyTrData(data);
321325
}
322326
}
323-
onBottomLayoutChange(event: EventData) {
327+
private onBottomLayoutChange(event: EventData) {
324328
const contentView = event.object as GridLayout;
325329
const height = Math.round(Utils.layout.toDeviceIndependentPixels(contentView.getMeasuredHeight()));
326330
this.bottomViewHeight = height;
@@ -334,21 +338,20 @@ export class PersistentBottomSheet extends GridLayout {
334338
this.applyTrData(data);
335339
}
336340
}
337-
get scrollViewVerticalOffset() {
341+
private get scrollViewVerticalOffset() {
338342
if (global.isAndroid) {
339343
return (this.scrollView.nativeViewProtected as androidx.core.view.ScrollingView).computeVerticalScrollOffset() / Utils.layout.getDisplayDensity();
340344
} else {
341345
return (this.scrollView.nativeViewProtected as UIScrollView).contentOffset.y;
342346
}
343347
}
344-
set scrollViewOffset(value: number) {
348+
private set scrollViewVerticalOffset(value: number) {
345349
if (global.isAndroid) {
346350
(this.scrollView.nativeViewProtected as androidx.recyclerview.widget.RecyclerView).scrollTo(0, 0);
347351
} else {
348352
(this.scrollView.nativeViewProtected as UIScrollView).contentOffset = CGPointMake(this.scrollView.nativeViewProtected.contentOffset.x, 0);
349353
}
350354
}
351-
_isScrollEnabled = true;
352355
get isScrollEnabled() {
353356
return this._isScrollEnabled;
354357
}
@@ -360,7 +363,7 @@ export class PersistentBottomSheet extends GridLayout {
360363
}
361364
}
362365
}
363-
onTouch(event: TouchGestureEventData) {
366+
private onTouch(event: TouchGestureEventData) {
364367
let touchY;
365368
// if (this.animationTimer) {
366369
// clearTimeout(this.animationTimer);
@@ -413,8 +416,7 @@ export class PersistentBottomSheet extends GridLayout {
413416
}
414417
this.lastTouchY = touchY;
415418
}
416-
scrollViewAtTop: boolean = true;
417-
onScroll(event: ScrollEventData & { scrollOffset?: number }) {
419+
private onScroll(event: ScrollEventData & { scrollOffset?: number }) {
418420
const scrollY = event.scrollOffset || event.scrollY || 0;
419421
if (scrollY <= 0) {
420422
this.scrollViewAtTop = true;
@@ -429,7 +431,7 @@ export class PersistentBottomSheet extends GridLayout {
429431
}
430432
this.lastScrollY = scrollY;
431433
}
432-
onGestureState(args: GestureStateEventData) {
434+
private onGestureState(args: GestureStateEventData) {
433435
const { state, prevState, extraData, view } = args.data;
434436
if (prevState === GestureState.ACTIVE) {
435437
const { velocityY, translationY } = extraData;
@@ -441,7 +443,7 @@ export class PersistentBottomSheet extends GridLayout {
441443
}
442444
}
443445

444-
computeAndAnimateEndGestureAnimation(totalDelta: number) {
446+
private computeAndAnimateEndGestureAnimation(totalDelta: number) {
445447
const viewHeight = this.bottomViewHeight;
446448
const steps = this.steps;
447449
let stepIndex = 0;
@@ -461,7 +463,7 @@ export class PersistentBottomSheet extends GridLayout {
461463
stepIndexProperty.nativeValueChange(this, stepIndex);
462464
this.animateToPosition(viewHeight - destSnapPoint, Math.min(distance * 2, OPEN_DURATION));
463465
}
464-
onGestureTouch(args: GestureTouchEventData) {
466+
private onGestureTouch(args: GestureTouchEventData) {
465467
const data = args.data;
466468
if (data.state !== GestureState.ACTIVE) {
467469
return;
@@ -480,7 +482,7 @@ export class PersistentBottomSheet extends GridLayout {
480482
this.prevDeltaY = deltaY;
481483
}
482484

483-
applyTrData(trData: { [k: string]: any }) {
485+
private applyTrData(trData: { [k: string]: any }) {
484486
Object.keys(trData).forEach((k) => {
485487
const { target, ...others } = trData[k];
486488
if (target) {
@@ -492,11 +494,11 @@ export class PersistentBottomSheet extends GridLayout {
492494
});
493495
}
494496

495-
constrainY(y) {
497+
private constrainY(y) {
496498
return Math.max(Math.min(y, this.bottomViewHeight), this.bottomViewHeight - this.translationMaxOffset);
497499
}
498500

499-
async animateToPosition(position, duration = OPEN_DURATION) {
501+
private async animateToPosition(position, duration = OPEN_DURATION) {
500502
if (this._scrollView && global.isAndroid) {
501503
// on android we get unwanted scroll effect while "swipping the view"
502504
// cancel the views touches before animation to prevent that

0 commit comments

Comments
 (0)