-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathScroll animation change view position
101 lines (90 loc) · 2.37 KB
/
Scroll animation change view position
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import React,{Component} from 'react';
import {
StyleSheet,
View,
Text,
Platform,
Dimensions,
FlatList,
Animated,
ScrollView,
} from 'react-native';
var {height, width} = Dimensions.get("window");
var headerHeight = 200;
class DemoScreen extends Component {
constructor(props) {
super(props);
this.state = {
scrollY: new Animated.Value(0),
}
}
componentDidMount() {
}
static navigationOptions = ({navigation}) => {
return {
headerTitle: <Text numberOfLines={1} style={{color: 'black', width: width-70, fontSize: 20, textAlign: Platform.OS==='android' ? 'left' : 'center'}}>Demo Screen</Text>,
};
}
render() {
var headMov = this.state.scrollY.interpolate({
inputRange: [0, headerHeight, headerHeight],
outputRange: [0, -headerHeight, -headerHeight]
});
return(
<View style={styles.container}>
<FlatList
style={{flex: 1}}
renderScrollComponent={this.renderScroll}
style={{height:height, backgroundColor:"green"}}
contentContainerStyle={{ paddingTop:headerHeight }}
renderItem={({item})=><View><Text>{item}</Text></View>}
keyExtractor={(item, index)=>index.toString()}
data={[1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0]} />
<Animated.View
style={{
position: "absolute",
height: headerHeight,
width: width,
top: 0,
backgroundColor: 'red',
transform: [{ translateY: headMov }]
}}>
<Text>1</Text>
<Text>2</Text>
<Text>3</Text>
<Text>4</Text>
<Text>5</Text>
</Animated.View>
</View>
)
}
renderScroll = (props) => {
return (
<Animated.ScrollView
{...props}
scrollEventThrottle={16}
showsVerticalScrollIndicator={false}
contentContainerStyle={{
paddingTop: headerHeight,
}}
onScroll={Animated.event(
[
{
nativeEvent: { contentOffset: { y: this.state.scrollY } }
}
],
//{ listener: this._handleScroll.bind(this) }, //Added listener
{
useNativeDriver: true
}
)} />
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor:'white',
},
});
export {DemoScreen};