({
children,
dark,
style,
mode = 'small',
elevated,
safeAreaInsets,
theme: themeOverrides,
...rest
}: Props)
| 155 | * ``` |
| 156 | */ |
| 157 | const Appbar = ({ |
| 158 | children, |
| 159 | dark, |
| 160 | style, |
| 161 | mode = 'small', |
| 162 | elevated, |
| 163 | safeAreaInsets, |
| 164 | theme: themeOverrides, |
| 165 | ...rest |
| 166 | }: Props) => { |
| 167 | const theme = useInternalTheme(themeOverrides); |
| 168 | const { isV3 } = theme; |
| 169 | const flattenedStyle = StyleSheet.flatten(style); |
| 170 | const { |
| 171 | backgroundColor: customBackground, |
| 172 | elevation = isV3 ? (elevated ? 2 : 0) : 4, |
| 173 | ...restStyle |
| 174 | } = (flattenedStyle || {}) as Exclude<typeof flattenedStyle, number> & { |
| 175 | elevation?: number; |
| 176 | backgroundColor?: ColorValue; |
| 177 | }; |
| 178 | |
| 179 | const backgroundColor = getAppbarBackgroundColor( |
| 180 | theme, |
| 181 | elevation, |
| 182 | customBackground, |
| 183 | elevated |
| 184 | ); |
| 185 | |
| 186 | const isMode = (modeToCompare: AppbarModes) => { |
| 187 | return isV3 && mode === modeToCompare; |
| 188 | }; |
| 189 | |
| 190 | let isDark = false; |
| 191 | |
| 192 | if (typeof dark === 'boolean') { |
| 193 | isDark = dark; |
| 194 | } else if (!isV3) { |
| 195 | isDark = |
| 196 | backgroundColor === 'transparent' |
| 197 | ? false |
| 198 | : typeof backgroundColor === 'string' |
| 199 | ? !color(backgroundColor).isLight() |
| 200 | : true; |
| 201 | } |
| 202 | |
| 203 | const isV3CenterAlignedMode = isV3 && isMode('center-aligned'); |
| 204 | |
| 205 | let shouldCenterContent = false; |
| 206 | let shouldAddLeftSpacing = false; |
| 207 | let shouldAddRightSpacing = false; |
| 208 | if ((!isV3 && Platform.OS === 'ios') || isV3CenterAlignedMode) { |
| 209 | let hasAppbarContent = false; |
| 210 | let leftItemsCount = 0; |
| 211 | let rightItemsCount = 0; |
| 212 | |
| 213 | React.Children.forEach(children, (child) => { |
| 214 | if (React.isValidElement<AppbarChildProps>(child)) { |
nothing calls this directly
no test coverage detected
searching dependent graphs…