react-native-drawer-layout 1.3.2 → 3.0.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 -34
  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 +418 -0
  26. package/lib/commonjs/views/legacy/Drawer.js.map +1 -0
  27. package/lib/commonjs/views/legacy/Overlay.js +71 -0
  28. package/lib/commonjs/views/legacy/Overlay.js.map +1 -0
  29. package/lib/commonjs/views/modern/Drawer.js +284 -0
  30. package/lib/commonjs/views/modern/Drawer.js.map +1 -0
  31. package/lib/commonjs/views/modern/Overlay.js +66 -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 +408 -0
  56. package/lib/module/views/legacy/Drawer.js.map +1 -0
  57. package/lib/module/views/legacy/Overlay.js +61 -0
  58. package/lib/module/views/legacy/Overlay.js.map +1 -0
  59. package/lib/module/views/modern/Drawer.js +275 -0
  60. package/lib/module/views/modern/Drawer.js.map +1 -0
  61. package/lib/module/views/modern/Overlay.js +57 -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 +105 -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 +88 -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 +88 -0
  92. package/lib/typescript/src/views/modern/Overlay.d.ts.map +1 -0
  93. package/package.json +51 -93
  94. package/src/constants.tsx +4 -0
  95. package/src/index.tsx +4 -0
  96. package/src/types.tsx +116 -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 +681 -0
  106. package/src/views/legacy/Overlay.tsx +75 -0
  107. package/src/views/modern/Drawer.tsx +412 -0
  108. package/src/views/modern/Overlay.tsx +70 -0
  109. package/dist/DrawerLayout.js +0 -419
@@ -1,419 +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;
2
- var _react = require('react');var _react2 = _interopRequireDefault(_react);
3
- var _reactNativeDismissKeyboard = require('react-native-dismiss-keyboard');var _reactNativeDismissKeyboard2 = _interopRequireDefault(_reactNativeDismissKeyboard);
4
- 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;}
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
- _onOverlayClick = function (e) {
201
- e.stopPropagation();
202
- if (!_this._isLockedClosed() && !_this._isLockedOpen()) {
203
- _this.closeDrawer();
204
- }
205
- };_this.
206
-
207
- _emitStateChanged = function (newState) {
208
- if (_this.props.onDrawerStateChanged) {
209
- _this.props.onDrawerStateChanged(newState);
210
- }
211
- };_this.
212
-
213
- openDrawer = function () {var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
214
- _this._emitStateChanged(SETTLING);
215
- _reactNative.Animated.spring(_this.state.openValue, _extends({
216
- toValue: 1,
217
- bounciness: 0,
218
- restSpeedThreshold: 0.1,
219
- useNativeDriver: _this.props.useNativeAnimations },
220
- options)).
221
-
222
- start(function () {
223
- if (_this.props.onDrawerOpen) {
224
- _this.props.onDrawerOpen();
225
- }
226
- _this._emitStateChanged(IDLE);
227
- });
228
- };_this.
229
-
230
- closeDrawer = function () {var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
231
- _this._emitStateChanged(SETTLING);
232
- _reactNative.Animated.spring(_this.state.openValue, _extends({
233
- toValue: 0,
234
- bounciness: 0,
235
- restSpeedThreshold: 1,
236
- useNativeDriver: _this.props.useNativeAnimations },
237
- options)).
238
-
239
- start(function () {
240
- if (_this.props.onDrawerClose) {
241
- _this.props.onDrawerClose();
242
- }
243
- _this._emitStateChanged(IDLE);
244
- });
245
- };_this.
246
-
247
- _handleDrawerOpen = function () {
248
- if (_this.props.onDrawerOpen) {
249
- _this.props.onDrawerOpen();
250
- }
251
- };_this.
252
-
253
- _handleDrawerClose = function () {
254
- if (_this.props.onDrawerClose) {
255
- _this.props.onDrawerClose();
256
- }
257
- };_this.
258
-
259
- _shouldSetPanResponder = function (
260
- e, _ref)
261
-
262
- {var moveX = _ref.moveX,dx = _ref.dx,dy = _ref.dy;
263
- if (!dx || !dy || Math.abs(dx) < MIN_SWIPE_DISTANCE) {
264
- return false;
265
- }
266
-
267
- if (_this._isLockedClosed() || _this._isLockedOpen()) {
268
- return false;
269
- }
270
-
271
- if (_this.getDrawerPosition() === 'left') {
272
- var overlayArea = DEVICE_WIDTH - (
273
- DEVICE_WIDTH - _this.props.drawerWidth);
274
-
275
- if (_this._lastOpenValue === 1) {
276
- if (
277
- dx < 0 && Math.abs(dx) > Math.abs(dy) * 3 || moveX > overlayArea)
278
- {
279
- _this._isClosing = true;
280
- _this._closingAnchorValue = _this._getOpenValueForX(moveX);
281
- return true;
282
- }
283
- } else {
284
- if (moveX <= 35 && dx > 0) {
285
- _this._isClosing = false;
286
- return true;
287
- }
288
-
289
- return false;
290
- }
291
- } else {
292
- var _overlayArea = DEVICE_WIDTH - _this.props.drawerWidth;
293
-
294
- if (_this._lastOpenValue === 1) {
295
- if (
296
- dx > 0 && Math.abs(dx) > Math.abs(dy) * 3 || moveX < _overlayArea)
297
- {
298
- _this._isClosing = true;
299
- _this._closingAnchorValue = _this._getOpenValueForX(moveX);
300
- return true;
301
- }
302
- } else {
303
- if (moveX >= DEVICE_WIDTH - 35 && dx < 0) {
304
- _this._isClosing = false;
305
- return true;
306
- }
307
-
308
- return false;
309
- }
310
- }
311
- };_this.
312
-
313
- _panResponderGrant = function () {
314
- _this._emitStateChanged(DRAGGING);
315
- };_this.
316
-
317
- _panResponderMove = function (e, _ref2) {var moveX = _ref2.moveX;
318
- var openValue = _this._getOpenValueForX(moveX);
319
-
320
- if (_this._isClosing) {
321
- openValue = 1 - (_this._closingAnchorValue - openValue);
322
- }
323
-
324
- if (openValue > 1) {
325
- openValue = 1;
326
- } else if (openValue < 0) {
327
- openValue = 0;
328
- }
329
-
330
- _this.state.openValue.setValue(openValue);
331
- };_this.
332
-
333
- _panResponderRelease = function (
334
- e, _ref3)
335
-
336
- {var moveX = _ref3.moveX,vx = _ref3.vx;
337
- var previouslyOpen = _this._isClosing;
338
- var isWithinVelocityThreshold = vx < VX_MAX && vx > -VX_MAX;
339
-
340
- if (_this.getDrawerPosition() === 'left') {
341
- if (
342
- vx > 0 && moveX > THRESHOLD ||
343
- vx >= VX_MAX ||
344
- isWithinVelocityThreshold && previouslyOpen && moveX > THRESHOLD)
345
- {
346
- _this.openDrawer({ velocity: vx });
347
- } else if (
348
- vx < 0 && moveX < THRESHOLD ||
349
- vx < -VX_MAX ||
350
- isWithinVelocityThreshold && !previouslyOpen)
351
- {
352
- _this.closeDrawer({ velocity: vx });
353
- } else if (previouslyOpen) {
354
- _this.openDrawer();
355
- } else {
356
- _this.closeDrawer();
357
- }
358
- } else {
359
- if (
360
- vx < 0 && moveX < THRESHOLD ||
361
- vx <= -VX_MAX ||
362
- isWithinVelocityThreshold && previouslyOpen && moveX < THRESHOLD)
363
- {
364
- _this.openDrawer({ velocity: -1 * vx });
365
- } else if (
366
- vx > 0 && moveX > THRESHOLD ||
367
- vx > VX_MAX ||
368
- isWithinVelocityThreshold && !previouslyOpen)
369
- {
370
- _this.closeDrawer({ velocity: -1 * vx });
371
- } else if (previouslyOpen) {
372
- _this.openDrawer();
373
- } else {
374
- _this.closeDrawer();
375
- }
376
- }
377
- };_this.
378
-
379
- _isLockedClosed = function () {
380
- return _this.props.drawerLockMode === 'locked-closed' &&
381
- !_this.state.drawerShown;
382
- };_this.
383
-
384
- _isLockedOpen = function () {
385
- return _this.props.drawerLockMode === 'locked-open' &&
386
- _this.state.drawerShown;
387
- };_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') {(0, _reactNativeDismissKeyboard2.default)();}_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), _react2.default.createElement(_reactNative.Animated.View, { style: styles.main }, this.props.children), _react2.default.createElement(_reactNative.TouchableWithoutFeedback, { pointerEvents: pointerEvents, onPress: this._onOverlayClick }, _react2.default.createElement(_reactNative.Animated.View, { pointerEvents: pointerEvents, style: [styles.overlay, animatedOverlayStyles] })), _react2.default.createElement(_reactNative.Animated.View, { accessibilityViewIsModal: accessibilityViewIsModal, style: [styles.drawer, dynamicDrawerStyles, animatedDrawerStyles] }, this.props.renderNavigationView()));} }, { key: '_getOpenValueForX', value: function _getOpenValueForX(
388
-
389
- x) {var
390
- drawerWidth = this.props.drawerWidth;
391
-
392
- if (this.getDrawerPosition() === 'left') {
393
- return x / drawerWidth;
394
- }
395
-
396
-
397
- return (DEVICE_WIDTH - x) / drawerWidth;
398
- } }]);return DrawerLayout;}(_react.Component), _class.defaultProps = { drawerWidth: 0, drawerPosition: 'left', useNativeAnimations: false }, _class.positions = { Left: 'left', Right: 'right' }, _temp);exports.default = DrawerLayout;
399
-
400
-
401
- var styles = _reactNative.StyleSheet.create({
402
- drawer: {
403
- position: 'absolute',
404
- top: 0,
405
- bottom: 0,
406
- zIndex: 1001 },
407
-
408
- main: {
409
- flex: 1,
410
- zIndex: 0 },
411
-
412
- overlay: {
413
- backgroundColor: '#000',
414
- position: 'absolute',
415
- top: 0,
416
- left: 0,
417
- bottom: 0,
418
- right: 0,
419
- zIndex: 1000 } });