@@ -2,13 +2,9 @@ import React from 'react';
22import type { ColorValue , StyleProp , ViewStyle } from 'react-native' ;
33import { StyleSheet , Animated } from 'react-native' ;
44
5- import AppbarAction from './AppbarAction' ;
6- import AppbarBackAction from './AppbarBackAction' ;
7- import AppbarContent from './AppbarContent' ;
85import overlay from '../../styles/overlay' ;
96import { black , white } from '../../styles/themes/v2/colors' ;
107import type { InternalTheme , ThemeProp } from '../../types' ;
11- import Tooltip from '../Tooltip/Tooltip' ;
128
139export type AppbarModes = 'small' | 'medium' | 'large' | 'center-aligned' ;
1410
@@ -93,8 +89,9 @@ type BaseProps = {
9389type RenderAppbarContentProps = BaseProps & {
9490 children : React . ReactNode ;
9591 shouldCenterContent ?: boolean ;
96- renderOnly ?: ( React . ComponentType < any > | false ) [ ] ;
97- renderExcept ?: React . ComponentType < any > [ ] ;
92+ isV3 : boolean ;
93+ renderOnly ?: ( string | boolean ) [ ] ;
94+ renderExcept ?: string [ ] ;
9895 mode ?: AppbarModes ;
9996 theme ?: ThemeProp ;
10097} ;
@@ -126,50 +123,56 @@ export const renderAppbarContent = ({
126123 mode = 'small' ,
127124 theme,
128125} : RenderAppbarContentProps ) => {
129- return (
130- React . Children . toArray ( children as React . ReactNode | React . ReactNode [ ] )
131- . filter ( ( child ) => child != null && typeof child !== 'boolean' )
132- . filter ( ( child ) =>
133- // @ts -expect-error: TypeScript complains about the type of type but it doesn't matter
134- renderExcept ? ! renderExcept . includes ( child . type ) : child
135- )
126+ return React . Children . toArray ( children as React . ReactNode | React . ReactNode [ ] )
127+ . filter ( ( child ) => child != null && typeof child !== 'boolean' )
128+ . filter ( ( child ) =>
129+ // @ts -expect-error: TypeScript complains about the type of type but it doesn't matter
130+ renderExcept ? ! renderExcept . includes ( child . type . displayName ) : child
131+ )
132+ . filter ( ( child ) =>
133+ // @ts -expect-error: TypeScript complains about the type of type but it doesn't matter
134+ renderOnly ? renderOnly . includes ( child . type . displayName ) : child
135+ )
136+ . map ( ( child , i ) => {
137+ if (
138+ ! React . isValidElement ( child ) ||
139+ ! [
140+ 'Appbar.Content' ,
141+ 'Appbar.Action' ,
142+ 'Appbar.BackAction' ,
143+ 'Tooltip' ,
144+ ] . includes (
145+ // @ts -expect-error: TypeScript complains about the type of type but it doesn't matter
146+ child . type . displayName
147+ )
148+ ) {
149+ return child ;
150+ }
151+
152+ const props : {
153+ color ?: string ;
154+ style ?: StyleProp < ViewStyle > ;
155+ mode ?: AppbarModes ;
156+ theme ?: ThemeProp ;
157+ } = {
158+ theme,
159+ color : getAppbarColor ( { color : child . props . color , isDark, isV3 } ) ,
160+ } ;
161+
136162 // @ts -expect-error: TypeScript complains about the type of type but it doesn't matter
137- . filter ( ( child ) => ( renderOnly ? renderOnly . includes ( child . type ) : child ) )
138- . map ( ( child , i ) => {
139- if (
140- ! React . isValidElement ( child ) ||
141- ! [ AppbarContent , AppbarAction , AppbarBackAction , Tooltip ] . includes (
142- // @ts -expect-error: TypeScript complains about the type of type but it doesn't matter
143- child . type
144- )
145- ) {
146- return child ;
147- }
148-
149- const props : {
150- color ?: string ;
151- style ?: StyleProp < ViewStyle > ;
152- mode ?: AppbarModes ;
153- theme ?: ThemeProp ;
154- } = {
155- theme,
156- color : getAppbarColor ( { color : child . props . color , isDark, isV3 } ) ,
157- } ;
158-
159- if ( child . type === AppbarContent ) {
160- props . mode = mode ;
161- props . style = [
162- isV3
163- ? i === 0 && ! shouldCenterContent && styles . v3Spacing
164- : i !== 0 && styles . v2Spacing ,
165- shouldCenterContent && styles . centerAlignedContent ,
166- child . props . style ,
167- ] ;
168- props . color ;
169- }
170- return React . cloneElement ( child , props ) ;
171- } )
172- ) ;
163+ if ( child . type . displayName === 'Appbar.Content' ) {
164+ props . mode = mode ;
165+ props . style = [
166+ isV3
167+ ? i === 0 && ! shouldCenterContent && styles . v3Spacing
168+ : i !== 0 && styles . v2Spacing ,
169+ shouldCenterContent && styles . centerAlignedContent ,
170+ child . props . style ,
171+ ] ;
172+ props . color ;
173+ }
174+ return React . cloneElement ( child , props ) ;
175+ } ) ;
173176} ;
174177
175178const styles = StyleSheet . create ( {
0 commit comments