-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
93 lines (77 loc) · 2.41 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import React from 'react';
import { ScrollView, StyleSheet, View } from 'react-native';
import { Provider } from 'react-redux';
import { fetchProducts } from './redux/actions/products';
import { navigateToScreen } from './redux/actions/ui';
import store from './redux/store';
import StickyFooter from './StickyFooter';
import DirectvNow from './screens/DirectvNow/DirectvNow';
import MainHeader from './components/MainHeader';
import globals from './globals';
import PageNotFound from './screens/404';
import Loading from './screens/Loading';
import CartAndCheckout from './screens/cartAndChackout/CartAndCheckout';
export default class App extends React.Component {
constructor(props) {
super(props);
this.scroll = React.createRef();
this.onStickyFooterCtaPress = this.onStickyFooterCtaPress.bind(this);
}
state = {
currentScreen: globals.screens.LOADING
};
componentDidMount() {
store.dispatch(fetchProducts());
store.subscribe(() => {
this.setState({
currentScreen: store.getState().ui.currentScreen
});
});
}
componentDidUpdate() {
this.scroll.scrollTo({x: 0, y: 0, animated: false});
}
onStickyFooterCtaPress() {
store.dispatch(navigateToScreen(globals.screens.CART_AND_CHECKOUT));
}
shouldComponentUpdate(nextProps, nextState) {
return nextState.currentScreen !== this.state.currentScreen;
}
render() {
let mainContent;
if (this.state.currentScreen === globals.screens.LOADING) {
mainContent = <Loading/>;
}
else if (this.state.currentScreen === globals.screens.DIRECTV_NOW) {
mainContent = <DirectvNow/>;
}
else if (this.state.currentScreen === globals.screens.CART_AND_CHECKOUT) {
mainContent = <CartAndCheckout/>;
}
else {
mainContent = <PageNotFound/>;
}
return (
<Provider store={store}>
<View style={styles.container}>
<ScrollView ref={scroll => this.scroll = scroll}>
<MainHeader/>
<View style={styles.mainContentContainer}>
{mainContent}
</View>
</ScrollView>
<StickyFooter onCtaPress={this.onStickyFooterCtaPress} buttonText={`Let's do this!`}/>
</View>
</Provider>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#eee'
},
mainContentContainer: {
flex: 1
}
});