Skip to content

Commit 4c61ae8

Browse files
committedJun 20, 2017
Add animation to scrollToBottom
1 parent 7dde61d commit 4c61ae8

File tree

2 files changed

+47
-30
lines changed

2 files changed

+47
-30
lines changed
 

‎app/components/ScrollToTop/index.js

+37-19
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import React, {Component, PropTypes} from 'react'
22
import {
3-
Dimensions,
43
TouchableOpacity,
5-
PixelRatio,
6-
View
4+
Animated
75
} from 'react-native'
86
import s from './styles'
97
import Icon from 'react-native-vector-icons/MaterialIcons'
108

119
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+
1230
_onPress() {
1331
this.props.root.refs.listview.scrollTo({x: 0, y: 0, animated: true});
1432
}
@@ -26,24 +44,25 @@ class ScrollToTop extends Component {
2644
iconSize
2745
} = this.props
2846

29-
const size = PixelRatio.getPixelSizeForLayoutSize(iconSize)
30-
3147
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+
}]}>
4260
<Icon
4361
size={iconSize}
4462
color="white"
4563
name={icon} />
46-
</TouchableOpacity>
64+
</TouchableOpacity>
65+
</Animated.View>
4766
);
4867
}
4968
}
@@ -52,8 +71,6 @@ ScrollToTop.defaultProps = {
5271
isRadius: true,
5372
width: 60,
5473
height: 60,
55-
right: Dimensions.get('window').width - 80,
56-
top: Dimensions.get('window').height - 160,
5774
borderRadius: 30,
5875
backgroundColor: 'white'
5976
}
@@ -69,7 +86,8 @@ ScrollToTop.propTypes = {
6986
root: PropTypes.object,
7087
bottom: PropTypes.number,
7188
icon: PropTypes.string,
72-
iconSize: PropTypes.number
89+
iconSize: PropTypes.number,
90+
visible: PropTypes.bool
7391
}
7492

7593
export default ScrollToTop

‎app/screens/Room/MessagesList/index.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,16 @@ export default class MessagesList extends Component {
135135
initialListSize={14}
136136
renderRow={(rowData, __, rowId) => this.renderRow(rowData, rowId)} />
137137

138-
{isScrollButtonVisible && (
139-
<ScrollToTop
140-
root={this}
141-
width={42}
142-
height={42}
143-
backgroundColor={colors.raspberry}
144-
bottom={12}
145-
right={12}
146-
icon="expand-more"
147-
iconSize={24} />
148-
)}
138+
<ScrollToTop
139+
root={this}
140+
visible={isScrollButtonVisible}
141+
width={42}
142+
height={42}
143+
backgroundColor={colors.raspberry}
144+
bottom={12}
145+
right={12}
146+
icon="expand-more"
147+
iconSize={24} />
149148
</View>
150149
)
151150
}

0 commit comments

Comments
 (0)
Please sign in to comment.