forked from race604/ZhiHuDaily-React-Native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
167 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
var React = require('react-native'); | ||
var { | ||
AsyncStorage, | ||
Image, | ||
StyleSheet, | ||
Text, | ||
View, | ||
} = React; | ||
|
||
var ListScreen = React.createClass({ | ||
render: function() { | ||
return ( | ||
<View style={styles.container}> | ||
<Text> | ||
This is the list Screen. | ||
</Text> | ||
</View> | ||
); | ||
} | ||
}); | ||
|
||
var styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
}); | ||
|
||
module.exports = ListScreen; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
'use strict'; | ||
|
||
var React = require('react-native'); | ||
var { | ||
AsyncStorage, | ||
Image, | ||
StyleSheet, | ||
Text, | ||
View, | ||
} = React; | ||
|
||
var REQUEST_URL = "http://news-at.zhihu.com/api/4/start-image/1080*1776"; | ||
|
||
var COVER_KEY = '@WelcomeScreen:cover'; | ||
|
||
var WelcomeScreen = React.createClass({ | ||
fetchData: function() { | ||
fetch(REQUEST_URL) | ||
.then((response) => response.json()) | ||
.then((responseData) => { | ||
//console.log(responseData); | ||
this.setState({cover: responseData}); | ||
//this._onCoverLoaded(responseData); | ||
}) | ||
.done(); | ||
}, | ||
async _onCoverLoaded(value) { | ||
try { | ||
await AsyncStorage.setItem(COVER_KEY, value); | ||
} catch (error) { | ||
console.log(error); | ||
} | ||
}, | ||
componentDidMount: function() { | ||
this.fetchData(); | ||
//this._loadInitialState().done(); | ||
}, | ||
async _loadInitialState() { | ||
try { | ||
var value = await AsyncStorage.getItem(COVER_KEY); | ||
if (value !== null){ | ||
this.setState({cover: value}); | ||
} | ||
} catch (error) { | ||
} | ||
}, | ||
getInitialState: function() { | ||
return { | ||
cover: null, | ||
}; | ||
}, | ||
renderEmpty: function() { | ||
return( | ||
<View style={styles.container}> | ||
<Text style={styles.title}> | ||
知乎日报 | ||
</Text> | ||
</View> | ||
); | ||
}, | ||
render: function() { | ||
if (!this.state.cover) { | ||
return this.renderEmpty(); | ||
} | ||
|
||
return( | ||
<Image | ||
source={{uri: this.state.cover.img}} | ||
style={styles.cover}> | ||
<Text style={styles.text}> | ||
{this.state.cover.text} | ||
</Text> | ||
</Image> | ||
); | ||
} | ||
}); | ||
|
||
var styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
cover: { | ||
flex: 1, | ||
flexDirection: 'row', | ||
backgroundColor: '#F5FCFF', | ||
}, | ||
title: { | ||
fontSize: 32, | ||
fontWeight: '500', | ||
}, | ||
text: { | ||
flex: 1, | ||
fontSize: 16, | ||
alignSelf: 'flex-end', | ||
textAlign: 'center', | ||
marginBottom: 10, | ||
} | ||
}); | ||
|
||
module.exports = WelcomeScreen; |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters