mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
fix title align
This commit is contained in:
@@ -9,6 +9,7 @@ export class ToolbarBase extends Ion {
|
||||
|
||||
constructor(elementRef: ElementRef, config: IonicConfig) {
|
||||
super(elementRef, config);
|
||||
this.titleAlign = config.setting('navTitleAlign');
|
||||
this.itemEles = [];
|
||||
}
|
||||
|
||||
@@ -34,20 +35,17 @@ export class ToolbarBase extends Ion {
|
||||
}
|
||||
|
||||
alignTitle() {
|
||||
// don't bother if we're not trying to center align the title
|
||||
if (this.titleAlign !== 'center' || this.aligned) return;
|
||||
|
||||
// called after the navbar/title has had a moment to
|
||||
// finish rendering in their correct locations
|
||||
const toolbarEle = this.getNativeElement();
|
||||
const titleEle = this._ttEle || (this._ttEle = toolbarEle.querySelector('ion-title'));
|
||||
const titleEle = toolbarEle.querySelector('ion-title');
|
||||
|
||||
// don't bother if there's no title element
|
||||
if (!titleEle) return;
|
||||
|
||||
// get the computed style of the title element
|
||||
const titleStyle = this._ttStyle || (this._ttStyle = window.getComputedStyle(titleEle));
|
||||
|
||||
// don't bother if we're not trying to center align the title
|
||||
if (titleStyle.textAlign !== 'center') return;
|
||||
|
||||
// get all the dimensions
|
||||
const titleOffsetLeft = titleEle.offsetLeft;
|
||||
const titleOffsetRight = toolbarEle.offsetWidth - (titleOffsetLeft + titleEle.offsetWidth);
|
||||
@@ -61,13 +59,13 @@ export class ToolbarBase extends Ion {
|
||||
marginRight = (titleOffsetLeft - titleOffsetRight) - 5;
|
||||
}
|
||||
|
||||
let margin = `0 ${marginRight}px 0 ${marginLeft}px`;
|
||||
|
||||
if ((marginLeft || marginRight) && margin !== this._ttMargin) {
|
||||
if (marginLeft || marginRight) {
|
||||
// only do an update if it has to
|
||||
const innerTitleEle = this._innerTtEle || (this._innerTtEle = toolbarEle.querySelector('.toolbar-inner-title'));
|
||||
innerTitleEle.style.margin = this._ttMargin = margin;
|
||||
const innerTitleEle = toolbarEle.querySelector('.toolbar-inner-title');
|
||||
innerTitleEle.style.margin = `0 ${marginRight}px 0 ${marginLeft}px`;
|
||||
}
|
||||
|
||||
this.aligned = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ Platform.register({
|
||||
forwardIcon: 'ion-ios-arrow-forward',
|
||||
mode: 'ios',
|
||||
iconMode: 'ios',
|
||||
navTitleAlign: 'center',
|
||||
viewTransition: 'ios'
|
||||
}
|
||||
});
|
||||
@@ -59,9 +60,10 @@ Platform.register({
|
||||
iconMode: 'md',
|
||||
type: 'overlay',
|
||||
keyboardScrollAssist: true,
|
||||
viewTransition: 'md',
|
||||
mdRipple: true,
|
||||
tabBarPlacement: 'top'
|
||||
tabBarPlacement: 'top',
|
||||
navTitleAlign: 'left',
|
||||
viewTransition: 'md'
|
||||
},
|
||||
isMatch(p) {
|
||||
// "silk" is kindle fire
|
||||
@@ -90,6 +92,7 @@ Platform.register({
|
||||
tapPolyfill: true,
|
||||
keyboardScrollAssist: true,
|
||||
viewTransition: 'ios',
|
||||
navTitleAlign: 'center',
|
||||
mdRipple: false
|
||||
},
|
||||
isMatch(p) {
|
||||
|
||||
Reference in New Issue
Block a user