Skip to content

Commit 6fa8162

Browse files
committed
Append a loader and refactor render into Example screen
1 parent 866e8ad commit 6fa8162

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

App/Containers/Example/ExampleScreen.js

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { Platform, Text, View, Button } from 'react-native'
2+
import { Platform, Text, View, Button, ActivityIndicator } from 'react-native'
33
import { connect } from 'react-redux'
44
import { PropTypes } from 'prop-types'
55
import ExampleActions from 'App/Stores/Example/Actions'
@@ -24,39 +24,42 @@ class ExampleScreen extends React.Component {
2424
}
2525

2626
render() {
27-
let isLoading = this.props.userIsLoading ? 'Data are loading...' : ''
28-
let user = this.props.user
29-
let error = this.props.userErrorMessage
30-
let result = null
31-
if (user && !error) {
32-
result =
33-
"I'm a fake user, my name is " +
34-
user.name +
35-
'.\n' +
36-
(this.props.liveInEurope ? 'I live in Europe !' : "I don't live in Europe.")
37-
}
38-
3927
return (
4028
<View style={Style.container}>
41-
<Text style={Style.title}>TheCodingMachine boilerplate</Text>
42-
<Text style={Style.text}>To get started, edit App.js</Text>
43-
<Text style={Style.instructions}>{instructions}</Text>
44-
<Text style={Style.loading}>{isLoading}</Text>
45-
{user && !error ? (
46-
<Text style={Style.result}>{result}</Text>
29+
{this.props.userIsLoading ? (
30+
<ActivityIndicator size="large" color="#0000ff" />
4731
) : (
48-
<Text style={Style.error}>{error}</Text>
32+
<View>
33+
<Text style={Style.title}>TheCodingMachine boilerplate</Text>
34+
<Text style={Style.text}>To get started, edit App.js</Text>
35+
<Text style={Style.instructions}>{instructions}</Text>
36+
{this.props.userErrorMessage ? (
37+
<Text style={Style.error}>{this.props.userErrorMessage}</Text>
38+
) : (
39+
<View>
40+
<Text style={Style.result}>
41+
{"I'm a fake user, my name is "}
42+
{this.props.user.name}
43+
</Text>
44+
<Text style={Style.result}>
45+
{this.props.liveInEurope ? 'I live in Europe !' : "I don't live in Europe."}
46+
</Text>
47+
</View>
48+
)}
49+
<Button onPress={this.props.fetchUser} title="Refresh" />
50+
</View>
4951
)}
50-
<Button onPress={this.props.fetchUser} title="Refresh" />
5152
</View>
5253
)
5354
}
5455
}
5556

56-
ExampleScreen.propsTypes = {
57-
user: PropTypes.number,
57+
ExampleScreen.propTypes = {
58+
user: PropTypes.object,
5859
userIsLoading: PropTypes.bool,
5960
userErrorMessage: PropTypes.string,
61+
fetchUser: PropTypes.func,
62+
liveInEurope: PropTypes.bool,
6063
}
6164

6265
const mapStateToProps = (state) => ({

0 commit comments

Comments
 (0)