|
4 | 4 | * @flow |
5 | 5 | */ |
6 | 6 |
|
7 | | -import React, { Component } from 'react'; |
| 7 | +import React, {Component} from 'react'; |
8 | 8 | import { |
9 | | - Platform, |
10 | | - StyleSheet, |
11 | | - Text, |
12 | | - View |
| 9 | + Platform, |
| 10 | + StyleSheet, |
| 11 | + Text, |
| 12 | + View, |
| 13 | + ScrollView, |
| 14 | + Animated, |
13 | 15 | } from 'react-native'; |
14 | | - |
| 16 | +import {SmartRefreshControl, AnyHeader} from 'react-native-smartrefreshlayout-next'; |
| 17 | +import Icon from 'react-native-vector-icons/Ionicons' |
| 18 | +import {DotIndicator,SkypeIndicator} from 'react-native-indicators'; |
| 19 | +const AnimatedIcon = Animated.createAnimatedComponent(Icon) |
15 | 20 | const instructions = Platform.select({ |
16 | | - ios: 'Press Cmd+R to reload,\n' + |
| 21 | + ios: 'Press Cmd+R to reload,\n' + |
17 | 22 | 'Cmd+D or shake for dev menu', |
18 | | - android: 'Double tap R on your keyboard to reload,\n' + |
| 23 | + android: 'Double tap R on your keyboard to reload,\n' + |
19 | 24 | 'Shake or press menu button for dev menu', |
20 | 25 | }); |
21 | 26 |
|
22 | 27 | type Props = {}; |
23 | 28 | export default class App extends Component<Props> { |
24 | | - render() { |
25 | | - return ( |
26 | | - <View style={styles.container}> |
27 | | - <Text style={styles.welcome}> |
28 | | - Welcome to React Native! |
29 | | - </Text> |
30 | | - <Text style={styles.instructions}> |
31 | | - To get started, edit App.js |
32 | | - </Text> |
33 | | - <Text style={styles.instructions}> |
34 | | - {instructions} |
35 | | - </Text> |
36 | | - </View> |
37 | | - ); |
38 | | - } |
| 29 | + state = { |
| 30 | + text:'下拉刷新', |
| 31 | + rotate:new Animated.Value(0), |
| 32 | + refreshing:false |
| 33 | + } |
| 34 | + |
| 35 | + render() { |
| 36 | + return ( |
| 37 | + <ScrollView |
| 38 | + refreshControl={ |
| 39 | + <SmartRefreshControl |
| 40 | + ref={ref=>this._refreshc = ref} |
| 41 | + onPullDownToRefresh={()=>{ |
| 42 | + this.setState({ |
| 43 | + text:'下拉刷新', |
| 44 | + refreshing:false |
| 45 | + }) |
| 46 | + Animated.timing(this.state.rotate,{ |
| 47 | + toValue:0, |
| 48 | + duration:197, |
| 49 | + useNativeDriver:true, |
| 50 | + }).start() |
| 51 | + } |
| 52 | + } |
| 53 | + onRefresh={()=>{ |
| 54 | + this.setState({ |
| 55 | + refreshing:true, |
| 56 | + text:'正在刷新' |
| 57 | + }) |
| 58 | + setTimeout(()=>{ |
| 59 | + this._refreshc && this._refreshc.finishRefresh(); |
| 60 | + },1000) |
| 61 | + }} |
| 62 | + onReleaseToRefresh={()=>{ |
| 63 | + this.setState({ |
| 64 | + text:'释放刷新' |
| 65 | + }) |
| 66 | + Animated.timing(this.state.rotate,{ |
| 67 | + toValue:1, |
| 68 | + duration:197, |
| 69 | + useNativeDriver:true, |
| 70 | + }).start() |
| 71 | + }} |
| 72 | + headerHeight={100} |
| 73 | + HeaderComponent={ |
| 74 | + <AnyHeader style={{ |
| 75 | + height: 100, |
| 76 | + flexDirection: 'row', |
| 77 | + alignItems: 'center', |
| 78 | + justifyContent: 'center', |
| 79 | + }}> |
| 80 | + {this.state.refreshing?<SkypeIndicator style={{flex:0}} size={24} color={'#2783cf'}/>:<AnimatedIcon style={{ |
| 81 | + transform:[{ |
| 82 | + rotate:this.state.rotate.interpolate({ |
| 83 | + inputRange:[0,1], |
| 84 | + outputRange:['0deg','180deg'] |
| 85 | + }) |
| 86 | + }] |
| 87 | + }} name="md-arrow-up" color="#2783cf" size={24}/>} |
| 88 | + <Text style={{marginLeft:15}}>{this.state.text}</Text> |
| 89 | + </AnyHeader> |
| 90 | + } |
| 91 | + /> |
| 92 | + } |
| 93 | + > |
| 94 | + <View style={styles.container}> |
| 95 | + <Text style={styles.instructions}> |
| 96 | + To get started, edit App.js |
| 97 | + </Text> |
| 98 | + <Text style={styles.instructions}> |
| 99 | + {instructions} |
| 100 | + </Text> |
| 101 | + </View> |
| 102 | + </ScrollView> |
| 103 | + ); |
| 104 | + } |
39 | 105 | } |
40 | 106 |
|
41 | 107 | const styles = StyleSheet.create({ |
42 | | - container: { |
43 | | - flex: 1, |
44 | | - justifyContent: 'center', |
45 | | - alignItems: 'center', |
46 | | - backgroundColor: '#F5FCFF', |
47 | | - }, |
48 | | - welcome: { |
49 | | - fontSize: 20, |
50 | | - textAlign: 'center', |
51 | | - margin: 10, |
52 | | - }, |
53 | | - instructions: { |
54 | | - textAlign: 'center', |
55 | | - color: '#333333', |
56 | | - marginBottom: 5, |
57 | | - }, |
| 108 | + container: { |
| 109 | + flex: 1, |
| 110 | + justifyContent: 'center', |
| 111 | + alignItems: 'center', |
| 112 | + backgroundColor: '#F5FCFF', |
| 113 | + }, |
| 114 | + welcome: { |
| 115 | + fontSize: 20, |
| 116 | + textAlign: 'center', |
| 117 | + margin: 10, |
| 118 | + }, |
| 119 | + instructions: { |
| 120 | + textAlign: 'center', |
| 121 | + color: '#333333', |
| 122 | + marginBottom: 5, |
| 123 | + }, |
58 | 124 | }); |
0 commit comments