generated from NativeScript/plugin-seed
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathview-helper.ts
49 lines (46 loc) · 1.74 KB
/
view-helper.ts
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
import { View } from '@nativescript/core';
import { AutoLayoutController, UNSPECIFIED } from './view-helper-controllers';
export { AutoLayoutController, AutoLayoutView, ViewLayoutWrapper } from './view-helper-controllers';
export class NativeScriptViewHelper {
static generateNativeView(view: View, nativeContextOrParent: any | View, autoLayout = true): any {
if (nativeContextOrParent instanceof View) {
if (view.parent !== nativeContextOrParent) {
view.parent?._removeView(view);
nativeContextOrParent._addView(view);
}
} else {
// this also sets up the style scope (root css)
view._setupAsRootView(nativeContextOrParent);
}
if (__APPLE__) {
const iosView = view.ios;
if (view.viewController) {
return view.viewController.view;
}
if (iosView instanceof UIViewController) {
return iosView.view;
} else {
// we can disable autolayout here, so it'll just create a normal view
if (!autoLayout) {
view.callLoaded();
// iosView.translatesAutoresizingMaskIntoConstraints = true;
View.measureChild(null, view, UNSPECIFIED, UNSPECIFIED);
View.layoutChild(null, view, 0, 0, view.getMeasuredWidth(), view.getMeasuredHeight());
return view.ios;
}
const controller = AutoLayoutController.initWithOwner(new WeakRef(view)) as UIViewController;
controller.view.addSubview(view.ios);
view.viewController = controller;
return controller.view;
}
} else if (__ANDROID__) {
view.callLoaded();
return view.android;
}
}
static disposeView(view: View) {
view.parent?._removeView(view);
view.destroyNode(true);
view.viewController = null;
}
}