@@ -103,10 +103,12 @@ import { isTrueProperty } from '../../util/util';
103
103
@Component ( {
104
104
selector : 'ion-content' ,
105
105
template :
106
+ '<div class="fixed-content">' +
107
+ '<ng-content select="[ion-fixed],ion-fab"></ng-content>' +
108
+ '</div>' +
106
109
'<div class="scroll-content">' +
107
110
'<ng-content></ng-content>' +
108
111
'</div>' +
109
- '<ng-content select="ion-fixed"></ng-content>' +
110
112
'<ng-content select="ion-refresher"></ng-content>' ,
111
113
host : {
112
114
'[class.statusbar-padding]' : '_sbPadding'
@@ -136,6 +138,11 @@ export class Content extends Ion {
136
138
*/
137
139
_scrollEle : HTMLElement ;
138
140
141
+ /*
142
+ * @private
143
+ */
144
+ _fixedEle : HTMLElement ;
145
+
139
146
/**
140
147
* A number representing how many pixels the top of the content has been
141
148
* adjusted, which could be by either padding or margin.
@@ -175,7 +182,8 @@ export class Content extends Ion {
175
182
* @private
176
183
*/
177
184
ngOnInit ( ) {
178
- this . _scrollEle = this . _elementRef . nativeElement . children [ 0 ] ;
185
+ this . _fixedEle = this . _elementRef . nativeElement . children [ 0 ] ;
186
+ this . _scrollEle = this . _elementRef . nativeElement . children [ 1 ] ;
179
187
180
188
this . _zone . runOutsideAngular ( ( ) => {
181
189
this . _scroll = new ScrollView ( this . _scrollEle ) ;
@@ -530,63 +538,61 @@ export class Content extends Ion {
530
538
* DOM WRITE
531
539
*/
532
540
writeDimensions ( ) {
533
- let newVal : number ;
534
- let scrollEle = this . _scrollEle ;
541
+ let scrollEle = this . _scrollEle as any ;
542
+ if ( ! scrollEle ) {
543
+ return ;
544
+ }
535
545
536
- if ( ! scrollEle ) return ;
546
+ let fixedEle = this . _fixedEle ;
547
+ if ( ! fixedEle ) {
548
+ return ;
549
+ }
537
550
538
- // only write when it has changed
539
- if ( this . _fullscreen ) {
540
- // adjust the content with padding, allowing content to scroll under headers/footers
541
- // however, on iOS you cannot control the margins of the scrollbar (last tested iOS9.2)
542
- // only add inline padding styles if the computed padding value, which would
543
- // have come from the app's css, is different than the new padding value
551
+ // Toolbar height
552
+ let contentTop = this . _headerHeight ;
553
+ let contentBottom = this . _footerHeight ;
544
554
545
- newVal = this . _headerHeight + this . _paddingTop ;
546
- if ( this . _tabsPlacement === 'top' ) {
547
- newVal += this . _tabbarHeight ;
548
- }
549
- if ( newVal !== this . contentTop ) {
550
- scrollEle . style . paddingTop = ( newVal > 0 ? newVal + 'px' : '' ) ;
551
- this . contentTop = newVal ;
552
- }
555
+ // Tabs height
556
+ if ( this . _tabsPlacement === 'top' ) {
557
+ contentTop += this . _tabbarHeight ;
553
558
554
- newVal = this . _footerHeight + this . _paddingBottom ;
555
- if ( this . _tabsPlacement === 'bottom' ) {
556
- newVal += this . _tabbarHeight ;
559
+ } else if ( this . _tabsPlacement === 'bottom' ) {
560
+ contentBottom += this . _tabbarHeight ;
557
561
558
- if ( newVal > 0 && this . _footerEle ) {
559
- this . _footerEle . style . bottom = ( newVal - this . _footerHeight - this . _paddingBottom ) + 'px' ;
560
- }
561
- }
562
- if ( newVal !== this . contentBottom ) {
563
- scrollEle . style . paddingBottom = ( newVal > 0 ? newVal + 'px' : '' ) ;
564
- this . contentBottom = newVal ;
562
+ // Update footer position
563
+ if ( contentBottom > 0 && this . _footerEle ) {
564
+ this . _footerEle . style . bottom = cssFormat ( contentBottom - this . _footerHeight ) ;
565
565
}
566
+ }
566
567
567
- } else {
568
- // adjust the content with margins
569
- newVal = this . _headerHeight ;
570
- if ( this . _tabsPlacement === 'top' ) {
571
- newVal += this . _tabbarHeight ;
572
- }
573
- if ( newVal !== this . contentTop ) {
574
- scrollEle . style . marginTop = ( newVal > 0 ? newVal + 'px' : '' ) ;
575
- this . contentTop = newVal ;
576
- }
568
+ // Handle fullscreen viewport (padding vs margin)
569
+ let topProperty = 'marginTop' ;
570
+ let bottomProperty = 'marginBottom' ;
571
+ let fixedTop : number = contentTop ;
572
+ let fixedBottom : number = contentBottom ;
573
+ if ( this . _fullscreen ) {
574
+ // adjust the content with padding, allowing content to scroll under headers/footers
575
+ // however, on iOS you cannot control the margins of the scrollbar (last tested iOS9.2)
576
+ // only add inline padding styles if the computed padding value, which would
577
+ // have come from the app's css, is different than the new padding value
578
+ contentTop += this . _paddingTop ;
579
+ contentBottom += this . _paddingBottom ;
580
+ topProperty = 'paddingTop' ;
581
+ bottomProperty = 'paddingBottom' ;
582
+ }
577
583
578
- newVal = this . _footerHeight ;
579
- if ( this . _tabsPlacement === 'bottom' ) {
580
- newVal += this . _tabbarHeight ;
581
- }
582
- if ( newVal !== this . contentBottom ) {
583
- scrollEle . style . marginBottom = ( newVal > 0 ? newVal + 'px' : '' ) ;
584
- this . contentBottom = newVal ;
584
+ // Only update top margin if value changed
585
+ if ( contentTop !== this . contentTop ) {
586
+ scrollEle . style [ topProperty ] = cssFormat ( contentTop ) ;
587
+ fixedEle . style . marginTop = cssFormat ( fixedTop ) ;
588
+ this . contentTop = contentTop ;
589
+ }
585
590
586
- if ( newVal > 0 && this . _footerEle ) {
587
- this . _footerEle . style . bottom = ( newVal - this . _footerHeight ) + 'px' ;
588
- }
589
- }
591
+ // Only update bottom margin if value changed
592
+ if ( contentBottom !== this . contentBottom ) {
593
+ scrollEle . style [ bottomProperty ] = cssFormat ( contentBottom ) ;
594
+ fixedEle . style . marginBottom = cssFormat ( fixedBottom ) ;
595
+ this . contentBottom = contentBottom ;
590
596
}
591
597
592
598
@@ -606,3 +612,7 @@ export class Content extends Ion {
606
612
function parsePxUnit ( val : string ) : number {
607
613
return ( val . indexOf ( 'px' ) > 0 ) ? parseInt ( val , 10 ) : 0 ;
608
614
}
615
+
616
+ function cssFormat ( val : number ) : string {
617
+ return ( val > 0 ? val + 'px' : '' ) ;
618
+ }
0 commit comments