Skip to content

Commit

Permalink
Add titlebar for story screen
Browse files Browse the repository at this point in the history
  • Loading branch information
race604 committed Sep 23, 2015
1 parent 0220d4c commit 330a9fe
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 17 deletions.
167 changes: 167 additions & 0 deletions DetailToolbar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
'use strict';

var React = require('react-native');
var {
AppRegistry,
PixelRatio,
StyleSheet,
Text,
View,
Image,
TouchableWithoutFeedback,
ToastAndroid,
} = React;

var SwitchAndroid = require('SwitchAndroid');
var ToolbarAndroid = require('ToolbarAndroid');

var API_STROY_EXTRA = 'http://news-at.zhihu.com/api/4/story-extra/';

var DetailToolbar = React.createClass({
getInitialState: function() {
return({
isLoading: true,
extra: null,
});
},
componentDidMount: function() {
this.fetchStroyExtra();
},
fetchStroyExtra: function() {
fetch(API_STROY_EXTRA + this.props.story.id)
.then((response) => response.json())
.catch((error) => {
this.setState({
isLoading: false,
extra: null,
});
})
.then((responseData) => {
this.setState({
isLoading: false,
extra: responseData,
});
})
.done();
},
_onPressBackButton: function() {
if (this.props.navigator) {
this.props.navigator.pop();
}
},
_onPressShareButton: function() {
// TODO:
ToastAndroid.show('分享', ToastAndroid.SHORT);
},
_onPressCollectButton: function() {
// TODO:
ToastAndroid.show('收藏', ToastAndroid.SHORT);
},
_onPressCommentButton: function() {
// TODO:
ToastAndroid.show('评论', ToastAndroid.SHORT);
},
_onPressPriseButton: function() {
// TODO:
ToastAndroid.show('赞', ToastAndroid.SHORT);
},
render: function() {
return(
<View {...this.props}>
<View style={styles.actionsContainer}>
<TouchableWithoutFeedback onPress={this._onPressBackButton}
style={styles.actionItem}>
<Image
style={styles.backIcon}
source={require('image!ic_back_white')}
resizeMode='contain' />
</TouchableWithoutFeedback>
<View style={{flex: 1}} />
<TouchableWithoutFeedback onPress={this._onPressShareButton}
style={styles.actionItem}>
<Image
style={styles.actionIcon}
source={require('image!ic_share_white')}
resizeMode='contain' />
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={this._onPressCollectButton}
style={styles.actionItem}>
<Image
style={styles.actionIcon}
source={require('image!ic_collect_white')}
resizeMode='contain' />
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={this._onPressCommentButton}
style={styles.actionItem}>
<View style={{flexDirection: 'row', alignItems: 'center'}}>
<Image
style={styles.actionIconWithCount}
source={require('image!ic_comment_white')}
resizeMode='contain' />
<Text style={styles.count}>
{this.state.isLoading ? '...' : this.state.extra.comments}
</Text>
</View>
</TouchableWithoutFeedback>
<TouchableWithoutFeedback onPress={this._onPressPraiseButton}
style={styles.actionItem}>
<View style={{flexDirection: 'row', alignItems: 'center', marginRight: 16}}>
<Image
style={styles.actionIconWithCount}
source={require('image!ic_praise_white')}
resizeMode='contain' />
<Text style={styles.count}>
{this.state.isLoading ? '...' : this.state.extra.popularity}
</Text>
</View>
</TouchableWithoutFeedback>
</View>

</View>
// <ToolbarAndroid
// navIcon={require('image!ic_back_white')}
// onIconClicked={this.props.navigator.pop}
// titleColor="white"
// actions={[]} >
// </ToolbarAndroid>
);
},

});

var styles = StyleSheet.create({
actionsContainer: {
height: 56,
flexDirection: 'row',
alignItems: 'center',
},
backIcon: {
width: 32,
height: 32,
marginLeft: 16,
marginRight: 16,
},
actionItem: {
height: 56,
alignItems: 'center',

},
actionIcon: {
width: 32,
height: 32,
marginLeft: 5,
marginRight: 5,
},
actionIconWithCount: {
width: 32,
height: 32,
marginLeft: 5,
},
count: {
fontSize: 16,
color: 'white',
marginRight: 5,
},
});

module.exports = DetailToolbar;
3 changes: 0 additions & 3 deletions ListScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ var ListScreen = React.createClass({
render: function() {
var content = this.state.dataSource.getRowCount() === 0 ?
<View style={styles.container}>
<Text>
This is the list Screen.
</Text>
</View> :
<ListView
ref="listview"
Expand Down
26 changes: 24 additions & 2 deletions StoryScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ var {
Text,
View,
Image,
ToolbarAndroid,
TouchableHighlight,
} = React;

var precomputeStyle = require('precomputeStyle');

var MyWebView = require('./WebView');
var DetailToolbar = require('./DetailToolbar');

var BASE_URL = 'http://news.at.zhihu.com/api/4/news/';
var REF_HEADER = 'header';
Expand Down Expand Up @@ -58,13 +61,15 @@ var StoryScreen = React.createClass({
this.refs[REF_HEADER].setNativeProps(nativeProps);
},
render: function() {
var url = BASE_URL + this.props.story.id;
var toolbar = <DetailToolbar navigator={this.props.navigator} style={styles.toolbar}
story={this.props.story}/>;
if (this.state.isLoading) {
return (
<View style={[styles.container, styles.center]}>
<Text>
正在加载...
</Text>
{toolbar}
</View>
);
} else {
Expand All @@ -74,6 +79,7 @@ var StoryScreen = React.createClass({
// flexDirection: 'row',
// transform: [{translateY: this.state.scrollY}],
// };
var toolbar
return (
<View style={styles.container}>
<MyWebView
Expand All @@ -91,6 +97,7 @@ var StoryScreen = React.createClass({
</Text>
</View>
</Image>
{toolbar}
</View>
);
} else {
Expand All @@ -99,6 +106,7 @@ var StoryScreen = React.createClass({
<Text>
加载失败
</Text>
{toolbar}
</View>
);
}
Expand All @@ -108,10 +116,24 @@ var StoryScreen = React.createClass({
});

var styles = StyleSheet.create({
toolbar: {
backgroundColor: '#00a2ed',
height: 56,
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
top: 0,
},
headerImage: {
height: 200,
flexDirection: 'row',
backgroundColor: '#DDDDDD',
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
top: 56,
},
titleContainer: {
flex: 1,
Expand Down Expand Up @@ -139,7 +161,7 @@ var styles = StyleSheet.create({
left: 0,
right: 0,
bottom: 0,
top:0,
top:56,
},
});

Expand Down
Binary file modified android/.gradle/2.4/taskArtifacts/cache.properties.lock
Binary file not shown.
Binary file modified android/.gradle/2.4/taskArtifacts/fileHashes.bin
Binary file not shown.
Binary file modified android/.gradle/2.4/taskArtifacts/fileSnapshots.bin
Binary file not shown.
Binary file modified android/.gradle/2.4/taskArtifacts/taskArtifacts.bin
Binary file not shown.
11 changes: 5 additions & 6 deletions android/.idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 0 additions & 6 deletions index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,6 @@ var RouteMapper = function(route, navigationOperations, onComponentRef) {
} else if (route.name === 'story') {
return (
<View style={styles.container}>
<ToolbarAndroid
navIcon={require('image!ic_back_white')}
onIconClicked={navigationOperations.pop}
titleColor="white"
style={styles.toolbar}
actions={[]}/>
<StoryScreen
style={{flex: 1}}
navigator={navigationOperations}
Expand Down

0 comments on commit 330a9fe

Please sign in to comment.