forked from NativeScript/NativeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslide-out.ios.ts
More file actions
92 lines (73 loc) · 2.88 KB
/
slide-out.ios.ts
File metadata and controls
92 lines (73 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import common = require("ui/slide-out/slide-out-common");
import view = require("ui/core/view");
import application = require("application");
import gestures = require("ui/gestures");
export class SlideOutControl extends common.SlideOutControl {
constructor() {
super();
this._ios = new UIView();
this.observe(gestures.GestureTypes.Swipe, (args) => {
var swipeArgs = <gestures.SwipeGestureEventData>args;
if (swipeArgs.direction === gestures.SwipeDirection.Left) {
this._toggleSlideContentVisibility(false);
} else if (swipeArgs.direction === gestures.SwipeDirection.Right) {
this._toggleSlideContentVisibility(true);
}
});
}
private _ios: any;
get ios(): any {
return this._ios;
}
private _toggleSlideContentVisibility(value: boolean): void {
if (this.slideContent && this.slideContent.ios) {
this.slideContent.ios.hidden = !value;
}
}
public openSlideContent(): void {
this._toggleSlideContentVisibility(true);
}
public closeSlideContent(): void {
this._toggleSlideContentVisibility(false);
}
//public _measureOverride(availableSize: geometry.Size): geometry.Size {
// if (this.slideContent) {
// this.slideContent.measure(new geometry.Size(this.slideContentWidth, availableSize.height));
// }
// if (this.mainContent) {
// return this.mainContent.measure(availableSize);
// }
// return geometry.Size.zero;
//}
public _addViewToNativeVisualTree(view: view.View): boolean {
super._addViewToNativeVisualTree(view);
if (this.ios && view.ios) {
var iOSView = <UIView>this.ios;
if (view === this.slideContent) {
view.ios.hidden = true;
view.observe(gestures.GestureTypes.Tap | gestures.GestureTypes.Swipe, (args) => {
if (args.type & gestures.GestureTypes.Tap) {
this._toggleSlideContentVisibility(false);
}
if (args.type & gestures.GestureTypes.Swipe) {
var swipeArgs = <gestures.SwipeGestureEventData>args;
if (swipeArgs.direction === gestures.SwipeDirection.Left) {
this._toggleSlideContentVisibility(false);
}
}
});
}
iOSView.addSubview(view.ios);
return true;
}
return false;
}
public _removeViewFromNativeVisualTree(child: view.View) {
super._removeViewFromNativeVisualTree(child);
// TODO: Probably remove gesture.
if (application.ios && this.ios && child.ios) {
var iOSView = <UIView>child.ios;
iOSView.removeFromSuperview();
}
}
}