Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit e2f0de1

Browse files
committed
finished moving to stateless functional components
1 parent c991ddd commit e2f0de1

File tree

6 files changed

+40
-57
lines changed

6 files changed

+40
-57
lines changed

components/NavButton.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import React from 'react-native'
33
const { Platform, TouchableOpacity, View, PropTypes } = React
44
import styles from '../styles'
55

6-
function NavButton(props: Object): React.Element {
6+
function NavButton({ style, onPress, children }: Object): React.Element {
77
const getNavBarButtonStyles = (): Array<Object> => {
8-
const { style } = props
98
if (Platform.OS === 'ios') {
109
return [
1110
styles.navBarButtonIOS,
@@ -20,18 +19,15 @@ function NavButton(props: Object): React.Element {
2019
return []
2120
}
2221

23-
const getTouchable = (): React.Element => {
24-
const { onPress, children } = props
25-
return (
26-
<TouchableOpacity onPress={onPress}>
27-
<View style={getNavBarButtonStyles}>
28-
{children}
29-
</View>
30-
</TouchableOpacity>
31-
)
32-
}
22+
const getTouchable = () => (
23+
<TouchableOpacity onPress={onPress}>
24+
<View style={getNavBarButtonStyles()}>
25+
{children}
26+
</View>
27+
</TouchableOpacity>
28+
)
3329

34-
return getTouchable
30+
return getTouchable()
3531
}
3632

3733
NavButton.propTypes = {

components/NavButtonText.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import React from 'react-native'
33
const { Text, PropTypes } = React
44
import styles from '../styles'
55

6-
function NavButtonText(props: Object): React.Element {
7-
const { style, children } = props
6+
function NavButtonText({ style, children }: Object): React.Element {
87
return (
98
<Text style={[styles.navBarButtonText, style]}>
109
{children}

components/NavGroup.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import React from 'react-native'
33
const { View, PropTypes } = React
44
import styles from '../styles'
55

6-
function NavGroup(props: Object): React.Element {
7-
const { style, children } = props
6+
function NavGroup({ style, children }: Object): React.Element {
87
return (
98
<View style={[styles.navGroup, style]}>
109
{children}

components/NavTitle.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import React from 'react-native'
33
const { Text, PropTypes } = React
44
import styles from '../styles'
55

6-
function NavTitle(props: Object): React.Element {
7-
const { style, children } = props
6+
function NavTitle({ style, children }: Object): React.Element {
87
return (
98
<Text style={[styles.navBarTitleText, style]}>
109
{children}

components/StatusBarEnhanced.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ import React from 'react-native'
33
const { Platform, View, PropTypes, StatusBar } = React
44
import styles from '../styles'
55

6-
function StatusBarEnhanced(props: Object): React.Element {
6+
function StatusBarEnhanced({ statusBar, style }: Object): React.Element {
77
const getConfig = (): Object => {
8-
const { statusBar } = this.props
98
if (Platform.OS === 'ios') {
109
const statusBarConfig = {
1110
animated: true,
@@ -25,11 +24,10 @@ function StatusBarEnhanced(props: Object): React.Element {
2524
}
2625
return Object.assign({}, statusBarConfig, statusBar)
2726
}
28-
return null
27+
return {}
2928
}
3029

31-
const getStyles = (): Array => {
32-
const { style } = this.props
30+
const getStyles = (): Array<Object> => {
3331
if (Platform.OS === 'ios') {
3432
return [
3533
styles.statusBarIOS,
@@ -41,24 +39,22 @@ function StatusBarEnhanced(props: Object): React.Element {
4139
style,
4240
]
4341
}
44-
return null
42+
return [{}]
4543
}
4644

4745
return (
48-
<View style={getStyles}>
49-
<StatusBar {...getConfig} />
46+
<View style={getStyles()}>
47+
<StatusBar {...getConfig()} />
5048
</View>
5149
)
5250
}
5351

5452
StatusBarEnhanced.propTypes = {
55-
statusBarTintColor: PropTypes.string,
5653
statusBar: PropTypes.object,
5754
style: View.propTypes.style,
5855
}
5956

6057
StatusBarEnhanced.defaultProps = {
61-
statusBarTintColor: '#fff',
6258
style: {},
6359
statusBar: {},
6460
}

index.js

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,19 @@
11
/* @flow */
22
import React from 'react-native'
33
const {
4-
Component,
54
View,
65
PropTypes,
76
Platform,
87
} = React
9-
import StatusBarEnhanced from './components/StatusBarEnhanced'
8+
import { StatusBarEnhanced } from './components/StatusBarEnhanced'
109
export { NavGroup } from './components/NavGroup'
1110
export { NavButton } from './components/NavButton'
1211
export { NavButtonText } from './components/NavButtonText'
1312
export { NavTitle } from './components/NavTitle'
1413
import styles from './styles'
1514

16-
class NavigationBar extends Component {
17-
18-
static propTypes = {
19-
statusBar: PropTypes.object,
20-
style: PropTypes.object,
21-
children: PropTypes.node,
22-
}
23-
24-
static defaultProps = {
25-
style: {},
26-
statusBar: {},
27-
}
28-
29-
getNavBar(): React.Element {
30-
const { style, children } = this.props
15+
function NavigationBar({ style, children, statusBar }: Object): React.Element {
16+
const getNavBar = (): React.Element => {
3117
if (Platform.OS === 'ios') {
3218
return (
3319
<View style={[styles.navBar, styles.navBarIOS, style.navBar]}>
@@ -44,17 +30,25 @@ class NavigationBar extends Component {
4430
return null
4531
}
4632

47-
render(): React.Element {
48-
const { style, statusBar } = this.props
49-
return (
50-
<View style={[styles.navBarContainer, style.navBarContainer]}>
51-
<StatusBarEnhanced style={style.statusBar}
52-
statusBar={statusBar}
53-
/>
54-
{this.getNavBar()}
55-
</View>
56-
)
57-
}
33+
return (
34+
<View style={[styles.navBarContainer, style.navBarContainer]}>
35+
<StatusBarEnhanced style={style.statusBar}
36+
statusBar={statusBar}
37+
/>
38+
{getNavBar()}
39+
</View>
40+
)
41+
}
42+
43+
NavigationBar.propTypes = {
44+
statusBar: PropTypes.object,
45+
style: PropTypes.object,
46+
children: PropTypes.node,
47+
}
48+
49+
NavigationBar.defaultProps = {
50+
style: {},
51+
statusBar: {},
5852
}
5953

6054
export default NavigationBar

0 commit comments

Comments
 (0)