Fixes settings item menu in footer missing active state
This commit is contained in:
+25
-21
@@ -20,10 +20,6 @@ const headerTitlesLowerCase = Object.keys(headerTitles).reduce((acc, curr) => {
|
|||||||
acc[curr] = headerTitles[curr].toLowerCase()
|
acc[curr] = headerTitles[curr].toLowerCase()
|
||||||
return acc
|
return acc
|
||||||
}, {})
|
}, {})
|
||||||
const menuTitlesLowerCase = Object.keys(menuTitles).reduce((acc, curr) => {
|
|
||||||
acc[curr] = menuTitles[curr].toLowerCase()
|
|
||||||
return acc
|
|
||||||
}, {})
|
|
||||||
|
|
||||||
const isSymptomView = name => Object.keys(symptomViews).includes(name)
|
const isSymptomView = name => Object.keys(symptomViews).includes(name)
|
||||||
const isSettingsView = name => Object.keys(settingsViews).includes(name)
|
const isSettingsView = name => Object.keys(settingsViews).includes(name)
|
||||||
@@ -87,47 +83,55 @@ export default class App extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const page = {
|
const { currentPage, currentProps } = this.state
|
||||||
Home, Calendar, CycleDay, Chart, InfoSymptom,
|
const pages = {
|
||||||
SettingsMenu, ...settingsViews, Stats, ...symptomViews
|
Home,
|
||||||
}[this.state.currentPage]
|
Calendar,
|
||||||
|
CycleDay,
|
||||||
|
Chart,
|
||||||
|
InfoSymptom,
|
||||||
|
SettingsMenu,
|
||||||
|
...settingsViews,
|
||||||
|
Stats,
|
||||||
|
...symptomViews
|
||||||
|
}
|
||||||
|
const page = pages[currentPage]
|
||||||
return (
|
return (
|
||||||
<View style={{flex: 1}}>
|
<View style={{flex: 1}}>
|
||||||
{this.isDefaultView() &&
|
{this.isDefaultView() &&
|
||||||
<Header
|
<Header
|
||||||
title={headerTitlesLowerCase[this.state.currentPage]}
|
title={headerTitlesLowerCase[currentPage]}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
{this.state.currentPage === 'InfoSymptom' &&
|
{currentPage === 'InfoSymptom' &&
|
||||||
<Header
|
<Header
|
||||||
title={headerTitlesLowerCase[this.state.currentPage]}
|
title={headerTitlesLowerCase[currentPage]}
|
||||||
goBack={this.handleBackButtonPress}
|
goBack={this.handleBackButtonPress}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
{isSymptomView(this.state.currentPage) &&
|
{isSymptomView(currentPage) &&
|
||||||
<Header
|
<Header
|
||||||
title={headerTitlesLowerCase[this.state.currentPage]}
|
title={headerTitlesLowerCase[currentPage]}
|
||||||
isSymptomView={true}
|
isSymptomView={true}
|
||||||
goBack={this.handleBackButtonPress}
|
goBack={this.handleBackButtonPress}
|
||||||
date={this.state.currentProps.date}
|
date={currentProps.date}
|
||||||
goToSymptomInfo={() => this.navigate('InfoSymptom', {
|
goToSymptomInfo={() => this.navigate('InfoSymptom', {
|
||||||
date: this.state.currentProps.date,
|
date: currentProps.date,
|
||||||
symptomView: this.state.currentPage,
|
symptomView: currentPage,
|
||||||
cycleDay: this.state.currentProps.cycleDay
|
cycleDay: currentProps.cycleDay
|
||||||
})}
|
})}
|
||||||
/>}
|
/>}
|
||||||
|
|
||||||
|
|
||||||
{React.createElement(page, {
|
{React.createElement(page, {
|
||||||
navigate: this.navigate,
|
navigate: this.navigate,
|
||||||
...this.state.currentProps
|
...currentProps
|
||||||
})}
|
})}
|
||||||
|
|
||||||
{!isSymptomView(this.state.currentPage) &&
|
{!isSymptomView(currentPage) &&
|
||||||
<Menu
|
<Menu
|
||||||
navigate={this.navigate}
|
navigate={this.navigate}
|
||||||
titles={menuTitlesLowerCase}
|
currentPage={currentPage}
|
||||||
currentPage={this.state.currentPage}
|
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
+56
-23
@@ -1,46 +1,79 @@
|
|||||||
import React, { Component } from 'react'
|
import React from 'react'
|
||||||
import {
|
import {
|
||||||
View,
|
View,
|
||||||
Text,
|
Text,
|
||||||
TouchableOpacity
|
TouchableOpacity
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
|
|
||||||
|
import { menuTitles } from '../i18n/en/labels'
|
||||||
|
|
||||||
import styles, { iconStyles, secondaryColor } from '../styles'
|
import styles, { iconStyles, secondaryColor } from '../styles'
|
||||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
||||||
|
|
||||||
export default class Menu extends Component {
|
const menuTitlesLowerCase = Object.keys(menuTitles).reduce((acc, curr) => {
|
||||||
makeMenuItem = ({ title, icon, onPress}, i) => {
|
acc[curr] = menuTitles[curr].toLowerCase()
|
||||||
const styleActive = (this.props.currentPage.toLowerCase() === title) ?
|
return acc
|
||||||
{color: secondaryColor} : {}
|
}, {})
|
||||||
|
|
||||||
|
const menuItems = [
|
||||||
|
{
|
||||||
|
labelKey: 'Home',
|
||||||
|
icon: 'home',
|
||||||
|
component: 'Home'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
labelKey: 'Calendar',
|
||||||
|
icon: 'calendar-range',
|
||||||
|
component: 'Calendar',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
labelKey: 'Chart',
|
||||||
|
icon: 'chart-line',
|
||||||
|
component: 'Chart'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
labelKey: 'Stats',
|
||||||
|
icon: 'chart-pie',
|
||||||
|
component: 'Stats',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
labelKey: 'Settings',
|
||||||
|
icon: 'settings',
|
||||||
|
component: 'SettingsMenu',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const MenuItem = ({ icon, labelKey, active, onPress }) => {
|
||||||
|
const styleActive = active ? { color: secondaryColor } : null
|
||||||
return (
|
return (
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
onPress={onPress}
|
|
||||||
style={styles.menuItem}
|
style={styles.menuItem}
|
||||||
key={i.toString()}
|
onPress={onPress}
|
||||||
>
|
>
|
||||||
<Icon name={icon} {...iconStyles.menuIcon} {...styleActive} />
|
<Icon name={icon} {...iconStyles.menuIcon} {...styleActive} />
|
||||||
<Text style={[styles.menuText, styleActive]}>
|
<Text style={[styles.menuText, styleActive]}>
|
||||||
{title}
|
{menuTitlesLowerCase[labelKey]}
|
||||||
</Text>
|
</Text>
|
||||||
</TouchableOpacity>
|
</TouchableOpacity>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
goTo(componentName) {
|
const Menu = ({ currentPage, navigate }) => {
|
||||||
this.props.navigate(componentName)
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
|
||||||
const t = this.props.titles
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.menu}>
|
<View style={styles.menu}>
|
||||||
{[
|
{ menuItems.map(({ icon, labelKey, component }) => {
|
||||||
{ title: t.Home, icon: 'home', onPress: () => this.goTo('Home') },
|
return (
|
||||||
{ title: t.Calendar, icon: 'calendar-range', onPress: () => this.goTo('Calendar') },
|
<MenuItem
|
||||||
{ title: t.Chart, icon: 'chart-line', onPress: () => this.goTo('Chart') },
|
key={labelKey}
|
||||||
{ title: t.Stats, icon: 'chart-pie', onPress: () => this.goTo('Stats') },
|
labelKey={labelKey}
|
||||||
{ title: t.Settings, icon: 'settings', onPress: () => this.goTo('SettingsMenu') },
|
icon={icon}
|
||||||
].map(this.makeMenuItem)}
|
active={component === currentPage}
|
||||||
|
onPress={() => navigate(component)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
)}
|
||||||
</View >
|
</View >
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default Menu
|
||||||
Reference in New Issue
Block a user