Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit ec0a123

Browse files
committed
improve webview UX
1 parent c937af9 commit ec0a123

File tree

3 files changed

+45
-22
lines changed

3 files changed

+45
-22
lines changed

js/containers/HomeTab/index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,18 @@ class HomeFragment extends Component{
6767
headerTitle={item}/>
6868
);
6969
})}
70-
<View style={[styles.footer, {
71-
backgroundColor: rowItemBackgroundColor,
72-
borderTopColor: segmentColor
73-
}]}>
74-
<TouchableOpacity
75-
onPress={this._onPress.bind(this, 1)}
76-
activeOpacity={theme.touchableOpacityActiveOpacity}>
77-
<View style={styles.bottomBtn}>
78-
<Text style={styles.btnLabel}>没看够?试试往期干货吧</Text>
79-
</View>
80-
</TouchableOpacity>
81-
</View>
70+
{/*<View style={[styles.footer, {*/}
71+
{/*backgroundColor: rowItemBackgroundColor,*/}
72+
{/*borderTopColor: segmentColor*/}
73+
{/*}]}>*/}
74+
{/*<TouchableOpacity*/}
75+
{/*onPress={this._onPress.bind(this, 1)}*/}
76+
{/*activeOpacity={theme.touchableOpacityActiveOpacity}>*/}
77+
{/*<View style={styles.bottomBtn}>*/}
78+
{/*<Text style={styles.btnLabel}>没看够?试试往期干货吧</Text>*/}
79+
{/*</View>*/}
80+
{/*</TouchableOpacity>*/}
81+
{/*</View>*/}
8282
</View>
8383
</View>
8484
:

js/containers/MainPage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class BottomTabBar extends Component{
3636
constructor(props){
3737
super(props);
3838
this.state = {
39-
selectedTab: 'more'
39+
selectedTab: 'home'
4040
};
4141
}
4242

js/containers/WebViewPage.js

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'use strict';
55

66
import React, {Component, PropTypes} from 'react';
7-
import {StyleSheet, View, WebView, InteractionManager, Text, TouchableOpacity, ActivityIndicator, Alert, Linking, Clipboard, Modal} from 'react-native';
7+
import {StyleSheet, View, WebView, InteractionManager, Text, TouchableOpacity, ActivityIndicator, Alert, Linking, Clipboard, Modal, PanResponder, Animated, ToastAndroid} from 'react-native';
88
import theme from '../constants/theme';
99
import NavigationBar from '../components/NavigationBar';
1010
import BackPageComponent from '../components/BackPageComponent';
@@ -21,20 +21,45 @@ class WebViewPage extends BackPageComponent{
2121
super(props);
2222
this.state = {
2323
didMount: false,
24-
showMoreContent: false
24+
showMoreContent: false,
25+
bottomInfoBarBottomValue: new Animated.Value(0),
26+
toolbarTopValue: new Animated.Value(0)
2527
};
2628
this.bottomIconNames = ['ios-arrow-back-outline',
2729
'ios-arrow-forward-outline',
2830
'ios-refresh-outline'
2931
];
3032
this.bottomIconSize = [px2dp(25),px2dp(25),px2dp(32)];
33+
34+
this.moveYThreshold = 5;
35+
this.animationFlag = true;
36+
}
37+
38+
componentWillMount(){
39+
this._panResponder = PanResponder.create({
40+
onMoveShouldSetPanResponder: (evt, gestureState) => true,
41+
onPanResponderMove: (evt, gestureState) => {
42+
let y = gestureState.dy;
43+
if(y > this.moveYThreshold) //drag down
44+
if(this.state.bottomInfoBarBottomValue === px2dp(0)) return;
45+
this.animationFlag = false;
46+
Animated.timing(this.state.bottomInfoBarBottomValue, {toValue: 0}).start(()=>this.animationFlag = true);
47+
Animated.timing(this.state.toolbarTopValue, {toValue: 0}).start();
48+
if(y < -this.moveYThreshold && this.animationFlag) { //drag up
49+
if(this.state.bottomInfoBarBottomValue === px2dp(-45)) return;
50+
this.animationFlag = false;
51+
Animated.timing(this.state.bottomInfoBarBottomValue, {toValue: px2dp(-45)}).start(()=>this.animationFlag = true);
52+
Animated.timing(this.state.toolbarTopValue, {toValue: -theme.toolbar.height}).start();
53+
}
54+
}
55+
});
3156
}
3257

3358
render(){
3459
const rowData = this.props.rowData;
3560
return(
3661
<View style={[styles.container, {backgroundColor: this.props.pageBackgroundColor}]}>
37-
<View style={styles.contentContainer}>
62+
<View style={styles.contentContainer} {...this._panResponder.panHandlers}>
3863
{this.state.didMount ?
3964
<WebView
4065
ref={(ref)=>{this.webView = ref}}
@@ -63,16 +88,16 @@ class WebViewPage extends BackPageComponent{
6388
</View>
6489
</Modal>
6590

66-
<View style={styles.toolbar}>
91+
<Animated.View style={[styles.toolbar, {top: this.state.toolbarTopValue}]}>
6792
<NavigationBar
6893
title="详细内容"
6994
leftBtnIcon="arrow-back"
7095
leftBtnPress={this._handleBack.bind(this)}
7196
rightBtnIcon="more"
7297
rightBtnPress={this._btnOnPressCallback.bind(this, 9)}
7398
/>
74-
</View>
75-
<View style={[styles.bottomInfoBar, {backgroundColor: this.props.webViewToolbarColor, borderTopColor: this.props.segmentColor}]}>
99+
</Animated.View>
100+
<Animated.View style={[styles.bottomInfoBar, {bottom: this.state.bottomInfoBarBottomValue, backgroundColor: this.props.webViewToolbarColor, borderTopColor: this.props.segmentColor}]}>
76101
{this.bottomIconNames.map((item, i)=>{
77102
return(
78103
<View key={i} style={{flex: 1, alignItems: 'center'}}>
@@ -99,7 +124,7 @@ class WebViewPage extends BackPageComponent{
99124
</TouchableOpacity>
100125
}
101126
</View>
102-
</View>
127+
</Animated.View>
103128
</View>
104129
);
105130
}
@@ -208,15 +233,13 @@ const styles = StyleSheet.create({
208233
position: 'absolute',
209234
width: theme.screenWidth,
210235
marginTop: theme.toolbar.paddingTop,
211-
top: 0,
212236
zIndex: 1
213237
},
214238
webView: {
215239
flex: 1
216240
},
217241
bottomInfoBar: {
218242
position: 'absolute',
219-
bottom: 0,
220243
height: px2dp(45),
221244
width: theme.screenWidth,
222245
borderTopWidth: theme.segment.width,

0 commit comments

Comments
 (0)