Skip to content

Commit 3d4ad4b

Browse files
author
lukebrandonfarrell
committed
fixed issues with types
1 parent 111e74a commit 3d4ad4b

File tree

6 files changed

+54
-33
lines changed

6 files changed

+54
-33
lines changed

lib/RNNDrawer.d.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ declare interface RNNDrawerOptions {
4343
*/
4444
drawerScreenHeight?: number;
4545
}
46-
declare enum DirectionType {
46+
export declare enum DirectionType {
4747
left = "left",
4848
right = "right",
4949
bottom = "bottom",
5050
top = "top"
5151
}
5252
declare class RNNDrawer {
5353
/**
54-
* Generates the drawer component to
55-
* be used with react-native-navigation
56-
*
57-
* @param component
58-
*/
54+
* Generates the drawer component to
55+
* be used with react-native-navigation
56+
*
57+
* @param component
58+
*/
5959
static create(Component: React.ComponentType): any;
6060
/**
6161
* Shows a drawer component

lib/RNNDrawer.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ var DirectionType;
4141
DirectionType["right"] = "right";
4242
DirectionType["bottom"] = "bottom";
4343
DirectionType["top"] = "top";
44-
})(DirectionType || (DirectionType = {}));
44+
})(DirectionType = exports.DirectionType || (exports.DirectionType = {}));
4545
var RNNDrawer = /** @class */ (function () {
4646
function RNNDrawer() {
4747
}
4848
/**
49-
* Generates the drawer component to
50-
* be used with react-native-navigation
51-
*
52-
* @param component
53-
*/
49+
* Generates the drawer component to
50+
* be used with react-native-navigation
51+
*
52+
* @param component
53+
*/
5454
RNNDrawer.create = function (Component) {
5555
var WrappedDrawer = /** @class */ (function (_super) {
5656
__extends(WrappedDrawer, _super);
@@ -198,12 +198,12 @@ var RNNDrawer = /** @class */ (function () {
198198
/** Props */
199199
var _a = this.props, direction = _a.direction, fadeOpacity = _a.fadeOpacity;
200200
// Adapt the drawer's size on orientation change
201-
react_native_1.Dimensions.addEventListener("change", function (_a) {
201+
react_native_1.Dimensions.addEventListener('change', function (_a) {
202202
var window = _a.window;
203203
var screenHeight = window.height;
204204
_this.setState({ screenHeight: screenHeight });
205205
// Apply correct position if opened from right
206-
if (_this.props.direction === "right") {
206+
if (_this.props.direction === 'right') {
207207
// Calculates the position of the drawer from the left side of the screen
208208
var alignedMovementValue = window.width - _this.drawerWidth;
209209
_this.state.sideMenuOpenValue.setValue(alignedMovementValue);
@@ -280,7 +280,7 @@ var RNNDrawer = /** @class */ (function () {
280280
* Removes all the listenrs from this component
281281
*/
282282
WrappedDrawer.prototype.removeListeners = function () {
283-
react_native_1.Dimensions.removeEventListener("change", function () { });
283+
react_native_1.Dimensions.removeEventListener('change', function () { });
284284
if (this.unsubscribeSwipeStart)
285285
this.unsubscribeSwipeStart();
286286
if (this.unsubscribeSwipeMove)

lib/SideMenuView.d.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@
55
*/
66
import * as React from 'react';
77
import { StyleProp, ViewStyle } from 'react-native';
8-
declare type SwipeFunctionType = () => void;
8+
import { Options } from 'react-native-navigation';
99
interface IProps {
1010
swipeSensitivity?: number;
11-
left?: SwipeFunctionType;
12-
right?: SwipeFunctionType;
1311
sideMargin?: number;
1412
sideMarginLeft?: number;
1513
sideMarginRight?: number;
1614
style?: StyleProp<ViewStyle>;
15+
drawerName: string;
16+
direction: 'left' | 'right';
17+
passProps?: any;
18+
options?: Options;
1719
}
1820
declare class SideMenuView extends React.Component<IProps, {}> {
1921
private isOpened;
@@ -24,6 +26,7 @@ declare class SideMenuView extends React.Component<IProps, {}> {
2426
static defaultProps: {
2527
sideMargin: number;
2628
swipeSensitivity: number;
29+
direction: string;
2730
};
2831
/**
2932
* [ Built-in React method. ]

lib/SideMenuView.js

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
4444
var React = require("react");
4545
var react_native_1 = require("react-native");
4646
/* Utils - Project Utilities */
47+
var RNNDrawer_1 = require("./RNNDrawer");
4748
var events_1 = require("./events");
49+
var RNNDrawer_2 = require("./RNNDrawer");
4850
var screenHeight = react_native_1.Dimensions.get('screen').height;
4951
var SideMenuView = /** @class */ (function (_super) {
5052
__extends(SideMenuView, _super);
@@ -58,7 +60,8 @@ var SideMenuView = /** @class */ (function (_super) {
5860
function SideMenuView(props) {
5961
var _this = _super.call(this, props) || this;
6062
_this.isOpened = false;
61-
var swipeSensitivity = props.swipeSensitivity, left = props.left, right = props.right;
63+
var swipeSensitivity = props.swipeSensitivity, drawerName = props.drawerName, direction = props.direction, passProps = props.passProps, options = props.options;
64+
var directionIsLeft = direction ? direction == 'left' : true;
6265
_this._panResponderMethods = {
6366
// Ask to be the responder:
6467
onStartShouldSetPanResponder: function (_evt, _gestureState) { return true; },
@@ -83,9 +86,15 @@ var SideMenuView = /** @class */ (function (_super) {
8386
events_1.dispatch('SWIPE_MOVE', { value: moveX, direction: 'left' });
8487
// Left Swipe
8588
if (typeof swipeSensitivity !== 'undefined') {
86-
if (vx > swipeSensitivity && !_this.isOpened && left) {
89+
if (vx > swipeSensitivity && !_this.isOpened && directionIsLeft) {
8790
_this.isOpened = true;
88-
left();
91+
RNNDrawer_1.default.showDrawer({
92+
component: {
93+
name: drawerName,
94+
passProps: __assign({ direction: RNNDrawer_2.DirectionType.left, parentComponentId: passProps === null || passProps === void 0 ? void 0 : passProps.parentComponentId }, passProps),
95+
options: __assign({}, options),
96+
},
97+
});
8998
}
9099
}
91100
} }));
@@ -96,9 +105,15 @@ var SideMenuView = /** @class */ (function (_super) {
96105
events_1.dispatch('SWIPE_MOVE', { value: moveX, direction: 'right' });
97106
// Right Swipe
98107
if (typeof swipeSensitivity !== 'undefined') {
99-
if (vx > -swipeSensitivity && !_this.isOpened && right) {
108+
if (vx > -swipeSensitivity && !_this.isOpened && !directionIsLeft) {
100109
_this.isOpened = true;
101-
right();
110+
RNNDrawer_1.default.showDrawer({
111+
component: {
112+
name: drawerName,
113+
passProps: __assign({ direction: RNNDrawer_2.DirectionType.right, parentComponentId: passProps === null || passProps === void 0 ? void 0 : passProps.parentComponentId }, passProps),
114+
options: __assign({}, options),
115+
},
116+
});
102117
}
103118
}
104119
} }));
@@ -137,27 +152,28 @@ var SideMenuView = /** @class */ (function (_super) {
137152
*/
138153
SideMenuView.prototype.render = function () {
139154
/** Props */
140-
var _a = this.props, children = _a.children, left = _a.left, right = _a.right, sideMargin = _a.sideMargin, sideMarginLeft = _a.sideMarginLeft, sideMarginRight = _a.sideMarginRight, props = __rest(_a, ["children", "left", "right", "sideMargin", "sideMarginLeft", "sideMarginRight"]);
155+
var _a = this.props, children = _a.children, direction = _a.direction, sideMargin = _a.sideMargin, sideMarginLeft = _a.sideMarginLeft, sideMarginRight = _a.sideMarginRight, props = __rest(_a, ["children", "direction", "sideMargin", "sideMarginLeft", "sideMarginRight"]);
156+
var directionIsLeft = direction ? direction == 'left' : true;
141157
return (React.createElement(react_native_1.View, __assign({}, props),
142158
children,
143-
left ? (React.createElement(react_native_1.View, __assign({ style: {
159+
directionIsLeft ? (React.createElement(react_native_1.View, __assign({ style: {
144160
left: 0,
145161
position: 'absolute',
146162
width: sideMargin || sideMarginLeft,
147163
height: screenHeight,
148164
zIndex: 9999,
149-
} }, this._leftPanResponder.panHandlers))) : null,
150-
right ? (React.createElement(react_native_1.View, __assign({ style: {
165+
} }, this._leftPanResponder.panHandlers))) : (React.createElement(react_native_1.View, __assign({ style: {
151166
position: 'absolute',
152167
right: 0,
153168
width: sideMargin || sideMarginRight,
154169
height: screenHeight,
155170
zIndex: 9999,
156-
} }, this._rightPanResponder.panHandlers))) : null));
171+
} }, this._rightPanResponder.panHandlers)))));
157172
};
158173
SideMenuView.defaultProps = {
159174
sideMargin: 15,
160175
swipeSensitivity: 0.2,
176+
direction: 'left',
161177
};
162178
return SideMenuView;
163179
}(React.Component));

src/RNNDrawer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ declare interface RNNDrawerOptions {
7171
drawerScreenHeight?: number;
7272
}
7373

74-
enum DirectionType {
74+
export enum DirectionType {
7575
left = 'left',
7676
right = 'right',
7777
bottom = 'bottom',

src/SideMenuView.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import {
1818
ViewStyle,
1919
} from 'react-native';
2020
import { Options } from 'react-native-navigation';
21-
2221
/* Utils - Project Utilities */
2322
import RNNDrawer from './RNNDrawer';
2423
import { listen, dispatch } from './events';
24+
import { DirectionType } from "./RNNDrawer";
2525

2626
const screenHeight: number = Dimensions.get('screen').height;
2727

@@ -33,7 +33,7 @@ interface IProps {
3333
style?: StyleProp<ViewStyle>;
3434
drawerName: string;
3535
direction: 'left' | 'right';
36-
passProps?: object;
36+
passProps?: any;
3737
options?: Options;
3838
}
3939

@@ -133,7 +133,8 @@ class SideMenuView extends React.Component<IProps, {}> {
133133
component: {
134134
name: drawerName,
135135
passProps: {
136-
direction: 'left',
136+
direction: DirectionType.left,
137+
parentComponentId: passProps?.parentComponentId,
137138
...passProps,
138139
},
139140
options: { ...options },
@@ -164,7 +165,8 @@ class SideMenuView extends React.Component<IProps, {}> {
164165
component: {
165166
name: drawerName,
166167
passProps: {
167-
direction: 'right',
168+
direction: DirectionType.right,
169+
parentComponentId: passProps?.parentComponentId,
168170
...passProps,
169171
},
170172
options: { ...options },

0 commit comments

Comments
 (0)