mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-15 19:26:42 +08:00
Fix action-bar desired size
This commit is contained in:
@ -139,32 +139,40 @@ export class ActionBar extends common.ActionBar {
|
|||||||
navigationItem.title = this.title;
|
navigationItem.title = this.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _navigationBarHeight: number = 0;
|
||||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number) {
|
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number) {
|
||||||
if (this.titleView) {
|
|
||||||
var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
let width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
||||||
|
let widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
|
||||||
|
|
||||||
view.View.measureChild(this, this.titleView,
|
let height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
|
||||||
utils.layout.makeMeasureSpec(width, utils.layout.AT_MOST),
|
let heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
|
||||||
utils.layout.makeMeasureSpec(this.navigationBarHeight, utils.layout.AT_MOST));
|
|
||||||
|
let navBarWidth = 0;
|
||||||
|
let navBarHeight = 0;
|
||||||
|
|
||||||
|
let frame = <frameModule.Frame>this.page.frame;
|
||||||
|
if (frame) {
|
||||||
|
let navBar: UIView = frame.ios.controller.navigationBar;
|
||||||
|
let navBarSize = navBar.sizeThatFits(CGSizeMake(width, height));
|
||||||
|
navBarWidth = navBarSize.width;
|
||||||
|
this._navigationBarHeight = navBarHeight = navBarSize.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setMeasuredDimension(0, 0);
|
if (this.titleView) {
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
view.View.measureChild(this, this.titleView,
|
||||||
|
utils.layout.makeMeasureSpec(width, utils.layout.AT_MOST),
|
||||||
|
utils.layout.makeMeasureSpec(navBarHeight, utils.layout.AT_MOST));
|
||||||
|
}
|
||||||
|
|
||||||
|
// We ignore our width/height, minWidth/minHeight dimensions because it is against Apple policy to change height of NavigationBar.
|
||||||
|
this.setMeasuredDimension(navBarWidth, navBarHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
public onLayout(left: number, top: number, right: number, bottom: number) {
|
public onLayout(left: number, top: number, right: number, bottom: number) {
|
||||||
view.View.layoutChild(this, this.titleView, 0, 0, right - left, this.navigationBarHeight);
|
view.View.layoutChild(this, this.titleView, 0, 0, right - left, this._navigationBarHeight);
|
||||||
super.onLayout(left, top, right, bottom);
|
super.onLayout(left, top, right, bottom);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected get navigationBarHeight(): number {
|
|
||||||
var navController = frameModule.topmost().ios.controller;
|
|
||||||
if (!navController) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
var navigationBar = navController.navigationBar;
|
|
||||||
return (navigationBar && !navController.navigationBarHidden) ? navigationBar.frame.size.height : 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TapBarItemHandlerImpl extends NSObject {
|
class TapBarItemHandlerImpl extends NSObject {
|
||||||
|
@ -345,6 +345,10 @@ export class Frame extends view.CustomLayoutView implements definition.Frame {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _getNavBarVisible(page: pages.Page): boolean {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
|
||||||
// We don't need to put Page as visual child. Don't call super.
|
// We don't need to put Page as visual child. Don't call super.
|
||||||
public _addViewToNativeVisualTree(child: view.View): boolean {
|
public _addViewToNativeVisualTree(child: view.View): boolean {
|
||||||
return true;
|
return true;
|
||||||
|
@ -410,6 +410,10 @@ export class Frame extends frameCommon.Frame {
|
|||||||
console.log("[ " + backstackEntry.resolvedPage.id + " ]");
|
console.log("[ " + backstackEntry.resolvedPage.id + " ]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public _getNavBarVisible(page: pages.Page): boolean {
|
||||||
|
return this._android.showActionBar;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var NativeActivity = {
|
var NativeActivity = {
|
||||||
|
1
ui/frame/frame.d.ts
vendored
1
ui/frame/frame.d.ts
vendored
@ -91,6 +91,7 @@ declare module "ui/frame" {
|
|||||||
navigationBarHeight: number;
|
navigationBarHeight: number;
|
||||||
_processNavigationQueue(page: pages.Page);
|
_processNavigationQueue(page: pages.Page);
|
||||||
_updateActionBar(page?: pages.Page);
|
_updateActionBar(page?: pages.Page);
|
||||||
|
_getNavBarVisible(page: pages.Page): boolean;
|
||||||
//@endprivate
|
//@endprivate
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,6 +20,10 @@ export class Frame extends frameCommon.Frame {
|
|||||||
|
|
||||||
public _shouldSkipNativePop: boolean = false;
|
public _shouldSkipNativePop: boolean = false;
|
||||||
public _navigateToEntry: definition.BackstackEntry;
|
public _navigateToEntry: definition.BackstackEntry;
|
||||||
|
public _widthMeasureSpec: number;
|
||||||
|
public _heightMeasureSpec: number;
|
||||||
|
public _layoutWidth: number;
|
||||||
|
public _layoutheight: number;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -130,34 +134,26 @@ export class Frame extends frameCommon.Frame {
|
|||||||
this._ios.showNavigationBar = newValue;
|
this._ios.showNavigationBar = newValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public _getNavBarVisible(page: pages.Page) {
|
public _getNavBarVisible(page: pages.Page): boolean {
|
||||||
if (!page) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
var newValue = false;
|
|
||||||
|
|
||||||
switch (this._ios.navBarVisibility) {
|
switch (this._ios.navBarVisibility) {
|
||||||
case enums.NavigationBarVisibility.always:
|
case enums.NavigationBarVisibility.always:
|
||||||
newValue = true;
|
return true;
|
||||||
break;
|
|
||||||
|
|
||||||
case enums.NavigationBarVisibility.never:
|
case enums.NavigationBarVisibility.never:
|
||||||
newValue = false;
|
return false;
|
||||||
break;
|
|
||||||
|
|
||||||
case enums.NavigationBarVisibility.auto:
|
case enums.NavigationBarVisibility.auto:
|
||||||
|
let newValue: boolean;
|
||||||
if (page && types.isDefined(page.actionBarHidden)) {
|
if (page && types.isDefined(page.actionBarHidden)) {
|
||||||
newValue = !page.actionBarHidden;
|
newValue = !page.actionBarHidden;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
newValue = this.backStack.length > 0 || (page && !page.actionBar._isEmpty());
|
newValue = this.backStack.length > 0 || (page && page.actionBar && !page.actionBar._isEmpty());
|
||||||
}
|
}
|
||||||
newValue = !!newValue; // Make sure it is boolean
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return newValue;
|
newValue = !!newValue; // Make sure it is boolean
|
||||||
|
return newValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public get ios(): definition.iOSFrame {
|
public get ios(): definition.iOSFrame {
|
||||||
@ -192,10 +188,10 @@ export class Frame extends frameCommon.Frame {
|
|||||||
var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
|
var height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
|
||||||
var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
|
var heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
|
||||||
|
|
||||||
|
this._widthMeasureSpec = widthMeasureSpec;
|
||||||
|
this._heightMeasureSpec = heightMeasureSpec;
|
||||||
|
|
||||||
var result = view.View.measureChild(this, this.currentPage, widthMeasureSpec, heightMeasureSpec);
|
var result = view.View.measureChild(this, this.currentPage, widthMeasureSpec, heightMeasureSpec);
|
||||||
if (this._navigateToEntry && this.currentPage) {
|
|
||||||
view.View.measureChild(this, this._navigateToEntry.resolvedPage, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
var widthAndState = view.View.resolveSizeAndState(result.measuredWidth, width, widthMode, 0);
|
var widthAndState = view.View.resolveSizeAndState(result.measuredWidth, width, widthMode, 0);
|
||||||
var heightAndState = view.View.resolveSizeAndState(result.measuredHeight, height, heightMode, 0);
|
var heightAndState = view.View.resolveSizeAndState(result.measuredHeight, height, heightMode, 0);
|
||||||
@ -204,10 +200,9 @@ export class Frame extends frameCommon.Frame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
public onLayout(left: number, top: number, right: number, bottom: number): void {
|
||||||
|
this._layoutWidth = right - left;
|
||||||
|
this._layoutheight = bottom - top;
|
||||||
view.View.layoutChild(this, this.currentPage, 0, 0, right - left, bottom - top);
|
view.View.layoutChild(this, this.currentPage, 0, 0, right - left, bottom - top);
|
||||||
if (this._navigateToEntry && this.currentPage) {
|
|
||||||
view.View.layoutChild(this, this._navigateToEntry.resolvedPage, 0, 0, right - left, bottom - top);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public get navigationBarHeight(): number {
|
public get navigationBarHeight(): number {
|
||||||
@ -257,6 +252,8 @@ class UINavigationControllerImpl extends UINavigationController implements UINav
|
|||||||
}
|
}
|
||||||
|
|
||||||
frame._addView(newPage);
|
frame._addView(newPage);
|
||||||
|
view.View.measureChild(frame, newPage, frame._widthMeasureSpec, frame._heightMeasureSpec);
|
||||||
|
view.View.layoutChild(frame, newPage, 0, 0, frame._layoutWidth, frame._layoutheight);
|
||||||
}
|
}
|
||||||
else if (newPage.parent !== frame) {
|
else if (newPage.parent !== frame) {
|
||||||
throw new Error("Page is already shown on another frame.");
|
throw new Error("Page is already shown on another frame.");
|
||||||
|
@ -171,23 +171,28 @@ export class Page extends pageCommon.Page {
|
|||||||
|
|
||||||
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number) {
|
public onMeasure(widthMeasureSpec: number, heightMeasureSpec: number) {
|
||||||
|
|
||||||
var width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
let width = utils.layout.getMeasureSpecSize(widthMeasureSpec);
|
||||||
var widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
|
let widthMode = utils.layout.getMeasureSpecMode(widthMeasureSpec);
|
||||||
|
|
||||||
let height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
|
let height = utils.layout.getMeasureSpecSize(heightMeasureSpec);
|
||||||
let heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
|
let heightMode = utils.layout.getMeasureSpecMode(heightMeasureSpec);
|
||||||
|
|
||||||
let navigationBarHeight = this.frame ? this.frame.navigationBarHeight : 0;
|
let actionBarWidth: number = 0;
|
||||||
let heightSpec = utils.layout.makeMeasureSpec(height - navigationBarHeight, heightMode);
|
let actionBarHeight: number = 0;
|
||||||
|
if (this.frame && this.frame._getNavBarVisible(this)) {
|
||||||
|
// Measure ActionBar with the full height.
|
||||||
|
let actionBarSize = View.measureChild(this, this.actionBar, widthMeasureSpec, heightMeasureSpec);
|
||||||
|
actionBarWidth = actionBarSize.measuredWidth;
|
||||||
|
actionBarHeight = actionBarSize.measuredHeight;
|
||||||
|
}
|
||||||
|
|
||||||
// Measure ActionBar with the full height.
|
let heightSpec = utils.layout.makeMeasureSpec(height - actionBarHeight, heightMode);
|
||||||
let actionBarSize = View.measureChild(this, this.actionBar, widthMeasureSpec, heightMeasureSpec);
|
|
||||||
|
|
||||||
// Measure content with height - navigationBarHeight. Here we could use actionBarSize.measuredHeight probably.
|
// Measure content with height - navigationBarHeight. Here we could use actionBarSize.measuredHeight probably.
|
||||||
let result = View.measureChild(this, this.content, widthMeasureSpec, heightSpec);
|
let result = View.measureChild(this, this.content, widthMeasureSpec, heightSpec);
|
||||||
|
|
||||||
let measureWidth = Math.max(actionBarSize.measuredWidth, result.measuredWidth, this.minWidth);
|
let measureWidth = Math.max(actionBarWidth, result.measuredWidth, this.minWidth);
|
||||||
let measureHeight = Math.max(result.measuredHeight + actionBarSize.measuredHeight, this.minHeight);
|
let measureHeight = Math.max(result.measuredHeight + actionBarHeight, this.minHeight);
|
||||||
|
|
||||||
let widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
|
let widthAndState = View.resolveSizeAndState(measureWidth, width, widthMode, 0);
|
||||||
let heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
let heightAndState = View.resolveSizeAndState(measureHeight, height, heightMode, 0);
|
||||||
|
Reference in New Issue
Block a user