mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Brought back the viewModule.getAncestor function.
Extended it, so you can pass actual type instances instead of strings.
This commit is contained in:
@@ -55,6 +55,21 @@ export function eachDescendant(view: definition.View, callback: (child: View) =>
|
||||
view._eachChildView(localCallback);
|
||||
}
|
||||
|
||||
export function getAncestor(view: View, criterion: string | Function): definition.View {
|
||||
let matcher: (view: definition.View) => boolean = null;
|
||||
if (typeof criterion === "string")
|
||||
matcher = (view: definition.View) => view.typeName === criterion;
|
||||
else
|
||||
matcher = (view: definition.View) => view instanceof criterion;
|
||||
|
||||
for (let parent: definition.View = view.parent; parent != null; parent = parent.parent) {
|
||||
if (matcher(parent))
|
||||
return parent;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
var viewIdCounter = 0;
|
||||
|
||||
function onCssClassPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
|
||||
8
ui/core/view.d.ts
vendored
8
ui/core/view.d.ts
vendored
@@ -22,6 +22,14 @@ declare module "ui/core/view" {
|
||||
*/
|
||||
export function eachDescendant(view: View, callback: (child: View) => boolean);
|
||||
|
||||
/**
|
||||
* Gets an ancestor from a given type.
|
||||
* @param view - Starting view (child view).
|
||||
* @param criterion - The type of ancestor view we are looking for. Could be a string containing a class name or an actual type.
|
||||
* Returns an instance of a view (if found), otherwise undefined.
|
||||
*/
|
||||
export function getAncestor(view: View, criterion: string | Function): View;
|
||||
|
||||
/**
|
||||
* Defines interface for an optional parameter used to create a view.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user