react-native-drawer-layout 2.0.0 → 3.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +235 -35
  3. package/lib/commonjs/constants.js +15 -0
  4. package/lib/commonjs/constants.js.map +1 -0
  5. package/lib/commonjs/index.js +35 -0
  6. package/lib/commonjs/index.js.map +1 -0
  7. package/lib/commonjs/types.js +6 -0
  8. package/lib/commonjs/types.js.map +1 -0
  9. package/lib/commonjs/utils/DrawerGestureContext.js +12 -0
  10. package/lib/commonjs/utils/DrawerGestureContext.js.map +1 -0
  11. package/lib/commonjs/utils/DrawerProgressContext.js +12 -0
  12. package/lib/commonjs/utils/DrawerProgressContext.js.map +1 -0
  13. package/lib/commonjs/utils/useDrawerProgress.js +19 -0
  14. package/lib/commonjs/utils/useDrawerProgress.js.map +1 -0
  15. package/lib/commonjs/views/Drawer.js +89 -0
  16. package/lib/commonjs/views/Drawer.js.map +1 -0
  17. package/lib/commonjs/views/GestureHandler.android.js +17 -0
  18. package/lib/commonjs/views/GestureHandler.android.js.map +1 -0
  19. package/lib/commonjs/views/GestureHandler.ios.js +17 -0
  20. package/lib/commonjs/views/GestureHandler.ios.js.map +1 -0
  21. package/lib/commonjs/views/GestureHandler.js +33 -0
  22. package/lib/commonjs/views/GestureHandler.js.map +1 -0
  23. package/lib/commonjs/views/GestureHandlerNative.js +37 -0
  24. package/lib/commonjs/views/GestureHandlerNative.js.map +1 -0
  25. package/lib/commonjs/views/legacy/Drawer.js +419 -0
  26. package/lib/commonjs/views/legacy/Drawer.js.map +1 -0
  27. package/lib/commonjs/views/legacy/Overlay.js +74 -0
  28. package/lib/commonjs/views/legacy/Overlay.js.map +1 -0
  29. package/lib/commonjs/views/modern/Drawer.js +285 -0
  30. package/lib/commonjs/views/modern/Drawer.js.map +1 -0
  31. package/lib/commonjs/views/modern/Overlay.js +69 -0
  32. package/lib/commonjs/views/modern/Overlay.js.map +1 -0
  33. package/lib/module/constants.js +5 -0
  34. package/lib/module/constants.js.map +1 -0
  35. package/lib/module/index.js +5 -0
  36. package/lib/module/index.js.map +1 -0
  37. package/lib/module/types.js +2 -0
  38. package/lib/module/types.js.map +1 -0
  39. package/lib/module/utils/DrawerGestureContext.js +3 -0
  40. package/lib/module/utils/DrawerGestureContext.js.map +1 -0
  41. package/lib/module/utils/DrawerProgressContext.js +3 -0
  42. package/lib/module/utils/DrawerProgressContext.js.map +1 -0
  43. package/lib/module/utils/useDrawerProgress.js +10 -0
  44. package/lib/module/utils/useDrawerProgress.js.map +1 -0
  45. package/lib/module/views/Drawer.js +81 -0
  46. package/lib/module/views/Drawer.js.map +1 -0
  47. package/lib/module/views/GestureHandler.android.js +2 -0
  48. package/lib/module/views/GestureHandler.android.js.map +1 -0
  49. package/lib/module/views/GestureHandler.ios.js +2 -0
  50. package/lib/module/views/GestureHandler.ios.js.map +1 -0
  51. package/lib/module/views/GestureHandler.js +21 -0
  52. package/lib/module/views/GestureHandler.js.map +1 -0
  53. package/lib/module/views/GestureHandlerNative.js +11 -0
  54. package/lib/module/views/GestureHandlerNative.js.map +1 -0
  55. package/lib/module/views/legacy/Drawer.js +409 -0
  56. package/lib/module/views/legacy/Drawer.js.map +1 -0
  57. package/lib/module/views/legacy/Overlay.js +64 -0
  58. package/lib/module/views/legacy/Overlay.js.map +1 -0
  59. package/lib/module/views/modern/Drawer.js +276 -0
  60. package/lib/module/views/modern/Drawer.js.map +1 -0
  61. package/lib/module/views/modern/Overlay.js +60 -0
  62. package/lib/module/views/modern/Overlay.js.map +1 -0
  63. package/lib/typescript/src/constants.d.ts +5 -0
  64. package/lib/typescript/src/constants.d.ts.map +1 -0
  65. package/lib/typescript/src/index.d.ts +5 -0
  66. package/lib/typescript/src/index.d.ts.map +1 -0
  67. package/lib/typescript/src/types.d.ts +110 -0
  68. package/lib/typescript/src/types.d.ts.map +1 -0
  69. package/lib/typescript/src/utils/DrawerGestureContext.d.ts +4 -0
  70. package/lib/typescript/src/utils/DrawerGestureContext.d.ts.map +1 -0
  71. package/lib/typescript/src/utils/DrawerProgressContext.d.ts +5 -0
  72. package/lib/typescript/src/utils/DrawerProgressContext.d.ts.map +1 -0
  73. package/lib/typescript/src/utils/useDrawerProgress.d.ts +3 -0
  74. package/lib/typescript/src/utils/useDrawerProgress.d.ts.map +1 -0
  75. package/lib/typescript/src/views/Drawer.d.ts +20 -0
  76. package/lib/typescript/src/views/Drawer.d.ts.map +1 -0
  77. package/lib/typescript/src/views/GestureHandler.android.d.ts +2 -0
  78. package/lib/typescript/src/views/GestureHandler.android.d.ts.map +1 -0
  79. package/lib/typescript/src/views/GestureHandler.d.ts +15 -0
  80. package/lib/typescript/src/views/GestureHandler.d.ts.map +1 -0
  81. package/lib/typescript/src/views/GestureHandler.ios.d.ts +2 -0
  82. package/lib/typescript/src/views/GestureHandler.ios.d.ts.map +1 -0
  83. package/lib/typescript/src/views/GestureHandlerNative.d.ts +6 -0
  84. package/lib/typescript/src/views/GestureHandlerNative.d.ts.map +1 -0
  85. package/lib/typescript/src/views/legacy/Drawer.d.ts +51 -0
  86. package/lib/typescript/src/views/legacy/Drawer.d.ts.map +1 -0
  87. package/lib/typescript/src/views/legacy/Overlay.d.ts +89 -0
  88. package/lib/typescript/src/views/legacy/Overlay.d.ts.map +1 -0
  89. package/lib/typescript/src/views/modern/Drawer.d.ts +10 -0
  90. package/lib/typescript/src/views/modern/Drawer.d.ts.map +1 -0
  91. package/lib/typescript/src/views/modern/Overlay.d.ts +89 -0
  92. package/lib/typescript/src/views/modern/Overlay.d.ts.map +1 -0
  93. package/package.json +54 -94
  94. package/src/constants.tsx +4 -0
  95. package/src/index.tsx +4 -0
  96. package/src/types.tsx +122 -0
  97. package/src/utils/DrawerGestureContext.tsx +3 -0
  98. package/src/utils/DrawerProgressContext.tsx +6 -0
  99. package/src/utils/useDrawerProgress.tsx +18 -0
  100. package/src/views/Drawer.tsx +122 -0
  101. package/src/views/GestureHandler.android.tsx +1 -0
  102. package/src/views/GestureHandler.ios.tsx +1 -0
  103. package/src/views/GestureHandler.tsx +29 -0
  104. package/src/views/GestureHandlerNative.tsx +24 -0
  105. package/src/views/legacy/Drawer.tsx +682 -0
  106. package/src/views/legacy/Overlay.tsx +87 -0
  107. package/src/views/modern/Drawer.tsx +413 -0
  108. package/src/views/modern/Overlay.tsx +82 -0
  109. package/dist/DrawerLayout.js +0 -430
@@ -1,430 +0,0 @@
1
- Object.defineProperty(exports, "__esModule", { value: true });exports.default = undefined;var _extends = Object.assign || function (target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i];for (var key in source) {if (Object.prototype.hasOwnProperty.call(source, key)) {target[key] = source[key];}}}return target;};var _createClass = function () {function defineProperties(target, props) {for (var i = 0; i < props.length; i++) {var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}return function (Constructor, protoProps, staticProps) {if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;};}();var _class,_temp,_jsxFileName = 'src/DrawerLayout.js';
2
- var _react = require('react');var _react2 = _interopRequireDefault(_react);
3
- var _reactNative = require('react-native');function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function _classCallCheck(instance, Constructor) {if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}function _possibleConstructorReturn(self, call) {if (!self) {throw new ReferenceError("this hasn't been initialised - super() hasn't been called");}return call && (typeof call === "object" || typeof call === "function") ? call : self;}function _inherits(subClass, superClass) {if (typeof superClass !== "function" && superClass !== null) {throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);}subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;}
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
-
13
-
14
- var MIN_SWIPE_DISTANCE = 3;
15
- var DEVICE_WIDTH = parseFloat(_reactNative.Dimensions.get('window').width);
16
- var THRESHOLD = DEVICE_WIDTH / 2;
17
- var VX_MAX = 0.1;
18
-
19
- var IDLE = 'Idle';
20
- var DRAGGING = 'Dragging';
21
- var SETTLING = 'Settling';var
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
- DrawerLayout = (_temp = _class = function (_Component) {_inherits(DrawerLayout, _Component);
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
-
72
-
73
-
74
-
75
-
76
-
77
-
78
-
79
-
80
-
81
- function DrawerLayout(props, context) {_classCallCheck(this, DrawerLayout);var _this = _possibleConstructorReturn(this, (DrawerLayout.__proto__ || Object.getPrototypeOf(DrawerLayout)).call(this,
82
- props, context));_this.
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
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
- _onOverlayClick = function (e) {
208
- e.stopPropagation();
209
- if (!_this._isLockedClosed() && !_this._isLockedOpen()) {
210
- _this.closeDrawer();
211
- }
212
- };_this.
213
-
214
- _emitStateChanged = function (newState) {
215
- if (_this.props.onDrawerStateChanged) {
216
- _this.props.onDrawerStateChanged(newState);
217
- }
218
- };_this.
219
-
220
- openDrawer = function () {var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
221
- _this._emitStateChanged(SETTLING);
222
- _reactNative.Animated.spring(_this.state.openValue, _extends({
223
- toValue: 1,
224
- bounciness: 0,
225
- restSpeedThreshold: 0.1,
226
- useNativeDriver: _this.props.useNativeAnimations },
227
- options)).
228
- start(function () {
229
- if (_this.props.onDrawerOpen) {
230
- _this.props.onDrawerOpen();
231
- }
232
- _this._emitStateChanged(IDLE);
233
- });
234
- };_this.
235
-
236
- closeDrawer = function () {var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
237
- _this._emitStateChanged(SETTLING);
238
- _reactNative.Animated.spring(_this.state.openValue, _extends({
239
- toValue: 0,
240
- bounciness: 0,
241
- restSpeedThreshold: 1,
242
- useNativeDriver: _this.props.useNativeAnimations },
243
- options)).
244
- start(function () {
245
- if (_this.props.onDrawerClose) {
246
- _this.props.onDrawerClose();
247
- }
248
- _this._emitStateChanged(IDLE);
249
- });
250
- };_this.
251
-
252
- _handleDrawerOpen = function () {
253
- if (_this.props.onDrawerOpen) {
254
- _this.props.onDrawerOpen();
255
- }
256
- };_this.
257
-
258
- _handleDrawerClose = function () {
259
- if (_this.props.onDrawerClose) {
260
- _this.props.onDrawerClose();
261
- }
262
- };_this.
263
-
264
- _shouldSetPanResponder = function (
265
- e, _ref)
266
-
267
- {var moveX = _ref.moveX,dx = _ref.dx,dy = _ref.dy;
268
- if (!dx || !dy || Math.abs(dx) < MIN_SWIPE_DISTANCE) {
269
- return false;
270
- }
271
-
272
- if (_this._isLockedClosed() || _this._isLockedOpen()) {
273
- return false;
274
- }
275
-
276
- if (_this.getDrawerPosition() === 'left') {
277
- var overlayArea = DEVICE_WIDTH - (
278
- DEVICE_WIDTH - _this.props.drawerWidth);
279
-
280
- if (_this._lastOpenValue === 1) {
281
- if (
282
- dx < 0 && Math.abs(dx) > Math.abs(dy) * 3 ||
283
- moveX > overlayArea)
284
- {
285
- _this._isClosing = true;
286
- _this._closingAnchorValue = _this._getOpenValueForX(moveX);
287
- return true;
288
- }
289
- } else {
290
- if (moveX <= 35 && dx > 0) {
291
- _this._isClosing = false;
292
- return true;
293
- }
294
-
295
- return false;
296
- }
297
- } else {
298
- var _overlayArea = DEVICE_WIDTH - _this.props.drawerWidth;
299
-
300
- if (_this._lastOpenValue === 1) {
301
- if (
302
- dx > 0 && Math.abs(dx) > Math.abs(dy) * 3 ||
303
- moveX < _overlayArea)
304
- {
305
- _this._isClosing = true;
306
- _this._closingAnchorValue = _this._getOpenValueForX(moveX);
307
- return true;
308
- }
309
- } else {
310
- if (moveX >= DEVICE_WIDTH - 35 && dx < 0) {
311
- _this._isClosing = false;
312
- return true;
313
- }
314
-
315
- return false;
316
- }
317
- }
318
- };_this.
319
-
320
- _panResponderGrant = function () {
321
- _this._emitStateChanged(DRAGGING);
322
- };_this.
323
-
324
- _panResponderMove = function (e, _ref2) {var moveX = _ref2.moveX;
325
- var openValue = _this._getOpenValueForX(moveX);
326
-
327
- if (_this._isClosing) {
328
- openValue = 1 - (_this._closingAnchorValue - openValue);
329
- }
330
-
331
- if (openValue > 1) {
332
- openValue = 1;
333
- } else if (openValue < 0) {
334
- openValue = 0;
335
- }
336
-
337
- _this.state.openValue.setValue(openValue);
338
- };_this.
339
-
340
- _panResponderRelease = function (
341
- e, _ref3)
342
-
343
- {var moveX = _ref3.moveX,vx = _ref3.vx;
344
- var previouslyOpen = _this._isClosing;
345
- var isWithinVelocityThreshold = vx < VX_MAX && vx > -VX_MAX;
346
-
347
- if (_this.getDrawerPosition() === 'left') {
348
- if (
349
- vx > 0 && moveX > THRESHOLD ||
350
- vx >= VX_MAX ||
351
- isWithinVelocityThreshold &&
352
- previouslyOpen &&
353
- moveX > THRESHOLD)
354
- {
355
- _this.openDrawer({ velocity: vx });
356
- } else if (
357
- vx < 0 && moveX < THRESHOLD ||
358
- vx < -VX_MAX ||
359
- isWithinVelocityThreshold && !previouslyOpen)
360
- {
361
- _this.closeDrawer({ velocity: vx });
362
- } else if (previouslyOpen) {
363
- _this.openDrawer();
364
- } else {
365
- _this.closeDrawer();
366
- }
367
- } else {
368
- if (
369
- vx < 0 && moveX < THRESHOLD ||
370
- vx <= -VX_MAX ||
371
- isWithinVelocityThreshold &&
372
- previouslyOpen &&
373
- moveX < THRESHOLD)
374
- {
375
- _this.openDrawer({ velocity: -1 * vx });
376
- } else if (
377
- vx > 0 && moveX > THRESHOLD ||
378
- vx > VX_MAX ||
379
- isWithinVelocityThreshold && !previouslyOpen)
380
- {
381
- _this.closeDrawer({ velocity: -1 * vx });
382
- } else if (previouslyOpen) {
383
- _this.openDrawer();
384
- } else {
385
- _this.closeDrawer();
386
- }
387
- }
388
- };_this.
389
-
390
- _isLockedClosed = function () {
391
- return _this.props.drawerLockMode === 'locked-closed' &&
392
- !_this.state.drawerShown;
393
- };_this.
394
-
395
- _isLockedOpen = function () {
396
- return _this.props.drawerLockMode === 'locked-open' &&
397
- _this.state.drawerShown;
398
- };_this.state = { accessibilityViewIsModal: false, drawerShown: false, openValue: new _reactNative.Animated.Value(0) };return _this;}_createClass(DrawerLayout, [{ key: 'getDrawerPosition', value: function getDrawerPosition() {var drawerPosition = this.props.drawerPosition;var rtl = _reactNative.I18nManager.isRTL;return rtl ? drawerPosition === 'left' ? 'right' : 'left' : drawerPosition;} }, { key: 'componentWillMount', value: function componentWillMount() {var _this2 = this;var openValue = this.state.openValue;openValue.addListener(function (_ref4) {var value = _ref4.value;var drawerShown = value > 0;var accessibilityViewIsModal = drawerShown;if (drawerShown !== _this2.state.drawerShown) {_this2.setState({ drawerShown: drawerShown, accessibilityViewIsModal: accessibilityViewIsModal });}if (_this2.props.keyboardDismissMode === 'on-drag') {_reactNative.Keyboard.dismiss();}_this2._lastOpenValue = value;if (_this2.props.onDrawerSlide) {_this2.props.onDrawerSlide({ nativeEvent: { offset: value } });}});this._panResponder = _reactNative.PanResponder.create({ onMoveShouldSetPanResponder: this._shouldSetPanResponder, onPanResponderGrant: this._panResponderGrant, onPanResponderMove: this._panResponderMove, onPanResponderTerminationRequest: function onPanResponderTerminationRequest() {return false;}, onPanResponderRelease: this._panResponderRelease, onPanResponderTerminate: function onPanResponderTerminate() {} });} }, { key: 'render', value: function render() {var _state = this.state,accessibilityViewIsModal = _state.accessibilityViewIsModal,drawerShown = _state.drawerShown,openValue = _state.openValue;var _props = this.props,drawerBackgroundColor = _props.drawerBackgroundColor,drawerWidth = _props.drawerWidth,drawerPosition = _props.drawerPosition;var dynamicDrawerStyles = { backgroundColor: drawerBackgroundColor, width: drawerWidth, left: drawerPosition === 'left' ? 0 : null, right: drawerPosition === 'right' ? 0 : null };var outputRange = void 0;if (this.getDrawerPosition() === 'left') {outputRange = [-drawerWidth, 0];} else {outputRange = [drawerWidth, 0];}var drawerTranslateX = openValue.interpolate({ inputRange: [0, 1], outputRange: outputRange, extrapolate: 'clamp' });var animatedDrawerStyles = { transform: [{ translateX: drawerTranslateX }] };var overlayOpacity = openValue.interpolate({ inputRange: [0, 1], outputRange: [0, 0.7], extrapolate: 'clamp' });var animatedOverlayStyles = { opacity: overlayOpacity };var pointerEvents = drawerShown ? 'auto' : 'none';return _react2.default.createElement(_reactNative.View, _extends({ style: { flex: 1, backgroundColor: 'transparent' } }, this._panResponder.panHandlers, { __source: { fileName: _jsxFileName, lineNumber: 177 } }), _react2.default.createElement(_reactNative.Animated.View, { style: styles.main, __source: { fileName: _jsxFileName, lineNumber: 181 } }, this.props.children), _react2.default.createElement(_reactNative.TouchableWithoutFeedback, { pointerEvents: pointerEvents, onPress: this._onOverlayClick, __source: { fileName: _jsxFileName, lineNumber: 184 } }, _react2.default.createElement(_reactNative.Animated.View, { pointerEvents: pointerEvents, style: [styles.overlay, animatedOverlayStyles], __source: { fileName: _jsxFileName, lineNumber: 188 } })), _react2.default.createElement(_reactNative.Animated.View, { accessibilityViewIsModal: accessibilityViewIsModal, style: [styles.drawer, dynamicDrawerStyles, animatedDrawerStyles], __source: { fileName: _jsxFileName, lineNumber: 193 } }, this.props.renderNavigationView()));} }, { key: '_getOpenValueForX', value: function _getOpenValueForX(
399
-
400
- x) {var
401
- drawerWidth = this.props.drawerWidth;
402
-
403
- if (this.getDrawerPosition() === 'left') {
404
- return x / drawerWidth;
405
- }
406
-
407
-
408
- return (DEVICE_WIDTH - x) / drawerWidth;
409
- } }]);return DrawerLayout;}(_react.Component), _class.defaultProps = { drawerWidth: 0, drawerPosition: 'left', useNativeAnimations: false }, _class.positions = { Left: 'left', Right: 'right' }, _temp);exports.default = DrawerLayout;
410
-
411
-
412
- var styles = _reactNative.StyleSheet.create({
413
- drawer: {
414
- position: 'absolute',
415
- top: 0,
416
- bottom: 0,
417
- zIndex: 1001 },
418
-
419
- main: {
420
- flex: 1,
421
- zIndex: 0 },
422
-
423
- overlay: {
424
- backgroundColor: '#000',
425
- position: 'absolute',
426
- top: 0,
427
- left: 0,
428
- bottom: 0,
429
- right: 0,
430
- zIndex: 1000 } });