mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup
This commit is contained in:
@@ -1,152 +1,125 @@
|
||||
import {
|
||||
PageBase,
|
||||
actionBarHiddenProperty,
|
||||
statusBarStyleProperty,
|
||||
androidStatusBarBackgroundProperty,
|
||||
} from "./page-common";
|
||||
import { View } from "../core/view";
|
||||
import { Color } from "../../color";
|
||||
import { ActionBar } from "../action-bar";
|
||||
import { GridLayout } from "../layouts/grid-layout";
|
||||
import { device } from "../../platform";
|
||||
import { profile } from "../../profiling";
|
||||
import { PageBase, actionBarHiddenProperty, statusBarStyleProperty, androidStatusBarBackgroundProperty } from './page-common';
|
||||
import { View } from '../core/view';
|
||||
import { Color } from '../../color';
|
||||
import { ActionBar } from '../action-bar';
|
||||
import { GridLayout } from '../layouts/grid-layout';
|
||||
import { device } from '../../platform';
|
||||
import { profile } from '../../profiling';
|
||||
|
||||
export * from "./page-common";
|
||||
export * from './page-common';
|
||||
|
||||
const SYSTEM_UI_FLAG_LIGHT_STATUS_BAR = 0x00002000;
|
||||
const STATUS_BAR_LIGHT_BCKG = -657931;
|
||||
const STATUS_BAR_DARK_BCKG = 1711276032;
|
||||
|
||||
export class Page extends PageBase {
|
||||
nativeViewProtected: org.nativescript.widgets.GridLayout;
|
||||
nativeViewProtected: org.nativescript.widgets.GridLayout;
|
||||
|
||||
public createNativeView() {
|
||||
const layout = new org.nativescript.widgets.GridLayout(this._context);
|
||||
layout.addRow(
|
||||
new org.nativescript.widgets.ItemSpec(
|
||||
1,
|
||||
org.nativescript.widgets.GridUnitType.auto
|
||||
)
|
||||
);
|
||||
layout.addRow(
|
||||
new org.nativescript.widgets.ItemSpec(
|
||||
1,
|
||||
org.nativescript.widgets.GridUnitType.star
|
||||
)
|
||||
);
|
||||
public createNativeView() {
|
||||
const layout = new org.nativescript.widgets.GridLayout(this._context);
|
||||
layout.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.auto));
|
||||
layout.addRow(new org.nativescript.widgets.ItemSpec(1, org.nativescript.widgets.GridUnitType.star));
|
||||
|
||||
return layout;
|
||||
}
|
||||
return layout;
|
||||
}
|
||||
|
||||
public initNativeView(): void {
|
||||
super.initNativeView();
|
||||
this.nativeViewProtected.setBackgroundColor(-1); // White color.
|
||||
}
|
||||
public initNativeView(): void {
|
||||
super.initNativeView();
|
||||
this.nativeViewProtected.setBackgroundColor(-1); // White color.
|
||||
}
|
||||
|
||||
public _addViewToNativeVisualTree(child: View, atIndex?: number): boolean {
|
||||
// Set the row property for the child
|
||||
if (this.nativeViewProtected && child.nativeViewProtected) {
|
||||
if (child instanceof ActionBar) {
|
||||
GridLayout.setRow(child, 0);
|
||||
child.horizontalAlignment = "stretch";
|
||||
child.verticalAlignment = "top";
|
||||
} else {
|
||||
GridLayout.setRow(child, 1);
|
||||
}
|
||||
}
|
||||
public _addViewToNativeVisualTree(child: View, atIndex?: number): boolean {
|
||||
// Set the row property for the child
|
||||
if (this.nativeViewProtected && child.nativeViewProtected) {
|
||||
if (child instanceof ActionBar) {
|
||||
GridLayout.setRow(child, 0);
|
||||
child.horizontalAlignment = 'stretch';
|
||||
child.verticalAlignment = 'top';
|
||||
} else {
|
||||
GridLayout.setRow(child, 1);
|
||||
}
|
||||
}
|
||||
|
||||
return super._addViewToNativeVisualTree(child, atIndex);
|
||||
}
|
||||
return super._addViewToNativeVisualTree(child, atIndex);
|
||||
}
|
||||
|
||||
@profile()
|
||||
public onLoaded() {
|
||||
super.onLoaded();
|
||||
if (!this.hasActionBar && this.actionBarHidden !== true) {
|
||||
// ensure actionBar is created
|
||||
// but we only need to do that if the actionBarHidden is not hidden
|
||||
this.actionBar = new ActionBar();
|
||||
}
|
||||
if (this.hasActionBar) {
|
||||
this.updateActionBar();
|
||||
}
|
||||
}
|
||||
@profile()
|
||||
public onLoaded() {
|
||||
super.onLoaded();
|
||||
if (!this.hasActionBar && this.actionBarHidden !== true) {
|
||||
// ensure actionBar is created
|
||||
// but we only need to do that if the actionBarHidden is not hidden
|
||||
this.actionBar = new ActionBar();
|
||||
}
|
||||
if (this.hasActionBar) {
|
||||
this.updateActionBar();
|
||||
}
|
||||
}
|
||||
|
||||
private updateActionBar() {
|
||||
// the test is actually to ensure the actionBar is created
|
||||
// it will be created if not
|
||||
if (this.actionBar) {
|
||||
this.actionBar.update();
|
||||
}
|
||||
}
|
||||
private updateActionBar() {
|
||||
// the test is actually to ensure the actionBar is created
|
||||
// it will be created if not
|
||||
if (this.actionBar) {
|
||||
this.actionBar.update();
|
||||
}
|
||||
}
|
||||
|
||||
[actionBarHiddenProperty.setNative](value: boolean) {
|
||||
// in case the actionBar is not created and actionBarHidden is changed to true
|
||||
// the actionBar will be created by updateActionBar
|
||||
if (!value || this.hasActionBar) {
|
||||
this.updateActionBar();
|
||||
}
|
||||
}
|
||||
[actionBarHiddenProperty.setNative](value: boolean) {
|
||||
// in case the actionBar is not created and actionBarHidden is changed to true
|
||||
// the actionBar will be created by updateActionBar
|
||||
if (!value || this.hasActionBar) {
|
||||
this.updateActionBar();
|
||||
}
|
||||
}
|
||||
|
||||
[statusBarStyleProperty.getDefault](): {
|
||||
color: number;
|
||||
systemUiVisibility: number;
|
||||
} {
|
||||
if (device.sdkVersion >= "21") {
|
||||
const window = (<androidx.appcompat.app.AppCompatActivity>(
|
||||
this._context
|
||||
)).getWindow();
|
||||
const decorView = window.getDecorView();
|
||||
[statusBarStyleProperty.getDefault](): {
|
||||
color: number;
|
||||
systemUiVisibility: number;
|
||||
} {
|
||||
if (device.sdkVersion >= '21') {
|
||||
const window = (<androidx.appcompat.app.AppCompatActivity>this._context).getWindow();
|
||||
const decorView = window.getDecorView();
|
||||
|
||||
return {
|
||||
color: (<any>window).getStatusBarColor(),
|
||||
systemUiVisibility: decorView.getSystemUiVisibility(),
|
||||
};
|
||||
}
|
||||
return {
|
||||
color: (<any>window).getStatusBarColor(),
|
||||
systemUiVisibility: decorView.getSystemUiVisibility(),
|
||||
};
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
[statusBarStyleProperty.setNative](
|
||||
value: "dark" | "light" | { color: number; systemUiVisibility: number }
|
||||
) {
|
||||
if (device.sdkVersion >= "21") {
|
||||
const window = (<androidx.appcompat.app.AppCompatActivity>(
|
||||
this._context
|
||||
)).getWindow();
|
||||
const decorView = window.getDecorView();
|
||||
return null;
|
||||
}
|
||||
[statusBarStyleProperty.setNative](value: 'dark' | 'light' | { color: number; systemUiVisibility: number }) {
|
||||
if (device.sdkVersion >= '21') {
|
||||
const window = (<androidx.appcompat.app.AppCompatActivity>this._context).getWindow();
|
||||
const decorView = window.getDecorView();
|
||||
|
||||
if (value === "light") {
|
||||
(<any>window).setStatusBarColor(STATUS_BAR_LIGHT_BCKG);
|
||||
decorView.setSystemUiVisibility(
|
||||
SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
|
||||
);
|
||||
} else if (value === "dark") {
|
||||
(<any>window).setStatusBarColor(STATUS_BAR_DARK_BCKG);
|
||||
decorView.setSystemUiVisibility(0);
|
||||
} else {
|
||||
(<any>window).setStatusBarColor(value.color);
|
||||
decorView.setSystemUiVisibility(value.systemUiVisibility);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (value === 'light') {
|
||||
(<any>window).setStatusBarColor(STATUS_BAR_LIGHT_BCKG);
|
||||
decorView.setSystemUiVisibility(SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
} else if (value === 'dark') {
|
||||
(<any>window).setStatusBarColor(STATUS_BAR_DARK_BCKG);
|
||||
decorView.setSystemUiVisibility(0);
|
||||
} else {
|
||||
(<any>window).setStatusBarColor(value.color);
|
||||
decorView.setSystemUiVisibility(value.systemUiVisibility);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[androidStatusBarBackgroundProperty.getDefault](): number {
|
||||
if (device.sdkVersion >= "21") {
|
||||
const window = (<androidx.appcompat.app.AppCompatActivity>(
|
||||
this._context
|
||||
)).getWindow();
|
||||
[androidStatusBarBackgroundProperty.getDefault](): number {
|
||||
if (device.sdkVersion >= '21') {
|
||||
const window = (<androidx.appcompat.app.AppCompatActivity>this._context).getWindow();
|
||||
|
||||
return (<any>window).getStatusBarColor();
|
||||
}
|
||||
return (<any>window).getStatusBarColor();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
[androidStatusBarBackgroundProperty.setNative](value: number | Color) {
|
||||
if (device.sdkVersion >= "21") {
|
||||
const window = (<androidx.appcompat.app.AppCompatActivity>(
|
||||
this._context
|
||||
)).getWindow();
|
||||
const color = value instanceof Color ? value.android : value;
|
||||
(<any>window).setStatusBarColor(color);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
[androidStatusBarBackgroundProperty.setNative](value: number | Color) {
|
||||
if (device.sdkVersion >= '21') {
|
||||
const window = (<androidx.appcompat.app.AppCompatActivity>this._context).getWindow();
|
||||
const color = value instanceof Color ? value.android : value;
|
||||
(<any>window).setStatusBarColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
284
nativescript-core/ui/page/index.d.ts
vendored
284
nativescript-core/ui/page/index.d.ts
vendored
@@ -1,194 +1,168 @@
|
||||
import { CssProperty, Property } from "../core/properties";
|
||||
import { Style } from "../styling/style";
|
||||
import { EventData } from "../../data/observable";
|
||||
import { ContentView } from "../content-view";
|
||||
import { Frame } from "../frame";
|
||||
import { ActionBar } from "../action-bar";
|
||||
import { KeyframeAnimationInfo } from "../animation/keyframe-animation";
|
||||
import { Color } from "../../color";
|
||||
import { CssProperty, Property } from '../core/properties';
|
||||
import { Style } from '../styling/style';
|
||||
import { EventData } from '../../data/observable';
|
||||
import { ContentView } from '../content-view';
|
||||
import { Frame } from '../frame';
|
||||
import { ActionBar } from '../action-bar';
|
||||
import { KeyframeAnimationInfo } from '../animation/keyframe-animation';
|
||||
import { Color } from '../../color';
|
||||
|
||||
/**
|
||||
* Defines the data for the page navigation events.
|
||||
*/
|
||||
export interface NavigatedData extends EventData {
|
||||
/**
|
||||
* The navigation context (optional, may be undefined) passed to the page navigation events method.
|
||||
*/
|
||||
context: any;
|
||||
/**
|
||||
* The navigation context (optional, may be undefined) passed to the page navigation events method.
|
||||
*/
|
||||
context: any;
|
||||
|
||||
/**
|
||||
* Represents if a navigation is forward or backward.
|
||||
*/
|
||||
isBackNavigation: boolean;
|
||||
/**
|
||||
* Represents if a navigation is forward or backward.
|
||||
*/
|
||||
isBackNavigation: boolean;
|
||||
}
|
||||
|
||||
export module knownCollections {
|
||||
export const actionItems: string;
|
||||
export const actionItems: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a logical unit for navigation (inside Frame).
|
||||
*/
|
||||
export class Page extends ContentView {
|
||||
/**
|
||||
* String value used when hooking to navigatingTo event.
|
||||
*/
|
||||
public static navigatingToEvent: string;
|
||||
/**
|
||||
* String value used when hooking to navigatingTo event.
|
||||
*/
|
||||
public static navigatingToEvent: string;
|
||||
|
||||
/**
|
||||
* String value used when hooking to navigatedTo event.
|
||||
*/
|
||||
public static navigatedToEvent: string;
|
||||
/**
|
||||
* String value used when hooking to navigatedTo event.
|
||||
*/
|
||||
public static navigatedToEvent: string;
|
||||
|
||||
/**
|
||||
* String value used when hooking to navigatingFrom event.
|
||||
*/
|
||||
public static navigatingFromEvent: string;
|
||||
/**
|
||||
* String value used when hooking to navigatingFrom event.
|
||||
*/
|
||||
public static navigatingFromEvent: string;
|
||||
|
||||
/**
|
||||
* String value used when hooking to navigatedFrom event.
|
||||
*/
|
||||
public static navigatedFromEvent: string;
|
||||
/**
|
||||
* String value used when hooking to navigatedFrom event.
|
||||
*/
|
||||
public static navigatedFromEvent: string;
|
||||
|
||||
/**
|
||||
* Gets or sets whether page background spans under status bar.
|
||||
*/
|
||||
public backgroundSpanUnderStatusBar: boolean;
|
||||
/**
|
||||
* Gets or sets whether page background spans under status bar.
|
||||
*/
|
||||
public backgroundSpanUnderStatusBar: boolean;
|
||||
|
||||
/**
|
||||
* Gets or sets the style of the status bar.
|
||||
*/
|
||||
public statusBarStyle: "light" | "dark";
|
||||
/**
|
||||
* Gets or sets the style of the status bar.
|
||||
*/
|
||||
public statusBarStyle: 'light' | 'dark';
|
||||
|
||||
/**
|
||||
* Gets or sets the color of the status bar in Android.
|
||||
*/
|
||||
public androidStatusBarBackground: Color;
|
||||
/**
|
||||
* Gets or sets the color of the status bar in Android.
|
||||
*/
|
||||
public androidStatusBarBackground: Color;
|
||||
|
||||
/**
|
||||
* Used to hide the Navigation Bar in iOS and the Action Bar in Android.
|
||||
*/
|
||||
public actionBarHidden: boolean;
|
||||
/**
|
||||
* Used to hide the Navigation Bar in iOS and the Action Bar in Android.
|
||||
*/
|
||||
public actionBarHidden: boolean;
|
||||
|
||||
/**
|
||||
* Used to control if swipe back navigation in iOS is enabled. This property is iOS specific. Default value: true
|
||||
*/
|
||||
public enableSwipeBackNavigation: boolean;
|
||||
/**
|
||||
* Used to control if swipe back navigation in iOS is enabled. This property is iOS specific. Default value: true
|
||||
*/
|
||||
public enableSwipeBackNavigation: boolean;
|
||||
|
||||
/**
|
||||
* Returns a CSS keyframe animation with the specified name, if it exists.
|
||||
*/
|
||||
public getKeyframeAnimationWithName(
|
||||
animationName: string
|
||||
): KeyframeAnimationInfo;
|
||||
/**
|
||||
* Returns a CSS keyframe animation with the specified name, if it exists.
|
||||
*/
|
||||
public getKeyframeAnimationWithName(animationName: string): KeyframeAnimationInfo;
|
||||
|
||||
/**
|
||||
* A property that is used to pass a data from another page (while navigate to).
|
||||
*/
|
||||
public navigationContext: any;
|
||||
/**
|
||||
* A property that is used to pass a data from another page (while navigate to).
|
||||
*/
|
||||
public navigationContext: any;
|
||||
|
||||
/**
|
||||
* Gets the Frame object controlling this instance.
|
||||
*/
|
||||
public frame: Frame;
|
||||
/**
|
||||
* Gets the Frame object controlling this instance.
|
||||
*/
|
||||
public frame: Frame;
|
||||
|
||||
/**
|
||||
* Gets the ActionBar for this page.
|
||||
*/
|
||||
public actionBar: ActionBar;
|
||||
/**
|
||||
* Gets the ActionBar for this page.
|
||||
*/
|
||||
public actionBar: ActionBar;
|
||||
|
||||
/**
|
||||
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
|
||||
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
|
||||
* @param callback - Callback function which will be executed when event is raised.
|
||||
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
|
||||
*/
|
||||
public on(
|
||||
eventNames: string,
|
||||
callback: (data: EventData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
/**
|
||||
* A basic method signature to hook an event listener (shortcut alias to the addEventListener method).
|
||||
* @param eventNames - String corresponding to events (e.g. "propertyChange"). Optionally could be used more events separated by `,` (e.g. "propertyChange", "change").
|
||||
* @param callback - Callback function which will be executed when event is raised.
|
||||
* @param thisArg - An optional parameter which will be used as `this` context for callback execution.
|
||||
*/
|
||||
public on(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void;
|
||||
|
||||
/**
|
||||
* Raised when navigation to the page has started.
|
||||
*/
|
||||
public on(
|
||||
event: "navigatingTo",
|
||||
callback: (args: NavigatedData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
/**
|
||||
* Raised when navigation to the page has started.
|
||||
*/
|
||||
public on(event: 'navigatingTo', callback: (args: NavigatedData) => void, thisArg?: any): void;
|
||||
|
||||
/**
|
||||
* Raised when navigation to the page has finished.
|
||||
*/
|
||||
public on(
|
||||
event: "navigatedTo",
|
||||
callback: (args: NavigatedData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
/**
|
||||
* Raised when navigation to the page has finished.
|
||||
*/
|
||||
public on(event: 'navigatedTo', callback: (args: NavigatedData) => void, thisArg?: any): void;
|
||||
|
||||
/**
|
||||
* Raised when navigation from the page has started.
|
||||
*/
|
||||
public on(
|
||||
event: "navigatingFrom",
|
||||
callback: (args: NavigatedData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
/**
|
||||
* Raised when navigation from the page has started.
|
||||
*/
|
||||
public on(event: 'navigatingFrom', callback: (args: NavigatedData) => void, thisArg?: any): void;
|
||||
|
||||
/**
|
||||
* Raised when navigation from the page has finished.
|
||||
*/
|
||||
public on(
|
||||
event: "navigatedFrom",
|
||||
callback: (args: NavigatedData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
//@private
|
||||
/**
|
||||
* Raised when navigation from the page has finished.
|
||||
*/
|
||||
public on(event: 'navigatedFrom', callback: (args: NavigatedData) => void, thisArg?: any): void;
|
||||
//@private
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
hasActionBar: boolean;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_frame: Frame;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
hasActionBar: boolean;
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
_frame: Frame;
|
||||
|
||||
/**
|
||||
* A method called before navigating to the page.
|
||||
* @private
|
||||
* @param context - The data passed to the page through the NavigationEntry.context property.
|
||||
* @param isBackNavigation - True if the Page is being navigated from using the Frame.goBack() method, false otherwise.
|
||||
* @param bindingContext - An object to become the binding context of the page navigating to. Optional.
|
||||
*/
|
||||
public onNavigatingTo(
|
||||
context: any,
|
||||
isBackNavigation: boolean,
|
||||
bindingContext?: any
|
||||
): void;
|
||||
/**
|
||||
* A method called before navigating to the page.
|
||||
* @private
|
||||
* @param context - The data passed to the page through the NavigationEntry.context property.
|
||||
* @param isBackNavigation - True if the Page is being navigated from using the Frame.goBack() method, false otherwise.
|
||||
* @param bindingContext - An object to become the binding context of the page navigating to. Optional.
|
||||
*/
|
||||
public onNavigatingTo(context: any, isBackNavigation: boolean, bindingContext?: any): void;
|
||||
|
||||
/**
|
||||
* A method called after navigated to the page.
|
||||
* @private
|
||||
* @param isBackNavigation - True if the Page is being navigated from using the Frame.goBack() method, false otherwise.
|
||||
*/
|
||||
public onNavigatedTo(isBackNavigation: boolean): void;
|
||||
/**
|
||||
* A method called after navigated to the page.
|
||||
* @private
|
||||
* @param isBackNavigation - True if the Page is being navigated from using the Frame.goBack() method, false otherwise.
|
||||
*/
|
||||
public onNavigatedTo(isBackNavigation: boolean): void;
|
||||
|
||||
/**
|
||||
* A method called before navigating from the page.
|
||||
* @private
|
||||
* @param isBackNavigation - True if the Page is being navigated from using the Frame.goBack() method, false otherwise.
|
||||
*/
|
||||
public onNavigatingFrom(isBackNavigation: boolean): void;
|
||||
/**
|
||||
* A method called before navigating from the page.
|
||||
* @private
|
||||
* @param isBackNavigation - True if the Page is being navigated from using the Frame.goBack() method, false otherwise.
|
||||
*/
|
||||
public onNavigatingFrom(isBackNavigation: boolean): void;
|
||||
|
||||
/**
|
||||
* A method called after navigated from the page.
|
||||
* @private
|
||||
* @param isBackNavigation - True if the Page is being navigated from using the Frame.goBack() method, false otherwise.
|
||||
*/
|
||||
public onNavigatedFrom(isBackNavigation: boolean): void;
|
||||
//@endprivate
|
||||
/**
|
||||
* A method called after navigated from the page.
|
||||
* @private
|
||||
* @param isBackNavigation - True if the Page is being navigated from using the Frame.goBack() method, false otherwise.
|
||||
*/
|
||||
public onNavigatedFrom(isBackNavigation: boolean): void;
|
||||
//@endprivate
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,7 +184,7 @@ export const enableSwipeBackNavigationProperty: Property<Page, boolean>;
|
||||
/**
|
||||
* Property backing statusBarStyle.
|
||||
*/
|
||||
export const statusBarStyleProperty: CssProperty<Style, "light" | "dark">;
|
||||
export const statusBarStyleProperty: CssProperty<Style, 'light' | 'dark'>;
|
||||
|
||||
/**
|
||||
* Property backing androidStatusBarBackground.
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,248 +1,184 @@
|
||||
import { Page as PageDefinition, NavigatedData } from ".";
|
||||
import { ContentView } from "../content-view";
|
||||
import { View, CSSType, ShownModallyData } from "../core/view";
|
||||
import { booleanConverter } from "../core/view-base";
|
||||
import { Property, CssProperty } from "../core/properties";
|
||||
import { Style } from "../styling/style";
|
||||
import { Color } from "../../color";
|
||||
import { EventData } from "../../data/observable";
|
||||
import { isIOS } from "../../platform";
|
||||
import { Frame } from "../frame";
|
||||
import { ActionBar } from "../action-bar";
|
||||
import { KeyframeAnimationInfo } from "../animation/keyframe-animation";
|
||||
import { profile } from "../../profiling";
|
||||
import { Page as PageDefinition, NavigatedData } from '.';
|
||||
import { ContentView } from '../content-view';
|
||||
import { View, CSSType, ShownModallyData } from '../core/view';
|
||||
import { booleanConverter } from '../core/view-base';
|
||||
import { Property, CssProperty } from '../core/properties';
|
||||
import { Style } from '../styling/style';
|
||||
import { Color } from '../../color';
|
||||
import { EventData } from '../../data/observable';
|
||||
import { isIOS } from '../../platform';
|
||||
import { Frame } from '../frame';
|
||||
import { ActionBar } from '../action-bar';
|
||||
import { KeyframeAnimationInfo } from '../animation/keyframe-animation';
|
||||
import { profile } from '../../profiling';
|
||||
|
||||
@CSSType("Page")
|
||||
@CSSType('Page')
|
||||
export class PageBase extends ContentView implements PageDefinition {
|
||||
public static navigatingToEvent = "navigatingTo";
|
||||
public static navigatedToEvent = "navigatedTo";
|
||||
public static navigatingFromEvent = "navigatingFrom";
|
||||
public static navigatedFromEvent = "navigatedFrom";
|
||||
public static navigatingToEvent = 'navigatingTo';
|
||||
public static navigatedToEvent = 'navigatedTo';
|
||||
public static navigatingFromEvent = 'navigatingFrom';
|
||||
public static navigatedFromEvent = 'navigatedFrom';
|
||||
|
||||
private _navigationContext: any;
|
||||
private _actionBar: ActionBar;
|
||||
private _navigationContext: any;
|
||||
private _actionBar: ActionBar;
|
||||
|
||||
public _frame: Frame;
|
||||
public _frame: Frame;
|
||||
|
||||
public actionBarHidden: boolean;
|
||||
public enableSwipeBackNavigation: boolean;
|
||||
public backgroundSpanUnderStatusBar: boolean;
|
||||
public hasActionBar: boolean;
|
||||
public actionBarHidden: boolean;
|
||||
public enableSwipeBackNavigation: boolean;
|
||||
public backgroundSpanUnderStatusBar: boolean;
|
||||
public hasActionBar: boolean;
|
||||
|
||||
get navigationContext(): any {
|
||||
return this._navigationContext;
|
||||
}
|
||||
get navigationContext(): any {
|
||||
return this._navigationContext;
|
||||
}
|
||||
|
||||
get actionBar(): ActionBar {
|
||||
if (!this._actionBar) {
|
||||
this.hasActionBar = true;
|
||||
this._actionBar = new ActionBar();
|
||||
this._addView(this._actionBar);
|
||||
}
|
||||
get actionBar(): ActionBar {
|
||||
if (!this._actionBar) {
|
||||
this.hasActionBar = true;
|
||||
this._actionBar = new ActionBar();
|
||||
this._addView(this._actionBar);
|
||||
}
|
||||
|
||||
return this._actionBar;
|
||||
}
|
||||
set actionBar(value: ActionBar) {
|
||||
if (!value) {
|
||||
throw new Error("ActionBar cannot be null or undefined.");
|
||||
}
|
||||
return this._actionBar;
|
||||
}
|
||||
set actionBar(value: ActionBar) {
|
||||
if (!value) {
|
||||
throw new Error('ActionBar cannot be null or undefined.');
|
||||
}
|
||||
|
||||
if (this._actionBar !== value) {
|
||||
if (this._actionBar) {
|
||||
this._removeView(this._actionBar);
|
||||
}
|
||||
this.hasActionBar = true;
|
||||
this._actionBar = value;
|
||||
this._addView(this._actionBar);
|
||||
}
|
||||
}
|
||||
if (this._actionBar !== value) {
|
||||
if (this._actionBar) {
|
||||
this._removeView(this._actionBar);
|
||||
}
|
||||
this.hasActionBar = true;
|
||||
this._actionBar = value;
|
||||
this._addView(this._actionBar);
|
||||
}
|
||||
}
|
||||
|
||||
get statusBarStyle(): "light" | "dark" {
|
||||
return this.style.statusBarStyle;
|
||||
}
|
||||
set statusBarStyle(value: "light" | "dark") {
|
||||
this.style.statusBarStyle = value;
|
||||
}
|
||||
get statusBarStyle(): 'light' | 'dark' {
|
||||
return this.style.statusBarStyle;
|
||||
}
|
||||
set statusBarStyle(value: 'light' | 'dark') {
|
||||
this.style.statusBarStyle = value;
|
||||
}
|
||||
|
||||
public get androidStatusBarBackground(): Color {
|
||||
return this.style.androidStatusBarBackground;
|
||||
}
|
||||
public set androidStatusBarBackground(value: Color) {
|
||||
this.style.androidStatusBarBackground = value;
|
||||
}
|
||||
public get androidStatusBarBackground(): Color {
|
||||
return this.style.androidStatusBarBackground;
|
||||
}
|
||||
public set androidStatusBarBackground(value: Color) {
|
||||
this.style.androidStatusBarBackground = value;
|
||||
}
|
||||
|
||||
get page(): PageDefinition {
|
||||
return this;
|
||||
}
|
||||
get page(): PageDefinition {
|
||||
return this;
|
||||
}
|
||||
|
||||
public _addChildFromBuilder(name: string, value: any) {
|
||||
if (value instanceof ActionBar) {
|
||||
this.actionBar = value;
|
||||
} else {
|
||||
super._addChildFromBuilder(name, value);
|
||||
}
|
||||
}
|
||||
public _addChildFromBuilder(name: string, value: any) {
|
||||
if (value instanceof ActionBar) {
|
||||
this.actionBar = value;
|
||||
} else {
|
||||
super._addChildFromBuilder(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
public getKeyframeAnimationWithName(
|
||||
animationName: string
|
||||
): KeyframeAnimationInfo {
|
||||
return this._styleScope.getKeyframeAnimationWithName(animationName);
|
||||
}
|
||||
public getKeyframeAnimationWithName(animationName: string): KeyframeAnimationInfo {
|
||||
return this._styleScope.getKeyframeAnimationWithName(animationName);
|
||||
}
|
||||
|
||||
get frame(): Frame {
|
||||
const frame = this.parent;
|
||||
get frame(): Frame {
|
||||
const frame = this.parent;
|
||||
|
||||
return frame instanceof Frame ? frame : undefined;
|
||||
}
|
||||
return frame instanceof Frame ? frame : undefined;
|
||||
}
|
||||
|
||||
private createNavigatedData(
|
||||
eventName: string,
|
||||
isBackNavigation: boolean
|
||||
): NavigatedData {
|
||||
return {
|
||||
eventName: eventName,
|
||||
object: this,
|
||||
context: this.navigationContext,
|
||||
isBackNavigation: isBackNavigation,
|
||||
};
|
||||
}
|
||||
private createNavigatedData(eventName: string, isBackNavigation: boolean): NavigatedData {
|
||||
return {
|
||||
eventName: eventName,
|
||||
object: this,
|
||||
context: this.navigationContext,
|
||||
isBackNavigation: isBackNavigation,
|
||||
};
|
||||
}
|
||||
|
||||
@profile()
|
||||
public onNavigatingTo(
|
||||
context: any,
|
||||
isBackNavigation: boolean,
|
||||
bindingContext?: any
|
||||
) {
|
||||
this._navigationContext = context;
|
||||
@profile()
|
||||
public onNavigatingTo(context: any, isBackNavigation: boolean, bindingContext?: any) {
|
||||
this._navigationContext = context;
|
||||
|
||||
if (isBackNavigation && this._styleScope) {
|
||||
this._styleScope.ensureSelectors();
|
||||
if (!this._cssState.isSelectorsLatestVersionApplied()) {
|
||||
this._onCssStateChange();
|
||||
}
|
||||
}
|
||||
if (isBackNavigation && this._styleScope) {
|
||||
this._styleScope.ensureSelectors();
|
||||
if (!this._cssState.isSelectorsLatestVersionApplied()) {
|
||||
this._onCssStateChange();
|
||||
}
|
||||
}
|
||||
|
||||
//https://github.com/NativeScript/NativeScript/issues/731
|
||||
if (
|
||||
!isBackNavigation &&
|
||||
bindingContext !== undefined &&
|
||||
bindingContext !== null
|
||||
) {
|
||||
this.bindingContext = bindingContext;
|
||||
}
|
||||
this.notify(
|
||||
this.createNavigatedData(
|
||||
PageBase.navigatingToEvent,
|
||||
isBackNavigation
|
||||
)
|
||||
);
|
||||
}
|
||||
//https://github.com/NativeScript/NativeScript/issues/731
|
||||
if (!isBackNavigation && bindingContext !== undefined && bindingContext !== null) {
|
||||
this.bindingContext = bindingContext;
|
||||
}
|
||||
this.notify(this.createNavigatedData(PageBase.navigatingToEvent, isBackNavigation));
|
||||
}
|
||||
|
||||
@profile()
|
||||
public onNavigatedTo(isBackNavigation: boolean) {
|
||||
this.notify(
|
||||
this.createNavigatedData(
|
||||
PageBase.navigatedToEvent,
|
||||
isBackNavigation
|
||||
)
|
||||
);
|
||||
}
|
||||
@profile()
|
||||
public onNavigatedTo(isBackNavigation: boolean) {
|
||||
this.notify(this.createNavigatedData(PageBase.navigatedToEvent, isBackNavigation));
|
||||
}
|
||||
|
||||
@profile()
|
||||
public onNavigatingFrom(isBackNavigation: boolean) {
|
||||
this.notify(
|
||||
this.createNavigatedData(
|
||||
PageBase.navigatingFromEvent,
|
||||
isBackNavigation
|
||||
)
|
||||
);
|
||||
}
|
||||
@profile()
|
||||
public onNavigatingFrom(isBackNavigation: boolean) {
|
||||
this.notify(this.createNavigatedData(PageBase.navigatingFromEvent, isBackNavigation));
|
||||
}
|
||||
|
||||
@profile()
|
||||
public onNavigatedFrom(isBackNavigation: boolean) {
|
||||
this.notify(
|
||||
this.createNavigatedData(
|
||||
PageBase.navigatedFromEvent,
|
||||
isBackNavigation
|
||||
)
|
||||
);
|
||||
@profile()
|
||||
public onNavigatedFrom(isBackNavigation: boolean) {
|
||||
this.notify(this.createNavigatedData(PageBase.navigatedFromEvent, isBackNavigation));
|
||||
|
||||
this._navigationContext = undefined;
|
||||
}
|
||||
this._navigationContext = undefined;
|
||||
}
|
||||
|
||||
public eachChildView(callback: (child: View) => boolean) {
|
||||
super.eachChildView(callback);
|
||||
if (this.hasActionBar) {
|
||||
callback(this.actionBar);
|
||||
}
|
||||
}
|
||||
public eachChildView(callback: (child: View) => boolean) {
|
||||
super.eachChildView(callback);
|
||||
if (this.hasActionBar) {
|
||||
callback(this.actionBar);
|
||||
}
|
||||
}
|
||||
|
||||
get _childrenCount(): number {
|
||||
return (this.content ? 1 : 0) + (this._actionBar ? 1 : 0);
|
||||
}
|
||||
get _childrenCount(): number {
|
||||
return (this.content ? 1 : 0) + (this._actionBar ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
PageBase.prototype.recycleNativeView = "never";
|
||||
PageBase.prototype.recycleNativeView = 'never';
|
||||
|
||||
export interface PageBase {
|
||||
on(
|
||||
eventNames: string,
|
||||
callback: (data: EventData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
on(
|
||||
event: "navigatingTo",
|
||||
callback: (args: NavigatedData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
on(
|
||||
event: "navigatedTo",
|
||||
callback: (args: NavigatedData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
on(
|
||||
event: "navigatingFrom",
|
||||
callback: (args: NavigatedData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
on(
|
||||
event: "navigatedFrom",
|
||||
callback: (args: NavigatedData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
on(
|
||||
event: "showingModally",
|
||||
callback: (args: ShownModallyData) => void,
|
||||
thisArg?: any
|
||||
): void;
|
||||
on(
|
||||
event: "shownModally",
|
||||
callback: (args: ShownModallyData) => void,
|
||||
thisArg?: any
|
||||
);
|
||||
on(eventNames: string, callback: (data: EventData) => void, thisArg?: any): void;
|
||||
on(event: 'navigatingTo', callback: (args: NavigatedData) => void, thisArg?: any): void;
|
||||
on(event: 'navigatedTo', callback: (args: NavigatedData) => void, thisArg?: any): void;
|
||||
on(event: 'navigatingFrom', callback: (args: NavigatedData) => void, thisArg?: any): void;
|
||||
on(event: 'navigatedFrom', callback: (args: NavigatedData) => void, thisArg?: any): void;
|
||||
on(event: 'showingModally', callback: (args: ShownModallyData) => void, thisArg?: any): void;
|
||||
on(event: 'shownModally', callback: (args: ShownModallyData) => void, thisArg?: any);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dependency property used to hide the Navigation Bar in iOS and the Action Bar in Android.
|
||||
*/
|
||||
export const actionBarHiddenProperty = new Property<PageBase, boolean>({
|
||||
name: "actionBarHidden",
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: booleanConverter,
|
||||
name: 'actionBarHidden',
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: booleanConverter,
|
||||
});
|
||||
actionBarHiddenProperty.register(PageBase);
|
||||
|
||||
/**
|
||||
* Dependency property that specify if page background should span under status bar.
|
||||
*/
|
||||
export const backgroundSpanUnderStatusBarProperty = new Property<
|
||||
PageBase,
|
||||
boolean
|
||||
>({
|
||||
name: "backgroundSpanUnderStatusBar",
|
||||
defaultValue: false,
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: booleanConverter,
|
||||
export const backgroundSpanUnderStatusBarProperty = new Property<PageBase, boolean>({
|
||||
name: 'backgroundSpanUnderStatusBar',
|
||||
defaultValue: false,
|
||||
affectsLayout: isIOS,
|
||||
valueConverter: booleanConverter,
|
||||
});
|
||||
backgroundSpanUnderStatusBarProperty.register(PageBase);
|
||||
|
||||
@@ -250,34 +186,29 @@ backgroundSpanUnderStatusBarProperty.register(PageBase);
|
||||
* Dependency property used to control if swipe back navigation in iOS is enabled.
|
||||
* This property is iOS specific. Default value: true
|
||||
*/
|
||||
export const enableSwipeBackNavigationProperty = new Property<
|
||||
PageBase,
|
||||
boolean
|
||||
>({
|
||||
name: "enableSwipeBackNavigation",
|
||||
defaultValue: true,
|
||||
valueConverter: booleanConverter,
|
||||
export const enableSwipeBackNavigationProperty = new Property<PageBase, boolean>({
|
||||
name: 'enableSwipeBackNavigation',
|
||||
defaultValue: true,
|
||||
valueConverter: booleanConverter,
|
||||
});
|
||||
enableSwipeBackNavigationProperty.register(PageBase);
|
||||
|
||||
/**
|
||||
* Property backing statusBarStyle.
|
||||
*/
|
||||
export const statusBarStyleProperty = new CssProperty<Style, "light" | "dark">({
|
||||
name: "statusBarStyle",
|
||||
cssName: "status-bar-style",
|
||||
export const statusBarStyleProperty = new CssProperty<Style, 'light' | 'dark'>({
|
||||
name: 'statusBarStyle',
|
||||
cssName: 'status-bar-style',
|
||||
});
|
||||
statusBarStyleProperty.register(Style);
|
||||
|
||||
/**
|
||||
* Property backing androidStatusBarBackground.
|
||||
*/
|
||||
export const androidStatusBarBackgroundProperty = new CssProperty<Style, Color>(
|
||||
{
|
||||
name: "androidStatusBarBackground",
|
||||
cssName: "android-status-bar-background",
|
||||
equalityComparer: Color.equals,
|
||||
valueConverter: (v) => new Color(v),
|
||||
}
|
||||
);
|
||||
export const androidStatusBarBackgroundProperty = new CssProperty<Style, Color>({
|
||||
name: 'androidStatusBarBackground',
|
||||
cssName: 'android-status-bar-background',
|
||||
equalityComparer: Color.equals,
|
||||
valueConverter: (v) => new Color(v),
|
||||
});
|
||||
androidStatusBarBackgroundProperty.register(Style);
|
||||
|
||||
Reference in New Issue
Block a user