Authored by 于良

个人中心tab悬浮 review by 阿瑟

@@ -32,8 +32,8 @@ export default class User extends React.Component { @@ -32,8 +32,8 @@ export default class User extends React.Component {
32 32
33 userInfo: ImmutablePropTypes.contains({ 33 userInfo: ImmutablePropTypes.contains({
34 avatar: React.PropTypes.string, 34 avatar: React.PropTypes.string,
35 - bgImage:React.PropTypes.string,  
36 - userName:React.PropTypes.string.isRequired, 35 + backgroundImage:React.PropTypes.string,
  36 + nickName:React.PropTypes.string.isRequired,
37 sign: React.PropTypes.string, 37 sign: React.PropTypes.string,
38 }), 38 }),
39 39
@@ -127,9 +127,9 @@ export default class User extends React.Component { @@ -127,9 +127,9 @@ export default class User extends React.Component {
127 onRefresh: React.PropTypes.func, 127 onRefresh: React.PropTypes.func,
128 }; 128 };
129 129
130 -  
131 constructor(props) { 130 constructor(props) {
132 super (props); 131 super (props);
  132 +
133 this.currentPage = 0; 133 this.currentPage = 0;
134 this.tabs = ['我的帖子', '我赞过的', '我的回复']; 134 this.tabs = ['我的帖子', '我赞过的', '我的回复'];
135 this.scrollableTabView = null; 135 this.scrollableTabView = null;
@@ -137,14 +137,17 @@ export default class User extends React.Component { @@ -137,14 +137,17 @@ export default class User extends React.Component {
137 scrollValueH: new Animated.Value(this.currentPage), 137 scrollValueH: new Animated.Value(this.currentPage),
138 scrollValueV: new Animated.Value(0), 138 scrollValueV: new Animated.Value(0),
139 listViewMarginTop: new Animated.Value(0), 139 listViewMarginTop: new Animated.Value(0),
140 - 140 + listViewTop: 0,
141 }; 141 };
142 142
  143 + this.lastValue = 0;
  144 +
143 this._renderSectionHeader = this._renderSectionHeader.bind(this); 145 this._renderSectionHeader = this._renderSectionHeader.bind(this);
144 this._renderRow = this._renderRow.bind(this); 146 this._renderRow = this._renderRow.bind(this);
145 this._renderSeparator = this._renderSeparator.bind(this); 147 this._renderSeparator = this._renderSeparator.bind(this);
146 this._updateHorizontalScrollValue = this._updateHorizontalScrollValue.bind(this); 148 this._updateHorizontalScrollValue = this._updateHorizontalScrollValue.bind(this);
147 this._updateVerticalScrollValue = this._updateVerticalScrollValue.bind(this); 149 this._updateVerticalScrollValue = this._updateVerticalScrollValue.bind(this);
  150 + this.setAnimationValue = this.setAnimationValue.bind(this);
148 this.dataSource = new ListView.DataSource({ 151 this.dataSource = new ListView.DataSource({
149 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), 152 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
150 sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2), 153 sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
@@ -160,28 +163,39 @@ export default class User extends React.Component { @@ -160,28 +163,39 @@ export default class User extends React.Component {
160 } 163 }
161 164
162 setAnimationValue({ value, }) { 165 setAnimationValue({ value, }) {
163 - // if (value <= 2) {  
164 -  
165 - console.log('value ============= >' + value);  
166 - this.animView && this.animView.setNativeProps({  
167 - style: {  
168 - top: 120,  
169 - },  
170 - });  
171 -  
172 - // this.listView && this.listView.setNativeProps({  
173 - // style: {  
174 - // marginTop: value,  
175 - // },  
176 - // });  
177 -  
178 - // value = value > 1 ? 1 : value;  
179 - // this.image.setNativeProps({  
180 - // style: {  
181 - // opacity: value,  
182 - // },  
183 - // });  
184 - // } 166 +
  167 + if (value < 0) {
  168 + return;
  169 + }
  170 +
  171 + if (this.lastValue > value) {
  172 + //down
  173 + if (value < 2) {
  174 + let top = 64 * (value - 1);
  175 + top = top > 64 ? 64 : top;
  176 + top = top < 0 ? 0 : top;
  177 + this.animView && this.animView.setNativeProps({
  178 + style: {
  179 + top,
  180 + },
  181 + });
  182 + }
  183 +
  184 + } else {
  185 + //up
  186 + if (value > 0.9) {
  187 + let top = 64 * (value - 0.6)
  188 + top = top > 64 ? 64 : top;
  189 + top = top < 0 ? 0 : top;
  190 + this.animView && this.animView.setNativeProps({
  191 + style: {
  192 + top,
  193 + },
  194 + });
  195 + }
  196 +
  197 + }
  198 + this.lastValue = value;
185 } 199 }
186 200
187 _renderRow(rowData, sectionID, rowID, highlightRow) { 201 _renderRow(rowData, sectionID, rowID, highlightRow) {
@@ -244,11 +258,10 @@ export default class User extends React.Component { @@ -244,11 +258,10 @@ export default class User extends React.Component {
244 ); 258 );
245 break; 259 break;
246 default: 260 default:
247 - 261 + return null;
248 } 262 }
249 } 263 }
250 264
251 -  
252 _renderSectionHeader(sectionData, sectionID) { 265 _renderSectionHeader(sectionData, sectionID) {
253 switch (sectionID) { 266 switch (sectionID) {
254 case 'list': 267 case 'list':
@@ -282,14 +295,9 @@ export default class User extends React.Component { @@ -282,14 +295,9 @@ export default class User extends React.Component {
282 } 295 }
283 296
284 _updateVerticalScrollValue(offsetY) { 297 _updateVerticalScrollValue(offsetY) {
285 - // console.log('value ============ ' + offsetY/180);  
286 - this.state.scrollValueV.setValue(offsetY/180);  
287 - // this.state.listViewMarginTop =  
288 - if (offsetY >= 180) {  
289 - this.state.listViewMarginTop.setValue(64);  
290 - } else {  
291 - this.state.listViewMarginTop.setValue(offsetY);  
292 - } 298 +
  299 + this.state.scrollValueV.setValue(offsetY/150);
  300 + this.state.listViewMarginTop.setValue(offsetY/150);
293 301
294 } 302 }
295 303
@@ -303,13 +311,12 @@ export default class User extends React.Component { @@ -303,13 +311,12 @@ export default class User extends React.Component {
303 return ( 311 return (
304 <View style={styles.container}> 312 <View style={styles.container}>
305 <Animated.View 313 <Animated.View
306 - ref={(c) => {  
307 - this.animView = c;  
308 - }}  
309 - style={{flex:1, backgroundColor: 'red'}} 314 + ref={(c) => {
  315 + this.animView = c;
  316 + }}
  317 + style={{flex:1, backgroundColor: 'transparent', top: this.state.listViewTop}}
310 > 318 >
311 <ListView 319 <ListView
312 - style={{flex:1, marginTop: 0}}  
313 ref={(c) => { 320 ref={(c) => {
314 this.listView = c; 321 this.listView = c;
315 }} 322 }}
@@ -343,17 +350,12 @@ export default class User extends React.Component { @@ -343,17 +350,12 @@ export default class User extends React.Component {
343 const offsetY = e.nativeEvent.contentOffset.y; 350 const offsetY = e.nativeEvent.contentOffset.y;
344 this._updateVerticalScrollValue(offsetY); 351 this._updateVerticalScrollValue(offsetY);
345 }} 352 }}
346 - // scrollEventThrottle={16}  
347 - >  
348 -  
349 - </ListView>  
350 - 353 + />
351 </Animated.View> 354 </Animated.View>
352 355
353 <UserNavBar scrollValue={this.state.scrollValueV} channel={this.props.channel}/> 356 <UserNavBar scrollValue={this.state.scrollValueV} channel={this.props.channel}/>
354 -  
355 </View> 357 </View>
356 - ) 358 + );
357 } 359 }
358 } 360 }
359 361