mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
flex order title
This commit is contained in:
@ -14,7 +14,7 @@ $toolbar-android-button-text-color: #007aff !default;
|
|||||||
height: $toolbar-android-height;
|
height: $toolbar-android-height;
|
||||||
background: $toolbar-android-background;
|
background: $toolbar-android-background;
|
||||||
|
|
||||||
.bar-inner-title {
|
.bar-title {
|
||||||
font-size: $toolbar-android-title-font-size;
|
font-size: $toolbar-android-title-font-size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,22 +35,22 @@ $toolbar-ios-button-background-color: transparent !default;
|
|||||||
content: '';
|
content: '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.bar-primary-item {
|
||||||
|
@include flex-order(2);
|
||||||
|
}
|
||||||
|
|
||||||
.bar-title {
|
.bar-title {
|
||||||
position: absolute;
|
@include flex-order(3);
|
||||||
top: 0;
|
font-size: $toolbar-ios-title-font-size;
|
||||||
right: 0;
|
text-align: center;
|
||||||
bottom: 0;
|
|
||||||
left: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar-inner-title {
|
.bar-inner-title {
|
||||||
font-size: $toolbar-ios-title-font-size;
|
|
||||||
text-align: center;
|
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar-spacer {
|
.bar-secondary-item {
|
||||||
@include flex(1);
|
@include flex-order(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
.button {
|
.button {
|
||||||
|
@ -24,7 +24,6 @@ export let ToolbarConfig = new ComponentConfig('toolbar')
|
|||||||
<div class="bar-item bar-primary-item">
|
<div class="bar-item bar-primary-item">
|
||||||
<content select="ion-nav-items[side=primary]"></content>
|
<content select="ion-nav-items[side=primary]"></content>
|
||||||
</div>
|
</div>
|
||||||
<div class="bar-spacer"></div>
|
|
||||||
<div class="bar-item bar-secondary-item">
|
<div class="bar-item bar-secondary-item">
|
||||||
<content select="ion-nav-items[side=secondary]"></content>
|
<content select="ion-nav-items[side=secondary]"></content>
|
||||||
</div>
|
</div>
|
||||||
@ -37,9 +36,10 @@ export class Toolbar {
|
|||||||
|
|
||||||
this.config = configFactory.create(this);
|
this.config = configFactory.create(this);
|
||||||
|
|
||||||
window.requestAnimationFrame(() => {
|
// TODO: make more better plz
|
||||||
|
setTimeout(() => {
|
||||||
this.alignTitle()
|
this.alignTitle()
|
||||||
})
|
}, 32)
|
||||||
}
|
}
|
||||||
|
|
||||||
alignTitle() {
|
alignTitle() {
|
||||||
@ -50,74 +50,29 @@ export class Toolbar {
|
|||||||
|
|
||||||
if (this.textAlign !== 'center') return
|
if (this.textAlign !== 'center') return
|
||||||
|
|
||||||
let barItemElements = ele.querySelectorAll('.bar-item')
|
// dont bother if the title is already too long
|
||||||
|
if (this.titleEle.offsetWidth < this.titleEle.scrollWidth) {
|
||||||
let x, barItem
|
if (!this.isTitleVisible) {
|
||||||
let barItemKeys = []
|
this.titleEle.style.opacity = this.isTitleVisible = 1
|
||||||
let barItems = {}
|
|
||||||
|
|
||||||
for (x = 0; x < (barItemElements && barItemElements.length); x++) {
|
|
||||||
barItem = barItemElements[x]
|
|
||||||
|
|
||||||
barItemKeys.push(barItem.offsetLeft)
|
|
||||||
|
|
||||||
barItems[barItem.offsetLeft] = {
|
|
||||||
left: barItem.offsetLeft,
|
|
||||||
right: barItem.offsetLeft + barItem.offsetWidth
|
|
||||||
}
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
barItemKeys.sort((a, b) => a - b)
|
let leftMargin = this.titleEle.offsetLeft
|
||||||
|
let rightMargin = ele.offsetWidth - (leftMargin + this.titleEle.offsetWidth)
|
||||||
|
let centerMargin = leftMargin - rightMargin
|
||||||
|
|
||||||
let largestGap = null
|
this.titleEle.style.margin = `0 ${centerMargin}px 0 0`
|
||||||
|
|
||||||
for (x = 1; x < barItemKeys.length; x++) {
|
|
||||||
let leftItem = barItems[barItemKeys[x - 1]]
|
|
||||||
let rightItem = barItems[barItemKeys[x]]
|
|
||||||
|
|
||||||
let gapWidth = rightItem.left - leftItem.right
|
|
||||||
|
|
||||||
if (!largestGap || gapWidth > largestGap.width) {
|
|
||||||
largestGap = {
|
|
||||||
width: gapWidth,
|
|
||||||
left: leftItem.right,
|
|
||||||
right: rightItem.left
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let marginLeft = 0
|
|
||||||
let marginRight = 0
|
|
||||||
|
|
||||||
if (largestGap) {
|
|
||||||
marginLeft = largestGap.left
|
|
||||||
marginRight = largestGap.right
|
|
||||||
}
|
|
||||||
|
|
||||||
let barWidth = ele.offsetWidth
|
|
||||||
let centeredMargin = Math.max(marginLeft, barWidth - marginRight)
|
|
||||||
let newMargin = `0 ${centeredMargin}px`
|
|
||||||
|
|
||||||
if (newMargin !== this.titleMargin) {
|
|
||||||
this.titleEle.style.margin = this.titleMargin = newMargin
|
|
||||||
if (this.titleTextAlgin !== '') {
|
|
||||||
this.titleEle.style.textAlign = this.titleTextAlgin = ''
|
|
||||||
}
|
|
||||||
|
|
||||||
// if an ellipsis is being shown, open up the right side
|
|
||||||
// as far as it can before hitting right side buttons
|
|
||||||
window.requestAnimationFrame(() => {
|
window.requestAnimationFrame(() => {
|
||||||
if (this.titleEle.offsetWidth < this.titleEle.scrollWidth) {
|
if (this.titleEle.offsetWidth < this.titleEle.scrollWidth) {
|
||||||
this.titleEle.style.margin = `0 ${barWidth - marginRight}px 0 ${centeredMargin}px`
|
this.titleEle.style.margin = ''
|
||||||
this.titleEle.style.textAlign = this.titleTextAlgin = 'left'
|
this.titleEle.style.textAlign = 'left'
|
||||||
}
|
}
|
||||||
if (!this.isTitleVisible) {
|
if (!this.isTitleVisible) {
|
||||||
this.titleEle.style.opacity = 1
|
this.titleEle.style.opacity = this.isTitleVisible = 1
|
||||||
this.isTitleVisible = true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
@ -34,14 +34,26 @@ $toolbar-background: #f7f7f8 !default;
|
|||||||
@include flex-align-items(center);
|
@include flex-align-items(center);
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar-spacer {
|
.toolbar .button {
|
||||||
@include flex(none);
|
background: transparent;
|
||||||
|
border: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-button {
|
||||||
|
@include flex-display();
|
||||||
|
@include flex-order(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.back-button-icon {
|
||||||
|
margin-right: 5px;
|
||||||
|
min-width: 12px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar-title {
|
.bar-title {
|
||||||
@include flex-display();
|
@include flex-display();
|
||||||
@include flex(1);
|
@include flex(1);
|
||||||
@include flex-align-items(center);
|
@include flex-align-items(center);
|
||||||
|
@include flex-order(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
.bar-inner-title {
|
.bar-inner-title {
|
||||||
@ -52,16 +64,10 @@ $toolbar-background: #f7f7f8 !default;
|
|||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
}
|
}
|
||||||
|
|
||||||
.back-button {
|
.bar-primary-item {
|
||||||
@include flex-display();
|
@include flex-order(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
.back-button-icon {
|
.bar-secondary-item {
|
||||||
margin-right: 5px;
|
@include flex-order(4);
|
||||||
min-width: 12px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.toolbar .button {
|
|
||||||
background: transparent;
|
|
||||||
border: none;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user