Skip to content

Commit 79e1ef2

Browse files
authored
feat: add onpress prop for appbar content (#700)
1 parent c80ca3f commit 79e1ef2

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

src/components/Appbar/AppbarContent.js

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
/* @flow */
22

33
import * as React from 'react';
4-
import { View, StyleSheet, Platform } from 'react-native';
4+
import {
5+
View,
6+
StyleSheet,
7+
Platform,
8+
TouchableWithoutFeedback,
9+
} from 'react-native';
510
import color from 'color';
611

712
import Text from '../Typography/Text';
@@ -32,6 +37,10 @@ type Props = $RemoveChildren<typeof View> & {|
3237
* Style for the subtitle.
3338
*/
3439
subtitleStyle?: any,
40+
/**
41+
* Function to execute on press.
42+
*/
43+
onPress?: () => mixed,
3544
style?: any,
3645
/**
3746
* @optional
@@ -50,6 +59,7 @@ class AppbarContent extends React.Component<Props> {
5059
color: titleColor = black,
5160
subtitle,
5261
subtitleStyle,
62+
onPress,
5363
style,
5464
titleStyle,
5565
theme,
@@ -64,31 +74,34 @@ class AppbarContent extends React.Component<Props> {
6474
.string();
6575

6676
return (
67-
<View style={[styles.container, style]} {...rest}>
68-
<Text
69-
style={[
70-
{
71-
color: titleColor,
72-
fontFamily: Platform.OS === 'ios' ? fonts.regular : fonts.medium,
73-
},
74-
styles.title,
75-
titleStyle,
76-
]}
77-
numberOfLines={1}
78-
accessibilityTraits="header"
79-
accessibilityRole="header"
80-
>
81-
{title}
82-
</Text>
83-
{subtitle ? (
77+
<TouchableWithoutFeedback onPress={onPress}>
78+
<View style={[styles.container, style]} {...rest}>
8479
<Text
85-
style={[styles.subtitle, { color: subtitleColor }, subtitleStyle]}
80+
style={[
81+
{
82+
color: titleColor,
83+
fontFamily:
84+
Platform.OS === 'ios' ? fonts.regular : fonts.medium,
85+
},
86+
styles.title,
87+
titleStyle,
88+
]}
8689
numberOfLines={1}
90+
accessibilityTraits="header"
91+
accessibilityRole="header"
8792
>
88-
{subtitle}
93+
{title}
8994
</Text>
90-
) : null}
91-
</View>
95+
{subtitle ? (
96+
<Text
97+
style={[styles.subtitle, { color: subtitleColor }, subtitleStyle]}
98+
numberOfLines={1}
99+
>
100+
{subtitle}
101+
</Text>
102+
) : null}
103+
</View>
104+
</TouchableWithoutFeedback>
92105
);
93106
}
94107
}

0 commit comments

Comments
 (0)