Skip to content

Commit

Permalink
Finish detail content scroll
Browse files Browse the repository at this point in the history
  • Loading branch information
race604 committed Sep 22, 2015
1 parent 5ccaa94 commit 0220d4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 16 additions & 1 deletion StoryScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,27 @@
var React = require('react-native');
var {
AppRegistry,
PixelRatio,
StyleSheet,
Text,
View,
Image,
} = React;

var precomputeStyle = require('precomputeStyle');

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

var BASE_URL = 'http://news.at.zhihu.com/api/4/news/';
var REF_HEADER = 'header';
var PIXELRATIO = PixelRatio.get();

var StoryScreen = React.createClass({
getInitialState: function() {
return({
isLoading: false,
detail: null,
scrollY: 0,
});
},
componentDidMount: function() {
Expand Down Expand Up @@ -46,7 +52,10 @@ var StoryScreen = React.createClass({
.done();
},
onWebViewScroll: function(event) {
console.log('GotEvent' + event);
//console.log('ScrollY: ' + event);
var scrollY = -event / PIXELRATIO;
var nativeProps = precomputeStyle({transform: [{translateY: scrollY}]});
this.refs[REF_HEADER].setNativeProps(nativeProps);
},
render: function() {
var url = BASE_URL + this.props.story.id;
Expand All @@ -60,6 +69,11 @@ var StoryScreen = React.createClass({
);
} else {
if (this.state.detail) {
// var headerStyle = {
// height: 200,
// flexDirection: 'row',
// transform: [{translateY: this.state.scrollY}],
// };
return (
<View style={styles.container}>
<MyWebView
Expand All @@ -68,6 +82,7 @@ var StoryScreen = React.createClass({
css={this.state.detail.css[0]}
onScrollChange={this.onWebViewScroll}/>
<Image
ref={REF_HEADER}
source={{uri: this.state.detail.image}}
style={styles.headerImage} >
<View style={styles.titleContainer}>
Expand Down
1 change: 0 additions & 1 deletion index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ var RouteMapper = function(route, navigationOperations, onComponentRef) {
<ToolbarAndroid
navIcon={require('image!ic_back_white')}
onIconClicked={navigationOperations.pop}
title={route.story.title}
titleColor="white"
style={styles.toolbar}
actions={[]}/>
Expand Down

0 comments on commit 0220d4c

Please sign in to comment.