forked from octopitus/rn-sliding-up-panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBottomSheet.js
More file actions
115 lines (100 loc) · 2.42 KB
/
BottomSheet.js
File metadata and controls
115 lines (100 loc) · 2.42 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
/**
* You can make the panel renders collapsed at bottom
* by using the startCollapsed prop.
*/
import React from 'react'
import {
AppRegistry,
Text,
View,
Dimensions,
Image,
Animated
} from 'react-native'
import SlidingUpPanel from 'rn-sliding-up-panel'
const {height} = Dimensions.get('window')
const styles = {
container: {
flex: 1,
backgroundColor: '#f8f9fa',
alignItems: 'center',
justifyContent: 'center'
},
panel: {
flex: 1,
backgroundColor: 'white',
position: 'relative'
},
panelHeader: {
height: 120,
backgroundColor: '#b197fc',
alignItems: 'center',
justifyContent: 'center'
},
favoriteIcon: {
position: 'absolute',
top: -24,
right: 24,
backgroundColor: '#2b8a3e',
width: 48,
height: 48,
padding: 8,
borderRadius: 24,
zIndex: 1
}
}
class BottomSheet extends React.Component {
static defaultProps = {
draggableRange: {
top: height / 1.75,
bottom: 120
}
}
_draggedValue = new Animated.Value(-120)
constructor(props) {
super(props)
this._renderFavoriteIcon = this._renderFavoriteIcon.bind(this)
}
_renderFavoriteIcon() {
const {top, bottom} = this.props.draggableRange
const draggedValue = this._draggedValue.interpolate({
inputRange: [bottom, top],
outputRange: [0, 1],
extrapolate: 'clamp'
})
const transform = [{scale: draggedValue}]
return (
<Animated.View style={[styles.favoriteIcon, {transform}]}>
<Image
source={require('./favorite_white.png')}
style={{width: 32, height: 32}}
/>
</Animated.View>
)
}
render() {
return (
<View style={styles.container}>
<Text>Hello world</Text>
<SlidingUpPanel
visible
startCollapsed
showBackdrop={false}
ref={c => this._panel = c}
draggableRange={this.props.draggableRange}
onDrag={v => this._draggedValue.setValue(v)}>
<View style={styles.panel}>
{this._renderFavoriteIcon()}
<View style={styles.panelHeader}>
<Text style={{color: '#FFF'}}>Bottom Sheet Peek</Text>
</View>
<View style={styles.container}>
<Text>Bottom Sheet Content</Text>
</View>
</View>
</SlidingUpPanel>
</View>
)
}
}
AppRegistry.registerComponent('BottomSheet', () => BottomSheet)