import color from 'color'; import * as React from 'react'; import { Platform, StyleProp, StyleSheet, TextStyle, TouchableWithoutFeedback, View, ViewStyle, } from 'react-native'; import { withTheme } from '../../core/theming'; import { white } from '../../styles/colors'; import type { $RemoveChildren } from '../../types'; import Text from '../Typography/Text'; type Props = $RemoveChildren & { /** * Custom color for the text. */ color?: string; /** * Text for the title. */ title: React.ReactNode; /** * Style for the title. */ titleStyle?: StyleProp; /** * Reference for the title. */ titleRef?: React.RefObject; /** * Text for the subtitle. */ subtitle?: React.ReactNode; /** * Style for the subtitle. */ subtitleStyle?: StyleProp; /** * Function to execute on press. */ onPress?: () => void; style?: StyleProp; /** * Title uses font scaling */ allowTitleFontScaling?: boolean; /** * Subtitle uses font scaling */ allowSubtitleFontScaling?: boolean; /** * @optional */ theme: ReactNativePaper.Theme; }; /** * A component used to display a title and optional subtitle in an appbar. * *
*
* *
*
* * ## Usage * ```js * import * as React from 'react'; * import { Appbar } from 'react-native-paper'; * * const MyComponent = () => ( * * * * ); * * export default MyComponent; * ``` */ const AppbarContent = React.forwardRef( ( { color: titleColor = white, subtitle, subtitleStyle, onPress, style, titleRef, titleStyle, theme, title, allowTitleFontScaling, allowSubtitleFontScaling, ...rest }: Props, ref: React.ForwardedRef ) => { const { fonts } = theme; const subtitleColor = color(titleColor).alpha(0.7).rgb().string(); let titleElement: React.ReactNode | null = null; let subtitleElement: React.ReactNode | null = null; const titleAccessibilityTraits: any = rest.accessible ? { accessible: false } : { accessible: true, accessibilityTraits: 'header', accessibilityRole: Platform.OS === 'web' ? 'heading' : 'header', }; const subtitleAccessibilityTraits = rest.accessible ? { accessible: false } : {}; if (title) { if (typeof title === 'string') { titleElement = ( {title} ); } else { titleElement = title; } } if (subtitle) { if (typeof subtitle === 'string') { subtitleElement = ( {subtitle} ); } else { subtitleElement = subtitle; } } const textView = ( {titleElement} {subtitleElement} ); if (onPress) { return ( onPress()}> {textView} ); } else { return textView; } } ); AppbarContent.displayName = 'Appbar.Content'; const styles = StyleSheet.create({ container: { flex: 1, paddingHorizontal: 12, }, title: { fontSize: Platform.OS === 'ios' ? 17 : 20, }, subtitle: { fontSize: Platform.OS === 'ios' ? 11 : 14, }, }); export default withTheme(AppbarContent); // @component-docs ignore-next-line const AppbarContentWithTheme = withTheme(AppbarContent); // @component-docs ignore-next-line export { AppbarContentWithTheme as AppbarContent };