Skip to content

Commit a1908f5

Browse files
author
Luke Brandon Farrell
committed
Fixes for RNN >= 3.XX
fix: 'transparent' is now automatically applied to the overlay. Fixes #19 fix: `useNativeDriver` is set to `false`. Fixes #20
1 parent c4f899f commit a1908f5

File tree

8 files changed

+47
-19
lines changed

8 files changed

+47
-19
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
2-
node_modules
2+
node_modules
3+
.DS_Store

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[React Native Navigation by Wix](https://wix.github.io/react-native-navigation/#/) does not offer an in-built solution for displaying a drawer on iOS. Their current side-menu has limited functionality on both iOS and Android. This is a drawer solution using showOverlay under the hood to display a drawer on iOS and Android.
44

5+
If you are using React Native Navigation >= 3.0.0 then use version 3.x.x + of this library.
6+
57
<p align="left">
68
<a href="https://www.npmjs.com/package/react-native-navigation-drawer-extension" rel="nofollow">
79
<img src="https://img.shields.io/npm/v/react-native-navigation-drawer-extension.svg?style=flat-square" alt="version" style="max-width:100%;" />

lib/RNNDrawer.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ declare class RNNDrawer {
99
/**
1010
* Shows a drawer component
1111
*
12-
* @param options
12+
* @param layout
1313
*/
14-
static showDrawer(options: Layout): void;
14+
static showDrawer(layout: Layout): void;
1515
/**
1616
* Dismiss the drawer component
1717
*/

lib/RNNDrawer.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,13 @@ var RNNDrawer = /** @class */ (function () {
117117
this.animatedDrawer = react_native_1.Animated.timing(this.state.sideMenuOpenValue, {
118118
toValue: this.drawerOpenedValues[direction],
119119
duration: this.props.animationOpenTime,
120+
useNativeDriver: false
120121
});
121122
// Animate outside side menu opacity
122123
this.animatedOpacity = react_native_1.Animated.timing(this.state.sideMenuOverlayOpacity, {
123124
toValue: fadeOpacity,
124125
duration: this.props.animationOpenTime,
126+
useNativeDriver: false
125127
});
126128
};
127129
/**
@@ -288,6 +290,7 @@ var RNNDrawer = /** @class */ (function () {
288290
react_native_1.Animated.timing(this.state.sideMenuOpenValue, {
289291
toValue: closeValues[direction],
290292
duration: this.props.animationCloseTime,
293+
useNativeDriver: false
291294
}).start(function () {
292295
react_native_navigation_1.Navigation.dismissOverlay(_this.props.componentId);
293296
_this.setState({ sideMenuIsDismissing: false });
@@ -296,6 +299,7 @@ var RNNDrawer = /** @class */ (function () {
296299
react_native_1.Animated.timing(this.state.sideMenuOverlayOpacity, {
297300
toValue: 0,
298301
duration: this.props.animationCloseTime,
302+
useNativeDriver: false
299303
}).start();
300304
};
301305
WrappedDrawer.defaultProps = {
@@ -314,10 +318,19 @@ var RNNDrawer = /** @class */ (function () {
314318
/**
315319
* Shows a drawer component
316320
*
317-
* @param options
321+
* @param layout
318322
*/
319-
RNNDrawer.showDrawer = function (options) {
320-
react_native_navigation_1.Navigation.showOverlay(options);
323+
RNNDrawer.showDrawer = function (layout) {
324+
var _a, _b, _c, _d, _e;
325+
// By default for this library, we make the 'componentBackgroundColor' transparent
326+
var componentBackgroundColor = (_d = (_c = (_b = (_a = layout === null || layout === void 0 ? void 0 : layout.component) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.layout) === null || _c === void 0 ? void 0 : _c.componentBackgroundColor) !== null && _d !== void 0 ? _d : "transparent";
327+
var options = __assign(__assign({}, (_e = layout === null || layout === void 0 ? void 0 : layout.component) === null || _e === void 0 ? void 0 : _e.options), { layout: {
328+
componentBackgroundColor: componentBackgroundColor
329+
} });
330+
// Mutate options to add 'transparent' by default
331+
// @ts-ignore
332+
layout.component.options = __assign({}, options);
333+
react_native_navigation_1.Navigation.showOverlay(layout);
321334
};
322335
/**
323336
* Dismiss the drawer component

lib/SideMenuView.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var SideMenuView = /** @class */ (function (_super) {
7777
onShouldBlockNativeResponder: function (_evt, _gestureState) { return false; },
7878
};
7979
// LEFT PAN RESPONDER
80-
_this._leftPanResponder = react_native_1.PanResponder.create(__assign({}, _this._panResponderMethods, { onPanResponderMove: function (_evt, gestureState) {
80+
_this._leftPanResponder = react_native_1.PanResponder.create(__assign(__assign({}, _this._panResponderMethods), { onPanResponderMove: function (_evt, gestureState) {
8181
var moveX = gestureState.moveX, vx = gestureState.vx;
8282
// Emit this event on movement
8383
events_1.dispatch('SWIPE_MOVE', { value: moveX, direction: 'left' });
@@ -90,7 +90,7 @@ var SideMenuView = /** @class */ (function (_super) {
9090
}
9191
} }));
9292
// RIGHT PAN RESPONDER
93-
_this._rightPanResponder = react_native_1.PanResponder.create(__assign({}, _this._panResponderMethods, { onPanResponderMove: function (_evt, gestureState) {
93+
_this._rightPanResponder = react_native_1.PanResponder.create(__assign(__assign({}, _this._panResponderMethods), { onPanResponderMove: function (_evt, gestureState) {
9494
var moveX = gestureState.moveX, vx = gestureState.vx;
9595
// Emit this event on movement
9696
events_1.dispatch('SWIPE_MOVE', { value: moveX, direction: 'right' });

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"typescript"
3232
],
3333
"peerDependencies": {
34-
"react-native-navigation": "2.x"
34+
"react-native-navigation": ">= 3.x"
3535
},
3636
"author": "Luke Brandon Farrell",
3737
"license": "MIT",
@@ -46,7 +46,7 @@
4646
"prettier": "1.18.2",
4747
"react": "^16.9.0",
4848
"react-native": "^0.60.4",
49-
"react-native-navigation": "^2.26.5",
50-
"typescript": "^3.5.3"
49+
"react-native-navigation": "^6.4.0",
50+
"typescript": "^3.8.3"
5151
}
5252
}

src/RNNDrawer.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ class RNNDrawer {
190190
this.animatedDrawer = Animated.timing(this.state.sideMenuOpenValue, {
191191
toValue: this.drawerOpenedValues[direction],
192192
duration: this.props.animationOpenTime,
193+
useNativeDriver: false
193194
});
194195

195196
// Animate outside side menu opacity
@@ -198,6 +199,7 @@ class RNNDrawer {
198199
{
199200
toValue: fadeOpacity,
200201
duration: this.props.animationOpenTime,
202+
useNativeDriver: false
201203
},
202204
);
203205
}
@@ -408,6 +410,7 @@ class RNNDrawer {
408410
Animated.timing(this.state.sideMenuOpenValue, {
409411
toValue: closeValues[direction],
410412
duration: this.props.animationCloseTime,
413+
useNativeDriver: false
411414
}).start(() => {
412415
Navigation.dismissOverlay(this.props.componentId);
413416
this.setState({ sideMenuIsDismissing: false });
@@ -417,6 +420,7 @@ class RNNDrawer {
417420
Animated.timing(this.state.sideMenuOverlayOpacity, {
418421
toValue: 0,
419422
duration: this.props.animationCloseTime,
423+
useNativeDriver: false
420424
}).start();
421425
}
422426
}
@@ -427,10 +431,23 @@ class RNNDrawer {
427431
/**
428432
* Shows a drawer component
429433
*
430-
* @param options
434+
* @param layout
431435
*/
432-
static showDrawer(options: Layout) {
433-
Navigation.showOverlay(options);
436+
static showDrawer(layout: Layout) {
437+
// By default for this library, we make the 'componentBackgroundColor' transparent
438+
const componentBackgroundColor = layout?.component?.options?.layout?.componentBackgroundColor ?? "transparent";
439+
const options = {
440+
...layout?.component?.options,
441+
layout: {
442+
componentBackgroundColor: componentBackgroundColor
443+
}
444+
};
445+
446+
// Mutate options to add 'transparent' by default
447+
// @ts-ignore
448+
layout.component.options = { ...options };
449+
450+
Navigation.showOverlay(layout);
434451
}
435452

436453
/**

src/events.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
* @description Event dispatcher for comunication between components.
44
*/
55

6-
interface EventInterface {
7-
count: number;
8-
funcs: any;
9-
}
10-
116
interface EvnetsInterface {
127
[key: string]: any;
138
}

0 commit comments

Comments
 (0)