Skip to content
This repository was archived by the owner on Mar 9, 2022. It is now read-only.

Commit b71f472

Browse files
Code Improvements & prop-types module installed
1 parent 870e770 commit b71f472

File tree

10 files changed

+151
-132
lines changed

10 files changed

+151
-132
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@expo/vector-icons": "^9.0.0",
1111
"expo": "^32.0.0",
1212
"native-base": "^2.10.0",
13+
"prop-types": "^15.7.2",
1314
"react": "^16.5.0",
1415
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz"
1516
},

src/App.js

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import React, { Component } from 'react';
22
import { registerRootComponent, AppLoading, Font } from 'expo';
33
import { StatusBar, StyleSheet } from 'react-native';
44
import { Container, Text, View } from 'native-base';
5-
import { Navbar, Pages } from './components/shared/navbar';
6-
import Home from './components/home/home';
7-
import Contributors from './components/contributors/contributors';
8-
import FAQ from './components/faq/faq';
5+
import Navbar from './components/shared/navbar';
6+
import Home from './components/home';
7+
import Contributors from './components/contributors';
8+
import FAQ from './components/faq';
9+
import Pages from './constants/pages';
910

1011
const styles = StyleSheet.create({
1112
container: {
@@ -18,6 +19,23 @@ const styles = StyleSheet.create({
1819
},
1920
});
2021

22+
function RenderPage(page) {
23+
switch (page) {
24+
case Pages.HOME:
25+
return <Home />;
26+
case Pages.CONTRIBUTORS:
27+
return <Contributors />;
28+
case Pages.FAQ:
29+
return <FAQ />;
30+
default:
31+
return (
32+
<Text>
33+
Error in RenderPage in App.js - An invalid page was attempting to be loaded
34+
</Text>
35+
);
36+
}
37+
}
38+
2139
export class App extends Component {
2240
constructor() {
2341
super();
@@ -41,7 +59,9 @@ export class App extends Component {
4159
}
4260

4361
render() {
44-
if (!this.state.fontsLoaded) {
62+
const { fontsLoaded, page } = this.state;
63+
64+
if (!fontsLoaded) {
4565
return <AppLoading />;
4666
}
4767
return (
@@ -53,32 +73,15 @@ export class App extends Component {
5373
) : (null)}
5474

5575
<View style={styles.content}>
56-
{this.RenderPage()}
76+
{RenderPage(page)}
5777
</View>
5878

59-
<Navbar callback={this.NavbarCallback} />
79+
<Navbar onButtonPress={this.NavbarCallback} currentPage={page} />
6080

6181
</Container >
6282
);
6383
}
6484

65-
RenderPage() {
66-
switch (this.state.page) {
67-
case Pages.HOME:
68-
return <Home />;
69-
case Pages.CONTRIBUTORS:
70-
return <Contributors />;
71-
case Pages.FAQ:
72-
return <FAQ />;
73-
default:
74-
return (
75-
<Text>
76-
Error in RenderPage in App.js - An invalid page was attempting to be loaded
77-
</Text>
78-
);
79-
}
80-
}
81-
8285
NavbarCallback(selectedPage) {
8386
this.setState({ page: selectedPage });
8487
}
File renamed without changes.

src/components/shared/navbar.js

Lines changed: 0 additions & 106 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { StyleSheet } from 'react-native';
4+
import { Footer } from 'native-base';
5+
import NavbarButton from './navbarButton';
6+
import Pages from '../../../constants/pages';
7+
8+
const iconImage = require('../../../../assets/icon.png');
9+
10+
const styles = StyleSheet.create({
11+
footer: {
12+
backgroundColor: '#fff',
13+
width: '100%',
14+
alignItems: 'center',
15+
justifyContent: 'center',
16+
height: 56,
17+
},
18+
});
19+
20+
export default function Navbar(props) {
21+
const { onButtonPress, currentPage } = props;
22+
return (
23+
<Footer style={styles.footer}>
24+
25+
<NavbarButton
26+
onButtonPress={onButtonPress}
27+
iconImage={iconImage}
28+
page={Pages.HOME}
29+
currentPage={currentPage}
30+
text="Home"
31+
/>
32+
33+
<NavbarButton
34+
onButtonPress={onButtonPress}
35+
iconImage={iconImage}
36+
page={Pages.CONTRIBUTORS}
37+
currentPage={currentPage}
38+
text="Contributors"
39+
/>
40+
41+
<NavbarButton
42+
onButtonPress={onButtonPress}
43+
iconImage={iconImage}
44+
page={Pages.FAQ}
45+
currentPage={currentPage}
46+
text="FAQ"
47+
/>
48+
49+
</Footer>
50+
);
51+
}
52+
53+
Navbar.propTypes = {
54+
onButtonPress: PropTypes.func.isRequired,
55+
currentPage: PropTypes.oneOf(Object.values(Pages)).isRequired,
56+
};
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
import { StyleSheet, Image, TouchableHighlight } from 'react-native';
4+
import { Text, View } from 'native-base';
5+
import Pages from '../../../constants/pages';
6+
7+
const styles = StyleSheet.create({
8+
navButton: {
9+
flex: 1,
10+
alignItems: 'center',
11+
justifyContent: 'center',
12+
},
13+
navButtonActiveText: {
14+
color: '#0098E8',
15+
},
16+
navButtonInactiveText: {
17+
color: '#000',
18+
},
19+
navImage: {
20+
width: 20,
21+
height: 20,
22+
}
23+
});
24+
25+
function handleButtonPress(selectedPage, onButtonPress) {
26+
onButtonPress(selectedPage);
27+
}
28+
29+
export default function NavbarButton(props) {
30+
const {
31+
onButtonPress,
32+
iconImage,
33+
page,
34+
currentPage,
35+
text
36+
} = props;
37+
38+
return (
39+
<TouchableHighlight style={styles.navButton} underlayColor='#eee' onPress={() => { handleButtonPress(page, onButtonPress); }}>
40+
<View style={styles.navButton}>
41+
42+
<Image style={styles.navImage} source={iconImage} />
43+
<Text style={
44+
(currentPage === page) ? (styles.navButtonActiveText) : (styles.navButtonInactiveText)
45+
}>
46+
{text}
47+
</Text>
48+
49+
</View>
50+
</TouchableHighlight >
51+
);
52+
}
53+
54+
NavbarButton.propTypes = {
55+
onButtonPress: PropTypes.func.isRequired,
56+
iconImage: PropTypes.number.isRequired,
57+
page: PropTypes.oneOf(Object.values(Pages)).isRequired,
58+
currentPage: PropTypes.oneOf(Object.values(Pages)).isRequired,
59+
text: PropTypes.string.isRequired
60+
};

src/constants/pages.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
HOME: 0,
3+
CONTRIBUTORS: 1,
4+
FAQ: 2,
5+
};

yarn.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4961,7 +4961,7 @@ promise@^7.1.1:
49614961
dependencies:
49624962
asap "~2.0.3"
49634963

4964-
prop-types@^15.5.10, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2:
4964+
prop-types@^15.5.10, prop-types@^15.5.8, prop-types@^15.6.0, prop-types@^15.6.1, prop-types@^15.6.2, prop-types@^15.7.2:
49654965
version "15.7.2"
49664966
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.7.2.tgz#52c41e75b8c87e72b9d9360e0206b99dcbffa6c5"
49674967
integrity sha512-8QQikdH7//R2vurIJSutZ1smHYTcLpRWEOlHnzcWHmBYrOGUysKwSsrC89BCiFj3CbrfJ/nXFdJepOVrY1GCHQ==
@@ -5081,7 +5081,7 @@ react-native-keyboard-aware-scroll-view@0.8.0:
50815081
prop-types "^15.6.2"
50825082
react-native-iphone-x-helper "^1.0.3"
50835083

5084-
"react-native-maps@github:expo/react-native-maps#v0.22.1-exp.0":
5084+
react-native-maps@expo/react-native-maps#v0.22.1-exp.0:
50855085
version "0.22.1"
50865086
resolved "https://codeload.github.com/expo/react-native-maps/tar.gz/e6f98ff7272e5d0a7fe974a41f28593af2d77bb2"
50875087

0 commit comments

Comments
 (0)