-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModernNavItem.js
More file actions
151 lines (136 loc) · 4.54 KB
/
ModernNavItem.js
File metadata and controls
151 lines (136 loc) · 4.54 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import React, {Component} from 'react';
import {
View,
TouchableOpacity,
Dimensions,
ScrollView,
ImageBackground, Animated,Image
} from 'react-native';
let {height, width} = Dimensions.get('window');
export default class ModernNavItem extends Component {
constructor(props) {
super(props);
this.state = {
isOnTop: true,
offsetY: new Animated.Value(40),
fadeIn: new Animated.Value(0)
};
openFab = openFab.bind(this);
closeFab = closeFab.bind(this);
}
render() {
return (
<View>
<ScrollView style={{zIndex: 999}} ref={(ref) => this.scrollView = ref}
nestedScrollEnabled onMomentumScrollEnd={this.handleScroll}>
<View style={{height: 2 * height / 3}}/>
<TouchableOpacity
key={this.props.item.id}
style={{
width: width,
marginRight: 8,
overflow: 'hidden',
}}
activeOpacity={1}
>
<View style={{
marginLeft: 8, marginRight: 8,
backgroundColor: 'white',
borderRadius: 8,
overflow: 'hidden',
}}>
{this.props.item.view}
</View>
</TouchableOpacity>
</ScrollView>
{!this.state.isOnTop &&
<Animated.View
style={{
opacity: this.state.fadeIn,
transform: [{translateY: this.state.offsetY}],
position: 'absolute',
right: 24,
bottom: 24,
}}
>
<ImageBackground
style={{padding: 8}}
source={require('./shadow.png')}
>
<TouchableOpacity
style={{
width: 52, height: 52,
borderRadius: 26,
overflow: 'hidden',
backgroundColor: this.props.topButtonColor,
justifyContent:'center',
alignItems:'center'
}}
onPress={() => {
this.scrollView.scrollTo({x: 0, y: 0, animated: true})
closeFab()
}
}
>
<Image source={require('./chevron-up.png')}/>
</TouchableOpacity>
</ImageBackground>
</Animated.View>
}
</View>
);
}
handleScroll = (event: Object) => {
console.log(event.nativeEvent);
if (this.state.isOnTop && parseInt(event.nativeEvent.contentOffset.y) > 0) {
this.setState({isOnTop: false},()=>{
openFab()
})
} else if (!this.state.isOnTop && parseInt(event.nativeEvent.contentOffset.y) <= 200) {
console.log(event.nativeEvent.contentOffset.y);
closeFab();
}
}
}
export function openFab() {
this.setState({open: true}, () => {
Animated.parallel([
Animated.timing(
this.state.fadeIn,
{
toValue: 1,
duration: 500,
useNativeDriver: true
}
),
Animated.timing(
this.state.offsetY,
{
toValue: 0,
duration: 300,
useNativeDriver: true
}
)
]).start();
});
}
export function closeFab() {
Animated.parallel([
Animated.timing(
this.state.fadeIn,
{
toValue: 0,
duration: 500,
useNativeDriver: true
}
),
Animated.timing(
this.state.offsetY,
{
toValue: 40,
duration: 300,
useNativeDriver: true
}
)
]).start(() => this.setState({isOnTop: true}));
}