Skip to content

Commit

Permalink
feat: add onpress prop for appbar content (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
james-watkin committed Dec 18, 2018
1 parent 1a4d006 commit 2919714
Showing 1 changed file with 35 additions and 22 deletions.
57 changes: 35 additions & 22 deletions src/components/Appbar/AppbarContent.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
/* @flow */

import * as React from 'react';
import { View, StyleSheet, Platform } from 'react-native';
import {
View,
StyleSheet,
Platform,
TouchableWithoutFeedback,
} from 'react-native';
import color from 'color';

import Text from '../Typography/Text';
Expand Down Expand Up @@ -32,6 +37,10 @@ type Props = $RemoveChildren<typeof View> & {|
* Style for the subtitle.
*/
subtitleStyle?: any,
/**
* Function to execute on press.
*/
onPress?: () => mixed,
style?: any,
/**
* @optional
Expand All @@ -50,6 +59,7 @@ class AppbarContent extends React.Component<Props> {
color: titleColor = black,
subtitle,
subtitleStyle,
onPress,
style,
titleStyle,
theme,
Expand All @@ -64,31 +74,34 @@ class AppbarContent extends React.Component<Props> {
.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 ? (
<TouchableWithoutFeedback onPress={onPress}>
<View style={[styles.container, style]} {...rest}>
<Text
style={[styles.subtitle, { color: subtitleColor }, subtitleStyle]}
style={[
{
color: titleColor,
fontFamily:
Platform.OS === 'ios' ? fonts.regular : fonts.medium,
},
styles.title,
titleStyle,
]}
numberOfLines={1}
accessibilityTraits="header"
accessibilityRole="header"
>
{subtitle}
{title}
</Text>
) : null}
</View>
{subtitle ? (
<Text
style={[styles.subtitle, { color: subtitleColor }, subtitleStyle]}
numberOfLines={1}
>
{subtitle}
</Text>
) : null}
</View>
</TouchableWithoutFeedback>
);
}
}
Expand Down

0 comments on commit 2919714

Please sign in to comment.