mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-26 22:00:17 +08:00
feat(frame): add new actionBarVisibility property (#6449)
This commit is contained in:
@ -4,8 +4,9 @@ import * as builder from "tns-core-modules/ui/builder";
|
||||
import { Label } from "tns-core-modules/ui/label";
|
||||
import { Button } from "tns-core-modules/ui/button";
|
||||
import { Page } from "tns-core-modules/ui/page";
|
||||
import { View } from "tns-core-modules/ui/core/view";
|
||||
import { View, isIOS } from "tns-core-modules/ui/core/view";
|
||||
import { fromObject } from "tns-core-modules/data/observable";
|
||||
import { topmost } from "tns-core-modules/ui/frame";
|
||||
|
||||
// >> actionbar-common-require
|
||||
import * as actionBarModule from "tns-core-modules/ui/action-bar";
|
||||
@ -302,6 +303,87 @@ export function test_LoadedEventsOrder_WithoutPageContent() {
|
||||
TKUnit.arrayAssert(loadedEvents, new Array<string>("action-bar", "page"));
|
||||
}
|
||||
|
||||
export function test_ActionBarVisibility_Never_ShouldNotShowDeclaredActionBar() {
|
||||
const frame = topmost();
|
||||
frame.actionBarVisibility = "never";
|
||||
|
||||
const page = <Page>builder.parse(
|
||||
`<Page>
|
||||
<ActionBar>
|
||||
<ActionBar.titleView>
|
||||
<Button text="test" />
|
||||
</ActionBar.titleView>
|
||||
</ActionBar>
|
||||
</Page>
|
||||
`);
|
||||
|
||||
helper.navigate(() => page);
|
||||
let actionBarHidden = false;
|
||||
if (isIOS) {
|
||||
actionBarHidden = page.actionBar.nativeView.hidden;
|
||||
} else {
|
||||
actionBarHidden = !page.actionBar.nativeView.isShown();
|
||||
}
|
||||
TKUnit.assertTrue(actionBarHidden, `ActionBar hidden: expected true, actual ${actionBarHidden}`);
|
||||
|
||||
// restore default actionBarVisibility
|
||||
frame.actionBarVisibility = "auto";
|
||||
}
|
||||
|
||||
export function test_ActionBarVisibility_Always_ShouldShownHiddenActionBar() {
|
||||
const frame = topmost();
|
||||
frame.actionBarVisibility = "always";
|
||||
|
||||
const page = <Page>builder.parse(
|
||||
`<Page actionBarHidden="true">
|
||||
<ActionBar>
|
||||
<ActionBar.titleView>
|
||||
<Button text="test" />
|
||||
</ActionBar.titleView>
|
||||
</ActionBar>
|
||||
</Page>
|
||||
`);
|
||||
|
||||
helper.navigate(() => page);
|
||||
let actionBarHidden = false;
|
||||
if (isIOS) {
|
||||
actionBarHidden = page.actionBar.nativeView.hidden;
|
||||
} else {
|
||||
actionBarHidden = !page.actionBar.nativeView.isShown();
|
||||
}
|
||||
TKUnit.assertFalse(actionBarHidden, `ActionBar hidden: expected false, actual ${actionBarHidden}`);
|
||||
|
||||
// restore default actionBarVisibility
|
||||
frame.actionBarVisibility = "auto";
|
||||
}
|
||||
|
||||
export function test_ActionBarVisibility_Auto_ShouldRespectPageActionBarHiddenProperty() {
|
||||
const frame = topmost();
|
||||
frame.actionBarVisibility = "auto";
|
||||
|
||||
const page = <Page>builder.parse(
|
||||
`<Page actionBarHidden="true">
|
||||
<ActionBar>
|
||||
<ActionBar.titleView>
|
||||
<Button text="test" />
|
||||
</ActionBar.titleView>
|
||||
</ActionBar>
|
||||
</Page>
|
||||
`);
|
||||
|
||||
helper.navigate(() => page);
|
||||
let actionBarHidden = false;
|
||||
if (isIOS) {
|
||||
actionBarHidden = page.actionBar.nativeView.hidden;
|
||||
} else {
|
||||
actionBarHidden = !page.actionBar.nativeView.isShown();
|
||||
}
|
||||
TKUnit.assertTrue(actionBarHidden, `ActionBar hidden: expected true, actual ${actionBarHidden}`);
|
||||
|
||||
// restore default actionBarVisibility
|
||||
frame.actionBarVisibility = "auto";
|
||||
}
|
||||
|
||||
export function test_setId() {
|
||||
const pageFactory = function (): Page {
|
||||
const page = new Page();
|
||||
|
@ -17,7 +17,9 @@ export function test_NavBar_isVisible_when_MenuItems_areSet() {
|
||||
|
||||
var handler = function (data) {
|
||||
page.off(PageModule.Page.navigatedToEvent, handler);
|
||||
navBarIsVisible = (<any>page.frame.ios).showNavigationBar;
|
||||
navBarIsVisible = !page.actionBar.nativeView.hidden;
|
||||
console.log(navBarIsVisible);
|
||||
console.log(page.actionBar.nativeView.hidden);
|
||||
}
|
||||
|
||||
var pageFactory = function (): PageModule.Page {
|
||||
|
@ -42,6 +42,7 @@ export class FrameBase extends CustomLayoutView implements FrameDefinition {
|
||||
private _backStack = new Array<BackstackEntry>();
|
||||
private _navigationQueue = new Array<NavigationContext>();
|
||||
|
||||
public actionBarVisibility: "auto" | "never" | "always";
|
||||
public _currentEntry: BackstackEntry;
|
||||
public _executingEntry: BackstackEntry;
|
||||
public _isInFrameStack = false;
|
||||
@ -612,5 +613,7 @@ export const defaultPage = new Property<FrameBase, string>({
|
||||
frame.navigate({ moduleName: newValue });
|
||||
}
|
||||
});
|
||||
defaultPage.register(FrameBase)
|
||||
|
||||
defaultPage.register(FrameBase)
|
||||
export const actionBarVisibilityProperty = new Property<FrameBase, "auto" | "never" | "always">({ name: "actionBarVisibility", defaultValue: "auto", affectsLayout: isIOS });
|
||||
actionBarVisibilityProperty.register(FrameBase);
|
||||
|
@ -436,15 +436,24 @@ export class Frame extends FrameBase {
|
||||
}
|
||||
|
||||
public _getNavBarVisible(page: Page): boolean {
|
||||
if (page.actionBarHidden !== undefined) {
|
||||
return !page.actionBarHidden;
|
||||
switch (this.actionBarVisibility) {
|
||||
case "never":
|
||||
return false;
|
||||
|
||||
case "always":
|
||||
return true;
|
||||
|
||||
default:
|
||||
if (page.actionBarHidden !== undefined) {
|
||||
return !page.actionBarHidden;
|
||||
}
|
||||
|
||||
if (this._android && this._android.showActionBar !== undefined) {
|
||||
return this._android.showActionBar;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this._android && this._android.showActionBar !== undefined) {
|
||||
return this._android.showActionBar;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public _saveFragmentsState(): void {
|
||||
|
5
tns-core-modules/ui/frame/frame.d.ts
vendored
5
tns-core-modules/ui/frame/frame.d.ts
vendored
@ -56,6 +56,11 @@ export class Frame extends View {
|
||||
*/
|
||||
navigate(entry: NavigationEntry);
|
||||
|
||||
/**
|
||||
* Used to control the visibility the Navigation Bar in iOS and the Action Bar in Android.
|
||||
*/
|
||||
public actionBarVisibility: "auto" | "never" | "always";
|
||||
|
||||
/**
|
||||
* Gets the back stack of this instance.
|
||||
*/
|
||||
|
@ -208,7 +208,7 @@ export class Frame extends FrameBase {
|
||||
}
|
||||
|
||||
public _getNavBarVisible(page: Page): boolean {
|
||||
switch (this._ios.navBarVisibility) {
|
||||
switch (this.actionBarVisibility) {
|
||||
case "always":
|
||||
return true;
|
||||
|
||||
@ -216,17 +216,26 @@ export class Frame extends FrameBase {
|
||||
return false;
|
||||
|
||||
case "auto":
|
||||
let newValue: boolean;
|
||||
|
||||
if (page && page.actionBarHidden !== undefined) {
|
||||
newValue = !page.actionBarHidden;
|
||||
switch (this._ios.navBarVisibility) {
|
||||
case "always":
|
||||
return true;
|
||||
|
||||
case "never":
|
||||
return false;
|
||||
|
||||
case "auto":
|
||||
let newValue: boolean;
|
||||
|
||||
if (page && page.actionBarHidden !== undefined) {
|
||||
newValue = !page.actionBarHidden;
|
||||
}
|
||||
else {
|
||||
newValue = this.ios.controller.viewControllers.count > 1 || (page && page.actionBar && !page.actionBar._isEmpty());
|
||||
}
|
||||
|
||||
newValue = !!newValue; // Make sure it is boolean
|
||||
return newValue;
|
||||
}
|
||||
else {
|
||||
newValue = this.ios.controller.viewControllers.count > 1 || (page && page.actionBar && !page.actionBar._isEmpty());
|
||||
}
|
||||
|
||||
newValue = !!newValue; // Make sure it is boolean
|
||||
return newValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user