Repository navigation
Expand file tree
/
Copy pathutils.ts
More file actions
94 lines (80 loc) · 2.52 KB
/
Copy pathutils.ts
File metadata and controls
94 lines (80 loc) · 2.52 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
93
94
import { LayoutBase } from 'tns-core-modules/ui/layouts/layout-base'
import { ContentView } from 'tns-core-modules/ui/content-view'
import { View } from 'tns-core-modules/ui/core/view'
import ViewNode from './ViewNode';
export function isView(view: any) {
return view instanceof View
}
export function isLayout(view: any) {
return view instanceof LayoutBase
}
export function isContentView(view: any) {
return view instanceof ContentView
}
export function insertChild(parentNode: ViewNode, childNode:ViewNode, atIndex = -1) {
if (!parentNode) {
return
}
if (parentNode.meta && typeof parentNode.meta.insertChild === 'function') {
return parentNode.meta.insertChild(parentNode, childNode, atIndex)
}
if (!parentNode.nativeView || !childNode.nativeView) {
return
}
const parentView = parentNode.nativeView
const childView = childNode.nativeView
/*if (parentView instanceof LayoutBase) {
if (childView.parent === parentView) {
let index = parentView.getChildIndex(childView)
if (index !== -1) {
parentView.removeChild(childView)
}
}
if (atIndex !== -1) {
parentView.insertChild(childView, atIndex)
} else {
parentView.addChild(childView)
}
} else if (parentView instanceof ContentView) {
if (childNode.nodeType === 8) {
parentView._addView(childView, atIndex)
} else {
parentView.content = childView
}
} else */
if (parentView && (parentView as any)._addChildFromBuilder) {
(parentView as any)._addChildFromBuilder(
childNode._nativeView.constructor.name,
childView
)
} else {
throw new Error("Parent can't contain children: " + parentNode + ", " + childNode);
}
}
export function removeChild(parentNode: ViewNode, childNode: ViewNode) {
if (!parentNode) {
return
}
if (parentNode.meta && typeof parentNode.meta.removeChild === 'function') {
return parentNode.meta.removeChild(parentNode, childNode)
}
if (!childNode.nativeView || !childNode.nativeView) {
return
}
const parentView = parentNode.nativeView
const childView = childNode.nativeView
if (parentView instanceof LayoutBase) {
parentView.removeChild(childView)
} else if (parentView instanceof ContentView) {
if (parentView.content === childView) {
parentView.content = null
}
if (childNode.nodeType === 8) {
parentView._removeView(childView)
}
} else if (isView(parentView)) {
parentView._removeView(childView)
} else {
// throw new Error("Unknown parent type: " + parent);
}
}