MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / getAncestor

Function getAncestor

packages/core/ui/core/view-base/index.ts:110–126  ·  view source on GitHub ↗
(view: T, criterion: string | { new () })

Source from the content-addressed store, hash-verified

108 * Returns an instance of a view (if found), otherwise undefined.
109 */
110export function getAncestor<T extends ViewBase = ViewBase>(view: T, criterion: string | { new () }): T {
111 let matcher: (view: ViewBase) => view is T;
112
113 if (typeof criterion === 'string') {
114 matcher = (view: ViewBase): view is T => view.typeName === criterion;
115 } else {
116 matcher = (view: ViewBase): view is T => view instanceof criterion;
117 }
118
119 for (let parent = view.parent; parent != null; parent = parent.parent) {
120 if (matcher(parent)) {
121 return parent;
122 }
123 }
124
125 return null;
126}
127
128/**
129 * Gets a child view by id.

Callers 3

goBackMethod · 0.90
isNestedWithinMethod · 0.90

Calls 1

matcherFunction · 0.85

Tested by

no test coverage detected