@@ -27,7 +27,7 @@ import {
27
27
StyleUtils ,
28
28
validateBasis ,
29
29
StyleBuilder ,
30
- StyleBuilderOutput ,
30
+ StyleDefinition ,
31
31
} from '@angular/flex-layout/core' ;
32
32
import { Subscription } from 'rxjs' ;
33
33
@@ -41,19 +41,16 @@ export type FlexBasisAlias = 'grow' | 'initial' | 'auto' | 'none' | 'nogrow' | '
41
41
interface FlexBuilderParent {
42
42
direction : string ;
43
43
hasWrap : boolean ;
44
- useColumnBasisZero : boolean | undefined ;
45
44
}
46
45
47
46
@Injectable ( { providedIn : 'root' } )
48
47
export class FlexStyleBuilder extends StyleBuilder {
49
- constructor ( ) {
48
+ constructor ( @ Inject ( LAYOUT_CONFIG ) protected layoutConfig : LayoutConfigOptions ) {
50
49
super ( ) ;
51
50
}
52
- buildStyles ( input : string , parent : FlexBuilderParent ) : StyleBuilderOutput {
53
- let grow : string | number ;
54
- let shrink : string | number ;
55
- let basis : string | number ;
56
- [ grow , shrink , basis ] = input . split ( '_' ) ;
51
+ buildStyles ( input : string , parent : FlexBuilderParent ) {
52
+ let [ grow , shrink , ...basisParts ] : ( string | number ) [ ] = input . split ( ' ' ) ;
53
+ let basis = basisParts . join ( ' ' ) ;
57
54
58
55
// The flex-direction of this element's flex container. Defaults to 'row'.
59
56
const direction = ( parent . direction . indexOf ( 'column' ) > - 1 ) ? 'column' : 'row' ;
@@ -100,7 +97,7 @@ export class FlexStyleBuilder extends StyleBuilder {
100
97
} ;
101
98
switch ( basis || '' ) {
102
99
case '' :
103
- const useColumnBasisZero = parent . useColumnBasisZero !== false ;
100
+ const useColumnBasisZero = this . layoutConfig . useColumnBasisZero !== false ;
104
101
basis = direction === 'row' ? '0%' : ( useColumnBasisZero ? '0.000000001px' : 'auto' ) ;
105
102
break ;
106
103
case 'initial' : // default
@@ -195,7 +192,7 @@ export class FlexStyleBuilder extends StyleBuilder {
195
192
}
196
193
}
197
194
198
- return { styles : extendObject ( css , { 'box-sizing' : 'border-box' } ) , shouldCache : true } ;
195
+ return extendObject ( css , { 'box-sizing' : 'border-box' } ) as StyleDefinition ;
199
196
}
200
197
}
201
198
@@ -313,12 +310,25 @@ export class FlexDirective extends BaseDirective implements OnInit, OnChanges, O
313
310
flexBasis = this . _mqActivation . activatedInput ;
314
311
}
315
312
316
- let basis = String ( flexBasis ) . replace ( ';' , '' ) ;
317
- let parts = validateBasis ( basis , this . _queryInput ( 'grow' ) , this . _queryInput ( 'shrink' ) ) ;
313
+ const basis = String ( flexBasis ) . replace ( ';' , '' ) ;
314
+ const parts = validateBasis ( basis , this . _queryInput ( 'grow' ) , this . _queryInput ( 'shrink' ) ) ;
318
315
const addFlexToParent = this . layoutConfig . addFlexToParent !== false ;
319
316
const direction = this . _getFlexFlowDirection ( this . parentElement , addFlexToParent ) ;
320
317
const hasWrap = this . _layout && this . _layout . wrap ;
321
- const useColumnBasisZero = this . layoutConfig . useColumnBasisZero ;
322
- this . addStyles ( parts . join ( '_' ) , { direction, hasWrap, useColumnBasisZero} ) ;
318
+ if ( direction === 'row' && hasWrap ) {
319
+ this . _styleCache = flexRowWrapCache ;
320
+ } else if ( direction === 'row' && ! hasWrap ) {
321
+ this . _styleCache = flexRowCache ;
322
+ } else if ( direction === 'column' && hasWrap ) {
323
+ this . _styleCache = flexColumnWrapCache ;
324
+ } else if ( direction === 'column' && ! hasWrap ) {
325
+ this . _styleCache = flexColumnCache ;
326
+ }
327
+ this . addStyles ( parts . join ( ' ' ) , { direction, hasWrap} ) ;
323
328
}
324
329
}
330
+
331
+ const flexRowCache : Map < string , StyleDefinition > = new Map ( ) ;
332
+ const flexColumnCache : Map < string , StyleDefinition > = new Map ( ) ;
333
+ const flexRowWrapCache : Map < string , StyleDefinition > = new Map ( ) ;
334
+ const flexColumnWrapCache : Map < string , StyleDefinition > = new Map ( ) ;
0 commit comments