1
1
import React , { Component , PropTypes } from 'react'
2
2
import {
3
- Dimensions ,
4
3
TouchableOpacity ,
5
- PixelRatio ,
6
- View
4
+ Animated
7
5
} from 'react-native'
8
6
import s from './styles'
9
7
import Icon from 'react-native-vector-icons/MaterialIcons'
10
8
11
9
class ScrollToTop extends Component {
10
+ constructor ( props ) {
11
+ super ( props )
12
+
13
+ this . state = {
14
+ bottom : new Animated . Value ( - 54 )
15
+ }
16
+ }
17
+
18
+ componentWillReceiveProps ( nextProps ) {
19
+ if ( this . props . visible !== nextProps . visible ) {
20
+ Animated . timing (
21
+ this . state . bottom ,
22
+ {
23
+ toValue : nextProps . visible ? 0 : - 54 ,
24
+ duration : 200
25
+ } ,
26
+ ) . start ( )
27
+ }
28
+ }
29
+
12
30
_onPress ( ) {
13
31
this . props . root . refs . listview . scrollTo ( { x : 0 , y : 0 , animated : true } ) ;
14
32
}
@@ -26,24 +44,25 @@ class ScrollToTop extends Component {
26
44
iconSize
27
45
} = this . props
28
46
29
- const size = PixelRatio . getPixelSizeForLayoutSize ( iconSize )
30
-
31
47
return (
32
- < TouchableOpacity
33
- onPress = { this . _onPress . bind ( this ) }
34
- style = { [ s . container , {
35
- borderRadius : isRadius ? borderRadius : 0 ,
36
- backgroundColor,
37
- width,
38
- height,
39
- right,
40
- bottom
41
- } ] } >
48
+ < Animated . View
49
+ style = { { bottom : this . state . bottom } } >
50
+ < TouchableOpacity
51
+ onPress = { this . _onPress . bind ( this ) }
52
+ style = { [ s . container , {
53
+ borderRadius : isRadius ? borderRadius : 0 ,
54
+ backgroundColor,
55
+ width,
56
+ height,
57
+ right,
58
+ bottom
59
+ } ] } >
42
60
< Icon
43
61
size = { iconSize }
44
62
color = "white"
45
63
name = { icon } />
46
- </ TouchableOpacity >
64
+ </ TouchableOpacity >
65
+ </ Animated . View >
47
66
) ;
48
67
}
49
68
}
@@ -52,8 +71,6 @@ ScrollToTop.defaultProps = {
52
71
isRadius : true ,
53
72
width : 60 ,
54
73
height : 60 ,
55
- right : Dimensions . get ( 'window' ) . width - 80 ,
56
- top : Dimensions . get ( 'window' ) . height - 160 ,
57
74
borderRadius : 30 ,
58
75
backgroundColor : 'white'
59
76
}
@@ -69,7 +86,8 @@ ScrollToTop.propTypes = {
69
86
root : PropTypes . object ,
70
87
bottom : PropTypes . number ,
71
88
icon : PropTypes . string ,
72
- iconSize : PropTypes . number
89
+ iconSize : PropTypes . number ,
90
+ visible : PropTypes . bool
73
91
}
74
92
75
93
export default ScrollToTop
0 commit comments