@@ -11,6 +11,7 @@ import {
1111 ViewStyle ,
1212 LayoutChangeEvent ,
1313 StyleProp ,
14+ TextProps ,
1415} from 'react-native' ;
1516
1617import {
@@ -29,6 +30,7 @@ import {
2930 HeaderLayoutPreset ,
3031 SceneInterpolatorProps ,
3132 HeaderProps ,
33+ HeaderBackButtonProps ,
3234} from '../../types' ;
3335
3436type Props = HeaderProps & {
@@ -216,27 +218,27 @@ class Header extends React.PureComponent<Props, State> {
216218 }
217219 : undefined ;
218220
219- const HeaderTitleComponent =
221+ const render =
220222 headerTitle && typeof headerTitle !== 'string'
221- ? headerTitle
222- : HeaderTitle ;
223- return (
224- < HeaderTitleComponent
225- onLayout = { onLayout }
226- allowFontScaling = { ! ! allowFontScaling }
227- style = { [
228- color ? { color } : null ,
229- layoutPreset === 'center'
230- ? // eslint-disable-next-line react-native/no-inline-styles
231- { textAlign : 'center' }
232- : // eslint-disable-next-line react-native/no-inline-styles
233- { textAlign : 'left' } ,
234- titleStyle ,
235- ] }
236- >
237- { titleString }
238- </ HeaderTitleComponent >
239- ) ;
223+ ? ( headerTitle as (
224+ props : TextProps & { children ?: string }
225+ ) => React . ReactNode )
226+ : ( props : TextProps & { children ?: string } ) => (
227+ < HeaderTitle { ... props } />
228+ ) ;
229+
230+ return render ( {
231+ onLayout ,
232+ allowFontScaling : Boolean ( allowFontScaling ) ,
233+ style : [
234+ color ? { color } : null ,
235+ layoutPreset === 'center'
236+ ? { textAlign : 'center' }
237+ : { textAlign : 'left' } ,
238+ titleStyle ,
239+ ] ,
240+ children : titleString ,
241+ } ) ;
240242 } ;
241243
242244 private renderLeftComponent = ( props : SubviewProps ) => {
@@ -259,7 +261,9 @@ class Header extends React.PureComponent<Props, State> {
259261 const width = this . state . widths [ props . scene . key ]
260262 ? ( this . props . layout . initWidth - this . state . widths [ props . scene . key ] ) / 2
261263 : undefined ;
262- const RenderedLeftComponent = options . headerLeft || HeaderBackButton ;
264+ const RenderedLeftComponent =
265+ ( options . headerLeft as React . FunctionComponent < HeaderBackButtonProps > ) ||
266+ HeaderBackButton ;
263267 const goBack = ( ) => {
264268 // Go back on next tick because button ripple effect needs to happen on Android
265269 requestAnimationFrame ( ( ) => {
@@ -331,6 +335,11 @@ class Header extends React.PureComponent<Props, State> {
331335
332336 private renderRightComponent = ( props : SubviewProps ) => {
333337 const { headerRight } = props . scene . descriptor . options ;
338+
339+ if ( typeof headerRight === 'function' ) {
340+ return headerRight ( ) ;
341+ }
342+
334343 return headerRight || null ;
335344 } ;
336345
0 commit comments