Skip to content

Commit 28ae7c7

Browse files
committed
Upgrade to v1.1.0
1 parent c47172c commit 28ae7c7

File tree

4 files changed

+89
-59
lines changed

4 files changed

+89
-59
lines changed

README.md

+19-13
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
- Smooth Animation
88
- Add Your own Component To Bottom Sheet
99
- Customize Whatever You Like
10+
- Support Gesture Swipe Down
1011
- Support All Orientations
1112
- Support Both Android And iOS
1213

13-
| Showcase iOS | Showcase Android |
14-
| :--------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------: |
15-
| ![](https://raw.githubusercontent.com/NYSamnang/stock-images/master/react-native-raw-bottom-sheet/RNRBS-IOS.gif) | ![](https://raw.githubusercontent.com/NYSamnang/stock-images/master/react-native-raw-bottom-sheet/RNRBS-AOS.gif) |
14+
| Showcase iOS | Showcase Android |
15+
| :--------------------------------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------: |
16+
| ![](https://raw.githubusercontent.com/NYSamnang/stock-images/master/react-native-raw-bottom-sheet/RNRBS-IOS-1.1.0.gif) | ![](https://raw.githubusercontent.com/NYSamnang/stock-images/master/react-native-raw-bottom-sheet/RNRBS-AOS-1.1.0.gif) |
1617

1718
## Installation
1819

@@ -50,7 +51,7 @@ class Example extends Component {
5051
height={300}
5152
duration={250}
5253
customStyles={{
53-
content: {
54+
container: {
5455
justifyContent: "center",
5556
alignItems: "center"
5657
}
@@ -70,20 +71,21 @@ export default Example;
7071

7172
## Props
7273

73-
| Prop | Type | Description | Default |
74-
| ------------ | -------- | --------------------------------------------- | -------- |
75-
| height | number | Height of Bottom Sheet | 260 |
76-
| duration | number | Duration of Bottom Sheet animation | 300 (ms) |
77-
| customStyles | object | Custom style to Bottom Sheet | {} |
78-
| onPressMask | function | Event on Mask (The area outside Bottom Sheet) | |
74+
| Prop | Type | Description | Default |
75+
| ---------------- | -------- | ---------------------------------------------- | -------- |
76+
| height | number | Height of Bottom Sheet | 260 |
77+
| duration | number | Duration of Bottom Sheet animation | 300 (ms) |
78+
| closeOnSwipeDown | boolean | Use gesture swipe down to close Bottom Sheet | true |
79+
| closeOnPressMask | boolean | Press the area outside to close Bottom Sheet | true |
80+
| onClose | function | Callback function when Bottom Sheet was closed | |
81+
| customStyles | object | Custom style to Bottom Sheet | {} |
7982

8083
### Available Custom Style
8184

8285
```jsx
8386
customStyles: {
84-
mask: {...}, // The area outside Bottom Sheet
85-
container: {...}, // Bottom Sheet Container
86-
content: {...} // Bottom Sheet Content
87+
wrapper: {...}, // The Background of Component
88+
container: {...} // The Container of Bottom Sheet
8789
}
8890
```
8991

@@ -98,6 +100,10 @@ customStyles: {
98100

99101
Always set `ref` to `RBSheet` and call each method by using `this.RBSheet.methodName()` like example above.
100102

103+
### Give me a Star
104+
105+
If you think this project is helpful just give me a ⭐️ Star is enough because i don't drink coffee :D
106+
101107
## License
102108

103109
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/NYSamnang/react-native-raw-bottom-sheet/blob/master/LICENSE) file for details

package.json

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "react-native-raw-bottom-sheet",
3-
"version": "1.0.0",
4-
"description": "Add Your Own Component To Bottom Sheet Whatever You Want (Android & iOS)",
3+
"version": "1.1.0",
4+
"description": "Add Your Own Component To Bottom Sheet Whatever You Want (Android & iOS)",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
@@ -11,15 +11,15 @@
1111
"url": "git+https://github.com/NYSamnang/react-native-raw-bottom-sheet.git"
1212
},
1313
"keywords": [
14-
"Sheet",
15-
"Bottom Sheet",
16-
"BottomSheet",
17-
"Action Sheet",
18-
"Raw Sheet",
19-
"Bottom Animated",
20-
"Picker",
21-
"Modal",
22-
"Dialog"
14+
"bottom-sheet",
15+
"action-sheet",
16+
"raw-bottom-sheet",
17+
"bottomsheet",
18+
"bottom-animated",
19+
"picker",
20+
"swipper",
21+
"modal",
22+
"dialog"
2323
],
2424
"author": "NY Samnang",
2525
"license": "MIT",

src/index.js

+54-29
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import React, { Component } from "react";
22
import PropTypes from "prop-types";
3-
import { View, Modal, TouchableOpacity, Animated } from "react-native";
3+
import {
4+
View,
5+
Modal,
6+
TouchableOpacity,
7+
Animated,
8+
PanResponder
9+
} from "react-native";
410
import styles from "./style";
511

612
const SUPPORTED_ORIENTATIONS = [
@@ -16,38 +22,51 @@ class RBSheet extends Component {
1622
super();
1723
this.state = {
1824
modalVisible: false,
19-
animatedHeight: new Animated.Value(0)
25+
animatedHeight: new Animated.Value(0),
26+
pan: new Animated.ValueXY()
2027
};
2128

22-
this.onPressMask = this.onPressMask.bind(this);
23-
this.setModalVisible = this.setModalVisible.bind(this);
29+
this.createPanResponder();
30+
}
31+
32+
createPanResponder() {
33+
this.panResponder = PanResponder.create({
34+
onStartShouldSetPanResponder: () => this.props.closeOnSwipeDown,
35+
onPanResponderMove: (e, gestureState) => {
36+
gestureState.dy < 0
37+
? null
38+
: Animated.event([null, { dy: this.state.pan.y }])(e, gestureState);
39+
},
40+
onPanResponderRelease: (e, gestureState) => {
41+
if (this.props.height / 4 - gestureState.dy < 0) {
42+
this.setModalVisible(false);
43+
} else {
44+
Animated.spring(this.state.pan, { toValue: { x: 0, y: 0 } }).start();
45+
}
46+
}
47+
});
2448
}
2549

2650
setModalVisible(visible) {
27-
const { height, duration } = this.props;
51+
const { height, duration, onClose } = this.props;
2852
if (visible) {
2953
this.setState({ modalVisible: visible });
30-
return Animated.timing(this.state.animatedHeight, {
54+
Animated.timing(this.state.animatedHeight, {
3155
toValue: height,
3256
duration: duration
3357
}).start();
3458
} else {
35-
return Animated.timing(this.state.animatedHeight, {
59+
Animated.timing(this.state.animatedHeight, {
3660
toValue: 0,
3761
duration: duration
3862
}).start(() => {
3963
this.setState({ modalVisible: visible });
64+
this.state.pan.setValue({ x: 0, y: 0 });
65+
if (typeof onClose === "function") onClose();
4066
});
4167
}
4268
}
4369

44-
onPressMask() {
45-
this.setModalVisible(false);
46-
if (typeof this.props.onPressMask === "function") {
47-
this.props.onPressMask();
48-
}
49-
}
50-
5170
open() {
5271
this.setModalVisible(true);
5372
}
@@ -57,7 +76,10 @@ class RBSheet extends Component {
5776
}
5877

5978
render() {
60-
const { children, customStyles } = this.props;
79+
const { closeOnPressMask, children, customStyles } = this.props;
80+
const panStyle = {
81+
transform: this.state.pan.getTranslateTransform()
82+
};
6183

6284
return (
6385
<Modal
@@ -69,25 +91,24 @@ class RBSheet extends Component {
6991
this.setModalVisible(false);
7092
}}
7193
>
72-
<TouchableOpacity
73-
style={[styles.mask, customStyles.mask]}
74-
activeOpacity={1}
75-
onPress={this.onPressMask}
76-
>
94+
<View style={[styles.wrapper, customStyles.wrapper]}>
95+
<TouchableOpacity
96+
style={styles.mask}
97+
activeOpacity={1}
98+
onPress={() => (closeOnPressMask ? this.close() : {})}
99+
/>
77100
<Animated.View
101+
{...this.panResponder.panHandlers}
78102
style={[
103+
panStyle,
79104
styles.container,
80-
{ height: this.state.animatedHeight },
81-
customStyles.container
105+
customStyles.container,
106+
{ height: this.state.animatedHeight }
82107
]}
83108
>
84-
<TouchableOpacity activeOpacity={1} style={styles.content}>
85-
<View style={[styles.content, customStyles.content]}>
86-
{children}
87-
</View>
88-
</TouchableOpacity>
109+
{children}
89110
</Animated.View>
90-
</TouchableOpacity>
111+
</View>
91112
</Modal>
92113
);
93114
}
@@ -96,13 +117,17 @@ class RBSheet extends Component {
96117
RBSheet.propTypes = {
97118
height: PropTypes.number,
98119
duration: PropTypes.number,
120+
closeOnSwipeDown: PropTypes.bool,
121+
closeOnPressMask: PropTypes.bool,
99122
customStyles: PropTypes.object,
100-
onPressMask: PropTypes.func
123+
onClose: PropTypes.func
101124
};
102125

103126
RBSheet.defaultProps = {
104127
height: 260,
105128
duration: 300,
129+
closeOnSwipeDown: true,
130+
closeOnPressMask: true,
106131
customStyles: {}
107132
};
108133

src/style.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import { StyleSheet } from "react-native";
22

33
const styles = StyleSheet.create({
4-
mask: {
4+
wrapper: {
55
flex: 1,
6-
alignItems: "flex-end",
7-
flexDirection: "row",
86
backgroundColor: "#00000077"
97
},
8+
mask: {
9+
flex: 1,
10+
backgroundColor: "transparent"
11+
},
1012
container: {
1113
backgroundColor: "#fff",
1214
width: "100%",
1315
height: 0,
1416
overflow: "hidden"
15-
},
16-
content: {
17-
flex: 1
1817
}
1918
});
2019

0 commit comments

Comments
 (0)