@@ -5,6 +5,11 @@ import React from 'react';
55import { View , Platform } from 'react-native' ;
66import NativeBaseComponent from '../Base/NativeBaseComponent' ;
77import computeProps from '../../Utils/computeProps' ;
8+ import Button from "./Button" ;
9+ import Title from "./Title" ;
10+ import InputGroup from "./InputGroup" ;
11+ import Subtitle from "./Subtitle" ;
12+ import _ from 'lodash' ;
813
914export default class Header extends NativeBaseComponent {
1015
@@ -16,18 +21,25 @@ export default class Header extends NativeBaseComponent {
1621 flexDirection : 'row' ,
1722 alignItems : 'center' ,
1823 padding : 15 ,
19- paddingTop : ( Platform . OS === 'ios' ) ? 25 : 15 ,
24+ paddingTop : ( Platform . OS === 'ios' ) ? 30 : 15 ,
2025 shadowColor : '#000' ,
2126 shadowOffset : { width : 0 , height : 2 } ,
2227 shadowOpacity : 0.1 ,
2328 shadowRadius : 1.5 ,
24- height : this . getTheme ( ) . toolbarHeight
29+ height : this . getTheme ( ) . toolbarHeight ,
30+ elevation : 2
2531 } ,
26- title : {
27- color : '#fff' ,
28- fontSize : 20 ,
29- fontWeight : "500" ,
30- alignSelf : 'center'
32+ iosToolbarSearch : {
33+ backgroundColor : this . getTheme ( ) . toolbarInputColor ,
34+ borderRadius : this . props . rounded ? 25 : 2 ,
35+ height : 30 ,
36+ borderColor : 'transparent'
37+ } ,
38+ androidToolbarSearch : {
39+ backgroundColor : "#fff" ,
40+ borderRadius : 2 ,
41+ borderColor : 'transparent' ,
42+ elevation : 2
3143 }
3244 }
3345 }
@@ -41,30 +53,95 @@ export default class Header extends NativeBaseComponent {
4153 return computeProps ( this . props , defaultProps ) ;
4254
4355 }
56+ renderChildren ( ) {
57+ if ( ! Array . isArray ( this . props . children ) ) {
58+ return this . props . children ;
59+ }
60+
61+ else if ( Array . isArray ( this . props . children ) ) {
62+ var newChildren = [ ] ;
63+ var childrenArray = React . Children . toArray ( this . props . children ) ;
64+
65+ var buttons = [ ] ;
66+ buttons = _ . remove ( childrenArray , function ( item ) {
67+ if ( item . type == Button ) {
68+ return true ;
69+ }
70+ } ) ;
71+
72+ var title = [ ] ;
73+ title = _ . remove ( childrenArray , function ( item ) {
74+ if ( item . type == Title ) {
75+ return true ;
76+ }
77+ } ) ;
78+
79+ var subtitle = [ ] ;
80+ subtitle = _ . remove ( childrenArray , function ( item ) {
81+ if ( item . type == Subtitle ) {
82+ return true ;
83+ }
84+ } ) ;
85+
86+ var input = [ ] ;
87+ input = _ . remove ( childrenArray , function ( item ) {
88+ if ( item . type == InputGroup ) {
89+ return true ;
90+ }
91+ } ) ;
4492
45- render ( ) {
4693
94+ if ( this . props . searchBar ) {
95+ if ( Platform . OS === 'ios' ) {
96+ newChildren . push ( < View style = { { flex : 4 , alignItems : 'center' , justifyContent : 'flex-start' , flexDirection : 'row' , marginLeft : - 7 } } >
97+ { React . cloneElement ( input [ 0 ] , { style : this . getInitialStyle ( ) . iosToolbarSearch , toolbar : true } ) }
98+ </ View > )
99+ newChildren . push ( < View style = { { flex :1 , alignItems : 'center' , justifyContent : 'flex-end' , flexDirection : 'row' , marginRight : - 24 , marginLeft : 10 } } >
100+ { React . cloneElement ( buttons [ 0 ] , { color : this . getTheme ( ) . iosToolbarBtnColor } ) }
101+ </ View > )
102+ } else {
103+ newChildren . push ( < View style = { { flex : 1 , alignItems : 'center' , paddingBottom : 4 , justifyContent : 'flex-start' , flexDirection : 'row' , marginLeft : - 8 , marginRight : - 8 } } >
104+ { React . cloneElement ( input [ 0 ] , { style : this . getInitialStyle ( ) . androidToolbarSearch , atoolbar : true } ) }
105+ </ View > )
106+ }
107+ }
108+ else {
109+ if ( Platform . OS === 'ios' ) {
110+ newChildren . push ( < View style = { { flex : 1 , alignItems : 'center' , justifyContent : 'flex-start' , flexDirection : 'row' , marginLeft : - 14 } } >
111+ { React . cloneElement ( buttons [ 0 ] , { color : this . getTheme ( ) . iosToolbarBtnColor } ) }
112+ </ View > )
113+ newChildren . push ( < View style = { { flex : 3 , alignSelf : 'center' , justifyContent : 'space-between' } } >
114+ { [ title [ 0 ] , subtitle [ 0 ] ] }
115+ </ View > )
116+ for ( let i = 1 ; i < buttons . length ; i ++ ) {
117+ newChildren . push ( < View style = { { alignItems : 'center' , justifyContent : 'flex-start' , flexDirection : 'row' , marginRight : - 14 } } >
118+ { React . cloneElement ( buttons [ i ] , { color : this . getTheme ( ) . iosToolbarBtnColor } ) }
119+ </ View > )
120+ }
121+ } else {
122+ newChildren . push ( < View style = { { alignItems : 'center' , justifyContent : 'flex-start' , flexDirection : 'row' , marginLeft : - 10 , marginRight : 12 } } >
123+ { buttons [ 0 ] }
124+ </ View > )
125+ newChildren . push ( < View style = { { flex : 3 , alignSelf : 'stretch' } } >
126+ { [ title [ 0 ] ] }
127+ </ View > )
128+ for ( let i = 1 ; i < buttons . length ; i ++ ) {
129+ newChildren . push ( < View style = { { alignItems : 'center' , justifyContent : 'flex-start' , flexDirection : 'row' , marginRight : - 7 } } >
130+ { buttons [ i ] }
131+ </ View > )
132+
133+ }
134+ }
135+
136+ }
137+ return newChildren ;
138+ }
139+ }
140+
141+ render ( ) {
47142 return (
48- < View { ...this . prepareRootProps ( ) } >
49- { ! Array . isArray ( this . props . children ) &&
50- < View >
51- { this . props . children }
52- </ View > }
53-
54- { Array . isArray ( this . props . children ) &&
55- < View style = { { flex : 1 , alignItems : 'center' , justifyContent : 'flex-start' , flexDirection : 'row' , marginLeft : - 14 } } >
56- { this . props . children [ 0 ] }
57- </ View > }
58-
59- { Array . isArray ( this . props . children ) &&
60- < View style = { { flex : 3 , alignSelf : 'center' } } >
61- { this . props . children [ 1 ] }
62- </ View > }
63-
64- { Array . isArray ( this . props . children ) &&
65- < View style = { { flex :1 , alignItems : 'center' , justifyContent : 'flex-end' , flexDirection : 'row' , marginRight : - 14 } } >
66- { this . props . children [ 2 ] }
67- </ View > }
143+ < View { ...this . prepareRootProps ( ) } >
144+ { this . renderChildren ( ) }
68145 </ View >
69146 ) ;
70147 }
0 commit comments