Skip to content

Commit ee12571

Browse files
Merge pull request #36 from aspect-apps/feature/close-drawer-swipping
Feature/close drawer swipping
2 parents dde7ef1 + 7c73191 commit ee12571

File tree

8 files changed

+11917
-41
lines changed

8 files changed

+11917
-41
lines changed

example/ios/AwesomeProject.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@
659659
DEVELOPMENT_TEAM = YT5JKQN5YD;
660660
ENABLE_BITCODE = NO;
661661
INFOPLIST_FILE = AwesomeProject/Info.plist;
662+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
662663
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
663664
OTHER_LDFLAGS = (
664665
"$(inherited)",
@@ -682,6 +683,7 @@
682683
CURRENT_PROJECT_VERSION = 1;
683684
DEVELOPMENT_TEAM = YT5JKQN5YD;
684685
INFOPLIST_FILE = AwesomeProject/Info.plist;
686+
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
685687
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
686688
OTHER_LDFLAGS = (
687689
"$(inherited)",

example/ios/AwesomeProject.xcodeproj/xcshareddata/xcschemes/AwesomeProject.xcscheme

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@
4141
</Testables>
4242
</TestAction>
4343
<LaunchAction
44-
buildConfiguration = "Debug"
45-
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
46-
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
44+
buildConfiguration = "Release"
45+
selectedDebuggerIdentifier = ""
46+
selectedLauncherIdentifier = "Xcode.IDEFoundation.Launcher.PosixSpawn"
4747
launchStyle = "0"
4848
useCustomWorkingDirectory = "NO"
4949
ignoresPersistentStateOnLaunch = "NO"

example/ios/Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,12 @@ PODS:
296296
- React-Core (= 0.63.3)
297297
- React-cxxreact (= 0.63.3)
298298
- React-jsi (= 0.63.3)
299-
- ReactNativeNavigation (7.2.0):
299+
- ReactNativeNavigation (7.3.0):
300300
- React-Core
301301
- React-RCTImage
302302
- React-RCTText
303-
- ReactNativeNavigation/Core (= 7.2.0)
304-
- ReactNativeNavigation/Core (7.2.0):
303+
- ReactNativeNavigation/Core (= 7.3.0)
304+
- ReactNativeNavigation/Core (7.3.0):
305305
- React-Core
306306
- React-RCTImage
307307
- React-RCTText
@@ -467,7 +467,7 @@ SPEC CHECKSUMS:
467467
React-RCTText: 65a6de06a7389098ce24340d1d3556015c38f746
468468
React-RCTVibration: 8e9fb25724a0805107fc1acc9075e26f814df454
469469
ReactCommon: 4167844018c9ed375cc01a843e9ee564399e53c3
470-
ReactNativeNavigation: 2f6571c37eaeb7d472fe8a3779d49d7aae32e75a
470+
ReactNativeNavigation: c2dcda2b86e32090c443182206c915107d03106f
471471
Yoga: 7d13633d129fd179e01b8953d38d47be90db185a
472472
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
473473

example/package-lock.json

Lines changed: 11716 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/src/pages/HomePage.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
TouchableOpacity,
77
View,
88
} from 'react-native';
9-
import {RNNDrawer} from 'react-native-navigation-drawer-extension';
9+
import { RNNDrawer, SideMenuView } from 'react-native-navigation-drawer-extension';
1010

1111
const HomePage = (props) => {
1212
const onPress = () => {
@@ -26,15 +26,29 @@ const HomePage = (props) => {
2626
};
2727

2828
return (
29-
<SafeAreaView>
30-
<View style={styles.mainContainer}>
31-
<Text style={styles.headlineText}>HomePage View</Text>
29+
<SideMenuView
30+
style={{ flex: 1 }}
31+
left={() => RNNDrawer.showDrawer({
32+
component: {
33+
name: 'CustomDrawer',
34+
passProps: {
35+
direction: 'left',
36+
parentComponentId: props.componentId,
37+
},
38+
},
39+
}
40+
)}
41+
>
42+
<SafeAreaView>
43+
<View style={styles.mainContainer}>
44+
<Text style={styles.headlineText}>HomePage View</Text>
3245

33-
<TouchableOpacity style={styles.buttonContainer} onPress={onPress}>
34-
<Text style={styles.buttonText}>Open Drawer</Text>
35-
</TouchableOpacity>
36-
</View>
37-
</SafeAreaView>
46+
<TouchableOpacity style={styles.buttonContainer} onPress={onPress}>
47+
<Text style={styles.buttonText}>Open Drawer</Text>
48+
</TouchableOpacity>
49+
</View>
50+
</SafeAreaView>
51+
</SideMenuView>
3852
);
3953
};
4054

lib/RNNDrawer.d.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,58 @@
44
*/
55
import * as React from 'react';
66
import { Layout } from 'react-native-navigation';
7-
8-
type DirectionType = "left" | "right" | "top" | "bottom";
9-
107
declare interface RNNDrawerOptions {
118
/**
129
* Id of parent component of the drawer.
1310
* This field is necessary in order to be able
1411
* to push screens inside the drawer
1512
*/
1613
parentComponentId: string;
17-
14+
/**
15+
* Direction to open the collage,
16+
* one of: ["left", "right", "top", "bottom"]
17+
* If not provided, drawer might have
18+
* a weird effect when closing
19+
*/
20+
direction: DirectionType;
1821
/**
1922
* Time in milliseconds to execute the drawer opening animation
2023
*/
2124
animationOpenTime?: number;
22-
2325
/**
2426
* Time in milliseconds to execute the drawer closing animation
2527
*/
2628
animationCloseTime?: number;
27-
28-
/**
29-
* Direction to open the collage,
30-
* one of: ["left", "right", "top", "bottom"]
31-
*/
32-
direction?: DirectionType;
33-
3429
/**
3530
* Whether the drawer be dismissed when a click is registered outside
3631
*/
3732
dismissWhenTouchOutside?: boolean;
38-
3933
/**
4034
* Opacity of the screen outside the drawer
4135
*/
4236
fadeOpacity?: number;
43-
4437
/**
4538
* Width of drawer in relation to the screen (0 to 1)
4639
*/
4740
drawerScreenWidth?: number;
48-
4941
/**
5042
* Height of drawer in relation to the screen (0 to 1)
5143
*/
5244
drawerScreenHeight?: number;
5345
}
54-
46+
declare enum DirectionType {
47+
left = "left",
48+
right = "right",
49+
bottom = "bottom",
50+
top = "top"
51+
}
5552
declare class RNNDrawer {
5653
/**
57-
* Generates the drawer component to
58-
* be used with react-native-navigation
59-
*
60-
* @param component
61-
*/
54+
* Generates the drawer component to
55+
* be used with react-native-navigation
56+
*
57+
* @param component
58+
*/
6259
static create(Component: React.ComponentType): any;
6360
/**
6461
* Shows a drawer component

lib/RNNDrawer.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ var DirectionType;
4545
var RNNDrawer = /** @class */ (function () {
4646
function RNNDrawer() {
4747
}
48+
/**
49+
* Generates the drawer component to
50+
* be used with react-native-navigation
51+
*
52+
* @param component
53+
*/
4854
RNNDrawer.create = function (Component) {
4955
var WrappedDrawer = /** @class */ (function (_super) {
5056
__extends(WrappedDrawer, _super);
@@ -59,6 +65,30 @@ var RNNDrawer = /** @class */ (function () {
5965
var _this = _super.call(this, props) || this;
6066
_this.screenWidth = react_native_1.Dimensions.get('window').width;
6167
_this.screenHeight = react_native_1.Dimensions.get('window').height;
68+
_this.panResponder = react_native_1.PanResponder.create({
69+
onStartShouldSetPanResponder: function (_evt, _gestureState) { return false; },
70+
onStartShouldSetPanResponderCapture: function (_evt, _gestureState) { return false; },
71+
onMoveShouldSetPanResponder: function (_evt, _gestureState) {
72+
var dx = _gestureState.dx;
73+
return Math.abs(dx) > 5;
74+
},
75+
onMoveShouldSetPanResponderCapture: function (_evt, _gestureState) { return false; },
76+
onPanResponderGrant: function (_evt, _gestureState) {
77+
events_1.dispatch('SWIPE_START');
78+
},
79+
onPanResponderRelease: function (_evt, gestureState) {
80+
var vx = gestureState.vx;
81+
// Emit this event when the gesture ends
82+
events_1.dispatch('SWIPE_END', vx > 0 ? 'right' : 'left');
83+
},
84+
onPanResponderTerminationRequest: function (_evt, _gestureState) { return false; },
85+
onShouldBlockNativeResponder: function (_evt, _gestureState) { return false; },
86+
onPanResponderMove: function (_evt, _gestureState) {
87+
var moveX = _gestureState.moveX;
88+
var direction = _this.props.direction || 'left';
89+
events_1.dispatch('SWIPE_MOVE', { value: moveX, direction: direction });
90+
},
91+
});
6292
/*
6393
* We need to convert the pushed drawer width
6494
* to a number as it can either be a string ('20%')
@@ -276,7 +306,7 @@ var RNNDrawer = /** @class */ (function () {
276306
var animatedValue = direction === DirectionType.left || direction === DirectionType.right
277307
? { marginLeft: sideMenuOpenValue }
278308
: { marginTop: sideMenuOpenValue };
279-
return (React.createElement(react_native_1.View, { style: sideMenuContainerStyle },
309+
return (React.createElement(react_native_1.View, __assign({ style: sideMenuContainerStyle }, this.panResponder.panHandlers),
280310
React.createElement(react_native_1.TouchableWithoutFeedback, { onPress: this.touchedOutside },
281311
React.createElement(react_native_1.Animated.View, { style: [
282312
sideMenuOverlayStyle,

0 commit comments

Comments
 (0)