forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAppbarContent.js
109 lines (98 loc) · 2.15 KB
/
AppbarContent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/* @flow */
import * as React from 'react';
import { View, StyleSheet, Platform } from 'react-native';
import color from 'color';
import Text from '../Typography/Text';
import { withTheme } from '../../core/theming';
import { black } from '../../styles/colors';
import type { Theme, $RemoveChildren } from '../../types';
type Props = $RemoveChildren<typeof View> & {|
/**
* Custom color for the text.
*/
color?: string,
/**
* Text for the title.
*/
title: React.Node,
/**
* Style for the title.
*/
titleStyle?: any,
/**
* Text for the subtitle.
*/
subtitle?: React.Node,
/**
* Style for the subtitle.
*/
subtitleStyle?: any,
style?: any,
/**
* @optional
*/
theme: Theme,
|};
/**
* A component used to display a title and optional subtitle in a appbar.
*/
class AppbarContent extends React.Component<Props> {
static displayName = 'Appbar.Content';
render() {
const {
color: titleColor = black,
subtitle,
subtitleStyle,
style,
titleStyle,
theme,
title,
...rest
} = this.props;
const { fonts } = theme;
const subtitleColor = color(titleColor)
.alpha(0.7)
.rgb()
.string();
return (
<View style={[styles.container, style]} {...rest}>
<Text
style={[
{
color: titleColor,
fontFamily: Platform.OS === 'ios' ? fonts.regular : fonts.medium,
},
styles.title,
titleStyle,
]}
numberOfLines={1}
accessibilityTraits="header"
accessibilityRole="header"
>
{title}
</Text>
{subtitle ? (
<Text
style={[styles.subtitle, { color: subtitleColor }, subtitleStyle]}
numberOfLines={1}
>
{subtitle}
</Text>
) : null}
</View>
);
}
}
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);