Merge pull request #267 from lbryio/back-navigation-part-deux

create navigation button component and handle onPress events properly
This commit is contained in:
Akinwale Ariwodola 2018-08-30 14:38:46 +01:00 committed by GitHub
commit 30682bf8f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 51 additions and 10 deletions

View file

@ -40,18 +40,25 @@ import {
} from 'lbryinc'; } from 'lbryinc';
import { makeSelectClientSetting } from '../redux/selectors/settings'; import { makeSelectClientSetting } from '../redux/selectors/settings';
import { decode as atob } from 'base-64'; import { decode as atob } from 'base-64';
import Icon from 'react-native-vector-icons/FontAwesome5'; import NavigationButton from '../component/navigationButton';
import Constants from '../constants'; import Constants from '../constants';
import discoverStyle from '../styles/discover'; import discoverStyle from '../styles/discover';
import searchStyle from '../styles/search'; import searchStyle from '../styles/search';
import SearchRightHeaderIcon from '../component/searchRightHeaderIcon'; import SearchRightHeaderIcon from '../component/searchRightHeaderIcon';
const menuNavigationButton = (navigation) => <NavigationButton
name="bars"
size={24}
style={discoverStyle.drawerMenuButton}
iconStyle={discoverStyle.drawerHamburger}
onPress={() => navigation.navigate('DrawerOpen')} />
const discoverStack = StackNavigator({ const discoverStack = StackNavigator({
Discover: { Discover: {
screen: DiscoverPage, screen: DiscoverPage,
navigationOptions: ({ navigation }) => ({ navigationOptions: ({ navigation }) => ({
title: 'Discover', title: 'Discover',
headerLeft: <Icon name="bars" size={24} style={discoverStyle.drawerHamburger} onPress={() => navigation.navigate('DrawerOpen')} />, headerLeft: menuNavigationButton(navigation),
}) })
}, },
File: { File: {
@ -76,7 +83,7 @@ const trendingStack = StackNavigator({
screen: TrendingPage, screen: TrendingPage,
navigationOptions: ({ navigation }) => ({ navigationOptions: ({ navigation }) => ({
title: 'Trending', title: 'Trending',
headerLeft: <Icon name="bars" size={24} style={discoverStyle.drawerHamburger} onPress={() => navigation.navigate('DrawerOpen')} />, headerLeft: menuNavigationButton(navigation),
}) })
} }
}); });
@ -86,7 +93,7 @@ const walletStack = StackNavigator({
screen: WalletPage, screen: WalletPage,
navigationOptions: ({ navigation }) => ({ navigationOptions: ({ navigation }) => ({
title: 'Wallet', title: 'Wallet',
headerLeft: <Icon name="bars" size={24} style={discoverStyle.drawerHamburger} onPress={() => navigation.navigate('DrawerOpen')} />, headerLeft: menuNavigationButton(navigation),
}) })
}, },
TransactionHistory: { TransactionHistory: {
@ -105,7 +112,7 @@ const rewardsStack = StackNavigator({
screen: RewardsPage, screen: RewardsPage,
navigationOptions: ({ navigation }) => ({ navigationOptions: ({ navigation }) => ({
title: 'Rewards', title: 'Rewards',
headerLeft: <Icon name="bars" size={24} style={discoverStyle.drawerHamburger} onPress={() => navigation.navigate('DrawerOpen')} />, headerLeft: menuNavigationButton(navigation),
}) })
} }
}); });

View file

@ -0,0 +1,4 @@
import { connect } from 'react-redux';
import NavigationButton from './view';
export default connect()(NavigationButton);

View file

@ -0,0 +1,18 @@
import React from 'react';
import Icon from 'react-native-vector-icons/FontAwesome5';
import { TouchableOpacity } from 'react-native';
class NavigationButton extends React.PureComponent {
render() {
const { iconStyle, name, onPress, size, style } = this.props;
return (
<TouchableOpacity onPress={onPress} style={style}>
<Icon name={name} size={size} style={iconStyle} />
</TouchableOpacity>
);
}
};
export default NavigationButton;

View file

@ -9,6 +9,7 @@ import {
View View
} from 'react-native'; } from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome5'; import Icon from 'react-native-vector-icons/FontAwesome5';
import NavigationButton from '../navigationButton';
import pageHeaderStyle from '../../styles/pageHeader'; import pageHeaderStyle from '../../styles/pageHeader';
const APPBAR_HEIGHT = Platform.OS === 'ios' ? 44 : 56; const APPBAR_HEIGHT = Platform.OS === 'ios' ? 44 : 56;
@ -34,9 +35,13 @@ class PageHeader extends React.PureComponent {
{title} {title}
</AnimatedText> </AnimatedText>
</View> </View>
<TouchableOpacity style={pageHeaderStyle.left}> <NavigationButton
<Icon name="arrow-left" size={24} onPress={onBackPressed} style={pageHeaderStyle.backIcon} /> name="arrow-left"
</TouchableOpacity> style={pageHeaderStyle.left}
size={24}
iconStyle={pageHeaderStyle.backIcon}
onPress={onBackPressed}
/>
</View> </View>
</View> </View>
</View> </View>

View file

@ -80,8 +80,13 @@ const discoverStyle = StyleSheet.create({
textAlign: 'center', textAlign: 'center',
color: '#0c604b' color: '#0c604b'
}, },
drawerMenuButton: {
height: '100%',
justifyContent: 'center'
},
drawerHamburger: { drawerHamburger: {
marginLeft: 16 marginLeft: 16,
marginRight: 16
}, },
rightHeaderIcon: { rightHeaderIcon: {
marginRight: 16 marginRight: 16

View file

@ -34,7 +34,8 @@ const pageHeaderStyle = StyleSheet.create({
...platformContainerStyles, ...platformContainerStyles,
}, },
backIcon: { backIcon: {
marginLeft: 16 marginLeft: 16,
marginRight: 16
}, },
header: { header: {
...StyleSheet.absoluteFillObject, ...StyleSheet.absoluteFillObject,
@ -61,6 +62,7 @@ const pageHeaderStyle = StyleSheet.create({
left: 0, left: 0,
bottom: 0, bottom: 0,
top: 0, top: 0,
height: '100%',
position: 'absolute', position: 'absolute',
alignItems: 'center', alignItems: 'center',
flexDirection: 'row', flexDirection: 'row',