mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(page): frame getter for custom Frames (#9195)
This commit is contained in:
@@ -10,6 +10,7 @@ import { getAncestor } from '../core/view-base';
|
||||
import { Builder } from '../builder';
|
||||
import { sanitizeModuleName } from '../builder/module-name-sanitizer';
|
||||
import { profile } from '../../profiling';
|
||||
import { FRAME_SYMBOL } from './frame-helpers';
|
||||
|
||||
export { NavigationType } from './frame-interfaces';
|
||||
export type { AndroidActivityCallbacks, AndroidFragmentCallbacks, AndroidFrame, BackstackEntry, NavigationContext, NavigationEntry, NavigationTransition, TransitionState, ViewEntry, iOSFrame } from './frame-interfaces';
|
||||
@@ -700,6 +701,9 @@ export class FrameBase extends CustomLayoutView {
|
||||
}
|
||||
}
|
||||
|
||||
// Mark as a Frame with an unique Symbol
|
||||
FrameBase.prototype[FRAME_SYMBOL] = true;
|
||||
|
||||
export function getFrameById(id: string): FrameBase {
|
||||
console.log('getFrameById() is deprecated. Use Frame.getFrameById() instead.');
|
||||
|
||||
|
||||
19
packages/core/ui/frame/frame-helpers.ts
Normal file
19
packages/core/ui/frame/frame-helpers.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
/**
|
||||
* Unique symbol to mark Frame instances.
|
||||
*
|
||||
* We use a symbol because in some cases importing the Frame to do
|
||||
* instanceof checks introduces circular references.
|
||||
*
|
||||
* Having the symbol in it's own file prevents any potential circular
|
||||
* references and allows checking if an object is a frame
|
||||
*/
|
||||
export const FRAME_SYMBOL = Symbol('FRAME_SYMBOL');
|
||||
|
||||
/**
|
||||
* Helper to determine if the passed object is a Frame
|
||||
*
|
||||
* @param object
|
||||
*/
|
||||
export function isFrame(object: any) {
|
||||
return object && object[FRAME_SYMBOL] === true;
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import { Style } from '../styling/style';
|
||||
import { Color } from '../../color';
|
||||
import { EventData } from '../../data/observable';
|
||||
import type { Frame } from '../frame';
|
||||
import { isFrame } from '../frame/frame-helpers';
|
||||
import { ActionBar } from '../action-bar';
|
||||
import { KeyframeAnimationInfo } from '../animation/keyframe-animation';
|
||||
import { profile } from '../../profiling';
|
||||
@@ -92,9 +93,9 @@ export class PageBase extends ContentView {
|
||||
}
|
||||
|
||||
get frame(): Frame {
|
||||
const frame = this.parent;
|
||||
const parent = this.parent;
|
||||
|
||||
return frame && frame.constructor.name === 'Frame' ? (frame as Frame) : undefined;
|
||||
return isFrame(parent) ? (parent as Frame) : undefined;
|
||||
}
|
||||
|
||||
private createNavigatedData(eventName: string, isBackNavigation: boolean): NavigatedData {
|
||||
|
||||
Reference in New Issue
Block a user