Newer
Older
import { View, BackHandler } from 'react-native'
import { connect } from 'react-redux'
import { getDate } from '../slices/date'
import { getNavigation, navigate, goBack } from '../slices/navigation'
import Header from './header'
import Menu from './menu'
import { viewsList } from './views'
import { isSymptomView, isSettingsView } from './pages'
import { headerTitles } from '../i18n/en/labels'
import setupNotifications from '../lib/notifications'
class App extends Component {
static propTypes = {
date: PropTypes.string,
navigation: PropTypes.object.isRequired,
navigate: PropTypes.func,
goBack: PropTypes.func,
this.backHandler = BackHandler.addEventListener(
'hardwareBackPress',
)
setupNotifications(this.props.navigate)
}
componentWillUnmount() {
this.backHandler.remove()
render() {
const { date, navigation, goBack } = this.props
const { currentPage } = navigation
const Page = viewsList[currentPage]
const isSymptomEditView = isSymptomView(currentPage)
const isSettingsSubView = isSettingsView(currentPage)
const isCycleDayView = currentPage === 'CycleDay'
const headerProps = {
title,
handleBack: isSettingsSubView ? goBack : null,
}
const pageProps = {
cycleDay: date && getCycleDay(date),
{
!isSymptomEditView &&
!isCycleDayView &&
<Header { ...headerProps } />
const mapStateToProps = (state) => {
return({
date: getDate(state),
navigation: getNavigation(state)
})
}
const mapDispatchToProps = (dispatch) => {
return({
navigate: (page) => dispatch(navigate(page)),
})
}
export default connect(
mapStateToProps,