Fixed header design

This commit is contained in:
mistikk 2018-11-02 14:41:59 +03:00
parent a4d9d1168c
commit 38321a2a4f
8 changed files with 68 additions and 36 deletions

View File

@ -1,5 +1,6 @@
import React, { Component } from 'react'; import React, { Component } from 'react';
import { withNavigation } from 'react-navigation'; import { withNavigation } from 'react-navigation';
import { connect } from 'react-redux';
// Services and Actions // Services and Actions
@ -41,14 +42,22 @@ class HeaderContainer extends Component {
}; };
render() { render() {
const { isLoggedIn, currentAccount } = this.props;
return ( return (
<HeaderView <HeaderView
handleOnPressBackButton={this._handleOnPressBackButton} handleOnPressBackButton={this._handleOnPressBackButton}
handleOpenDrawer={this._handleOpenDrawer} handleOpenDrawer={this._handleOpenDrawer}
isLoggedIn={isLoggedIn}
currentAccount={currentAccount}
{...this.props} {...this.props}
/> />
); );
} }
} }
export default withNavigation(HeaderContainer); const mapStateToProps = state => ({
isLoggedIn: state.application.isLoggedIn || false,
currentAccount: state.account.currentAccount || {},
});
export default connect(mapStateToProps)(withNavigation(HeaderContainer));

View File

@ -13,11 +13,14 @@ export default EStyleSheet.create({
justifyContent: 'space-between', justifyContent: 'space-between',
flexDirection: 'row-reverse', flexDirection: 'row-reverse',
}, },
avatarWrapperReverse: { avatarWrapper: {
justifyContent: 'center',
},
avatarButtonWrapperReverse: {
borderTopLeftRadius: 68 / 2, borderTopLeftRadius: 68 / 2,
borderBottomLeftRadius: 68 / 2, borderBottomLeftRadius: 68 / 2,
}, },
avatarWrapper: { avatarButtonWrapper: {
backgroundColor: '#357ce6', backgroundColor: '#357ce6',
height: 50, height: 50,
width: 68, width: 68,
@ -38,6 +41,10 @@ export default EStyleSheet.create({
fontWeight: 'bold', fontWeight: 'bold',
color: '$primaryDarkGray', color: '$primaryDarkGray',
}, },
noAuthTitle: {
fontSize: 14,
color: '$iconColor',
},
subTitle: { subTitle: {
color: '$primaryDarkGray', color: '$primaryDarkGray',
fontSize: 12, fontSize: 12,

View File

@ -3,10 +3,8 @@ import {
View, StatusBar, Text, SafeAreaView, TouchableOpacity, View, StatusBar, Text, SafeAreaView, TouchableOpacity,
} from 'react-native'; } from 'react-native';
import FastImage from 'react-native-fast-image'; import FastImage from 'react-native-fast-image';
// Constants
// Utils // Utils
import { getReputation } from '../../../utils/user'; import { getReputation } from '../../../utils/user';
// Components // Components
@ -33,46 +31,70 @@ class HeaderView extends Component {
// Component Functions // Component Functions
_getNameOfUser = () => {
const { currentAccount } = this.props;
if (Object.keys(currentAccount).length === 0) return '';
const jsonMetadata = JSON.parse(currentAccount.json_metadata);
if (Object.keys(jsonMetadata).length !== 0) {
return jsonMetadata.profile.name;
}
return currentAccount.name;
};
_getUserAvatar = () => {
const { currentAccount } = this.props;
if (Object.keys(currentAccount).length === 0) return DEFAULT_IMAGE;
const jsonMetadata = JSON.parse(currentAccount.json_metadata);
if (Object.keys(jsonMetadata).length !== 0) {
return { uri: jsonMetadata.profile.profile_image };
}
return DEFAULT_IMAGE;
};
render() { render() {
const { const {
avatar,
handleOpenDrawer, handleOpenDrawer,
handleOnPressBackButton, handleOnPressBackButton,
hideStatusBar, hideStatusBar,
userName,
isReverse, isReverse,
name, currentAccount,
reputation, isLoggedIn,
} = this.props; } = this.props;
return ( return (
<SafeAreaView style={[styles.container, isReverse && styles.containerReverse]}> <SafeAreaView style={[styles.container, isReverse && styles.containerReverse]}>
<StatusBar hidden={hideStatusBar} translucent /> <StatusBar hidden={hideStatusBar} translucent />
<TouchableOpacity onPress={() => !isReverse && handleOpenDrawer()}> <TouchableOpacity
style={styles.avatarWrapper}
onPress={() => !isReverse && handleOpenDrawer()}
>
<View <View
style={[ style={[
styles.avatarWrapper, styles.avatarButtonWrapper,
isReverse ? styles.avatarWrapperReverse : styles.avatarDefault, isReverse ? styles.avatarButtonWrapperReverse : styles.avatarDefault,
]} ]}
> >
<FastImage <FastImage
style={styles.avatar} style={styles.avatar}
source={{ uri: avatar }} source={this._getUserAvatar()}
defaultSource={DEFAULT_IMAGE} defaultSource={DEFAULT_IMAGE}
/> />
</View> </View>
</TouchableOpacity> </TouchableOpacity>
<View style={styles.titleWrapper}> {isLoggedIn ? (
{name && <Text style={styles.title}>{name}</Text>} <View style={styles.titleWrapper}>
{userName !== undefined <Text style={styles.title}>{this._getNameOfUser()}</Text>
&& reputation !== undefined && ( <Text style={styles.subTitle}>
<Text style={styles.subTitle}> @
@ {currentAccount.name}
{userName} {`(${getReputation(currentAccount.reputation)})`}
{`(${getReputation(reputation)})`} </Text>
</Text> </View>
)} ) : (
</View> <View style={styles.titleWrapper}>
<Text style={styles.noAuthTitle}>Log in to customize your feed</Text>
</View>
)}
{isReverse && ( {isReverse && (
<View style={styles.backButtonWrapper}> <View style={styles.backButtonWrapper}>
<IconButton <IconButton

View File

@ -68,7 +68,7 @@ class SideMenuView extends Component {
if (Object.keys(currentAccount).length === 0) return DEFAULT_IMAGE; if (Object.keys(currentAccount).length === 0) return DEFAULT_IMAGE;
const jsonMetadata = JSON.parse(currentAccount.json_metadata); const jsonMetadata = JSON.parse(currentAccount.json_metadata);
if (Object.keys(jsonMetadata).length !== 0) { if (Object.keys(jsonMetadata).length !== 0) {
return { uri: jsonMetadata.profile.cover_image }; return { uri: jsonMetadata.profile.profile_image };
} }
return DEFAULT_IMAGE; return DEFAULT_IMAGE;
}; };

View File

@ -57,7 +57,7 @@ export const Login = (username, password) => {
const jsonMetadata = JSON.parse(account.json_metadata); const jsonMetadata = JSON.parse(account.json_metadata);
if (Object.keys(jsonMetadata).length !== 0) { if (Object.keys(jsonMetadata).length !== 0) {
avatar = jsonMetadata.profile.cover_image; avatar = jsonMetadata.profile.profile_image;
} }
if (loginFlag) { if (loginFlag) {
const userData = { const userData = {
@ -97,7 +97,7 @@ export const loginWithSC2 = async (accessToken) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const jsonMetadata = JSON.parse(account.json_metadata); const jsonMetadata = JSON.parse(account.json_metadata);
if (Object.keys(jsonMetadata).length !== 0) { if (Object.keys(jsonMetadata).length !== 0) {
avatar = jsonMetadata.profile.cover_image; avatar = jsonMetadata.profile.profile_image;
} }
const userData = { const userData = {

View File

@ -78,7 +78,7 @@ export default class HomeScreen extends PureComponent {
const { componentId } = this.props; const { componentId } = this.props;
return ( return (
<Fragment> <Fragment>
<Header userName={user && user.name} reputation={user && user.reputation} /> <Header />
<View style={styles.root} key="overlay"> <View style={styles.root} key="overlay">
<ScrollableTabView <ScrollableTabView
style={styles.tabView} style={styles.tabView}

View File

@ -66,13 +66,7 @@ class ProfileScreen extends Component {
} }
return ( return (
<Fragment> <Fragment>
<Header <Header isReverse={isReverseHeader} />
name={name}
avatar={avatar}
isReverse={isReverseHeader}
userName={user && user.name}
reputation={user && user.reputation}
/>
<View style={styles.container}> <View style={styles.container}>
{!isReady ? ( {!isReady ? (
<ProfileSummaryPlaceHolder /> <ProfileSummaryPlaceHolder />

View File

@ -47,7 +47,7 @@ class SplashContainer extends Component {
}); });
} else { } else {
dispatch(activeApplication()); dispatch(activeApplication());
navigation.navigate(ROUTES.SCREENS.LOGIN); navigation.navigate(ROUTES.DRAWER.MAIN);
} }
}); });
}; };