@wavemaker/rn-codegen 12.0.0-next.45002 → 12.0.0-next.45006

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 (105) hide show
  1. rn-codegen/command.js +19 -8
  2. rn-codegen/command.js.map +1 -1
  3. rn-codegen/index.js +26 -0
  4. rn-codegen/index.js.map +1 -1
  5. rn-codegen/package.json +42 -42
  6. rn-codegen/src/app.generator.js +4 -2
  7. rn-codegen/src/app.generator.js.map +1 -1
  8. rn-codegen/src/templates/app.template +42 -30
  9. rn-codegen/src/templates/babel.config.js.template +7 -1
  10. rn-codegen/src/templates/component/component.template +2 -3
  11. rn-codegen/src/templates/package.web.json +52 -53
  12. rn-codegen/src/templates/project/app.json +11 -1
  13. rn-codegen/src/templates/project/esbuild/@react-navigation/drawer/6.6.3/lib/module/views/modern/Drawer.js +303 -0
  14. rn-codegen/src/templates/project/esbuild/@react-navigation/drawer/6.6.3/lib/module/views/modern/Overlay.js +60 -0
  15. rn-codegen/src/templates/project/esbuild/esbuild.script.js +113 -2
  16. rn-codegen/src/templates/project/metro.config.js +2 -0
  17. rn-codegen/src/templates/project/package-lock.json +5671 -6017
  18. rn-codegen/src/templates/project/package.json +52 -54
  19. rn-codegen/src/templates/project/revert-to-1.0.styles.js +31 -6
  20. rn-codegen/src/templates/project/scripts/post-build.js +13 -0
  21. rn-codegen/src/templates/variables.template +10 -0
  22. rn-codegen/src/theme/components/basic/lottie.styledef.js +6 -0
  23. rn-codegen/src/theme/components/basic/lottie.styledef.js.map +1 -1
  24. rn-codegen/src/theme/components/chart/area-chart.styledef.js +7 -1
  25. rn-codegen/src/theme/components/chart/area-chart.styledef.js.map +1 -1
  26. rn-codegen/src/theme/components/chart/bar-chart.styledef.js +7 -1
  27. rn-codegen/src/theme/components/chart/bar-chart.styledef.js.map +1 -1
  28. rn-codegen/src/theme/components/chart/bubble-chart.styledef.js +7 -1
  29. rn-codegen/src/theme/components/chart/bubble-chart.styledef.js.map +1 -1
  30. rn-codegen/src/theme/components/chart/column-chart.styledef.js +7 -1
  31. rn-codegen/src/theme/components/chart/column-chart.styledef.js.map +1 -1
  32. rn-codegen/src/theme/components/chart/donut-chart.styledef.js +30 -1
  33. rn-codegen/src/theme/components/chart/donut-chart.styledef.js.map +1 -1
  34. rn-codegen/src/theme/components/chart/line-chart.styledef.js +7 -0
  35. rn-codegen/src/theme/components/chart/line-chart.styledef.js.map +1 -1
  36. rn-codegen/src/theme/components/chart/pie-chart.styledef.js +27 -0
  37. rn-codegen/src/theme/components/chart/pie-chart.styledef.js.map +1 -1
  38. rn-codegen/src/theme/components/container/wizard.styledef.js +4 -0
  39. rn-codegen/src/theme/components/container/wizard.styledef.js.map +1 -1
  40. rn-codegen/src/theme/components/data/list/list-action-template.styledef.js +18 -0
  41. rn-codegen/src/theme/components/data/list/list-action-template.styledef.js.map +1 -0
  42. rn-codegen/src/theme/components/input/epoch/datetime.styledef.js +9 -1
  43. rn-codegen/src/theme/components/input/epoch/datetime.styledef.js.map +1 -1
  44. rn-codegen/src/theme/components/input/slider.styledef.js +40 -0
  45. rn-codegen/src/theme/components/input/slider.styledef.js.map +1 -1
  46. rn-codegen/src/theme/components/input/switch.styledef.js +10 -0
  47. rn-codegen/src/theme/components/input/switch.styledef.js.map +1 -1
  48. rn-codegen/src/theme/components/style-definition.provider.js +2 -0
  49. rn-codegen/src/theme/components/style-definition.provider.js.map +1 -1
  50. rn-codegen/src/theme/variables.js +6 -0
  51. rn-codegen/src/theme/variables.js.map +1 -1
  52. rn-codegen/src/transpile/components/advanced/carousel/carousel-template.transformer.js +2 -2
  53. rn-codegen/src/transpile/components/advanced/carousel/carousel-template.transformer.js.map +1 -1
  54. rn-codegen/src/transpile/components/basic/search.transformer.js +2 -1
  55. rn-codegen/src/transpile/components/basic/search.transformer.js.map +1 -1
  56. rn-codegen/src/transpile/components/chart/area-chart.transformer.js +4 -1
  57. rn-codegen/src/transpile/components/chart/area-chart.transformer.js.map +1 -1
  58. rn-codegen/src/transpile/components/chart/bar-chart.transformer.js +4 -2
  59. rn-codegen/src/transpile/components/chart/bar-chart.transformer.js.map +1 -1
  60. rn-codegen/src/transpile/components/chart/bubble-chart.transformer.js +4 -2
  61. rn-codegen/src/transpile/components/chart/bubble-chart.transformer.js.map +1 -1
  62. rn-codegen/src/transpile/components/chart/column-chart.transformer.js +4 -2
  63. rn-codegen/src/transpile/components/chart/column-chart.transformer.js.map +1 -1
  64. rn-codegen/src/transpile/components/chart/donut-chart.transformer.js +4 -2
  65. rn-codegen/src/transpile/components/chart/donut-chart.transformer.js.map +1 -1
  66. rn-codegen/src/transpile/components/chart/line-chart.transformer.js +4 -2
  67. rn-codegen/src/transpile/components/chart/line-chart.transformer.js.map +1 -1
  68. rn-codegen/src/transpile/components/chart/pie-chart.transformer.js +4 -2
  69. rn-codegen/src/transpile/components/chart/pie-chart.transformer.js.map +1 -1
  70. rn-codegen/src/transpile/components/chart/stack-chart.transformer.js +4 -2
  71. rn-codegen/src/transpile/components/chart/stack-chart.transformer.js.map +1 -1
  72. rn-codegen/src/transpile/components/data/list/list-action-template.transformer.js +15 -0
  73. rn-codegen/src/transpile/components/data/list/list-action-template.transformer.js.map +1 -0
  74. rn-codegen/src/transpile/components/data/list/list-content.transformer.js +35 -0
  75. rn-codegen/src/transpile/components/data/list/list-content.transformer.js.map +1 -0
  76. rn-codegen/src/transpile/components/data/list/list-template.transformer.js +0 -25
  77. rn-codegen/src/transpile/components/data/list/list-template.transformer.js.map +1 -1
  78. rn-codegen/src/transpile/components/data/list.transformer.js +29 -3
  79. rn-codegen/src/transpile/components/data/list.transformer.js.map +1 -1
  80. rn-codegen/src/transpile/components/input/checkboxset.transformer.js +3 -1
  81. rn-codegen/src/transpile/components/input/checkboxset.transformer.js.map +1 -1
  82. rn-codegen/src/transpile/components/input/radioset.transformer.js +2 -1
  83. rn-codegen/src/transpile/components/input/radioset.transformer.js.map +1 -1
  84. rn-codegen/src/transpile/components/input/slider.transformer.js +15 -1
  85. rn-codegen/src/transpile/components/input/slider.transformer.js.map +1 -1
  86. rn-codegen/src/transpile/components/page/partial-container.transformer.js +1 -1
  87. rn-codegen/src/transpile/components/page/partial-container.transformer.js.map +1 -1
  88. rn-codegen/src/transpile/components/prefab/prefab.transformer.js +1 -1
  89. rn-codegen/src/transpile/components/prefab/prefab.transformer.js.map +1 -1
  90. rn-codegen/src/transpile/components/transform-register.js +4 -0
  91. rn-codegen/src/transpile/components/transform-register.js.map +1 -1
  92. rn-codegen/src/transpile/components/utils.js +20 -1
  93. rn-codegen/src/transpile/components/utils.js.map +1 -1
  94. rn-codegen/src/transpile/property/property-parser.js +21 -8
  95. rn-codegen/src/transpile/property/property-parser.js.map +1 -1
  96. rn-codegen/src/transpile/style/background-image.parser.js +1 -1
  97. rn-codegen/src/transpile/style/background-image.parser.js.map +1 -1
  98. rn-codegen/src/transpile/style/dimension-style.parser.js +5 -0
  99. rn-codegen/src/transpile/style/dimension-style.parser.js.map +1 -1
  100. rn-codegen/src/transpile/transpile.js +11 -4
  101. rn-codegen/src/transpile/transpile.js.map +1 -1
  102. rn-codegen/src/utils.js +1 -20
  103. rn-codegen/src/utils.js.map +1 -1
  104. rn-codegen/src/variables/variable.transformer.js +8 -1
  105. rn-codegen/src/variables/variable.transformer.js.map +1 -1
@@ -15,6 +15,7 @@ import BaseApp from '@wavemaker/app-rn-runtime/runtime/App';
15
15
  import { WmMemo } from '@wavemaker/app-rn-runtime/runtime/memo.component';
16
16
  {{#if sslPinning}}
17
17
  import { initializeSslPinning, isSslPinningAvailable } from 'react-native-ssl-public-key-pinning';
18
+ import { getPublicHashKey } from '@wavemaker/react-native-ssl-publickey';
18
19
  {{/if}}
19
20
 
20
21
  import { isWebPreviewMode } from '@wavemaker/app-rn-runtime/core/utils';
@@ -68,11 +69,11 @@ class App extends BaseApp {
68
69
  }
69
70
 
70
71
  getServiceDefinitions() {
72
+ {{#if profile.useLocalMetadata}}
73
+ return Promise.resolve(require('./metadata/app/service-definitions.json'))
74
+ {{else}}
71
75
  return axios.get(this.baseUrl + '/services/servicedefs')
72
76
  .then((response) => response?.data || {})
73
- {{#if profile.useLocalMetadata}}
74
- .catch(() => import('./metadata/app/service-definitions.json').then(mod => mod.default))
75
- {{else}}
76
77
  .catch(() => ({}))
77
78
  {{/if}}
78
79
  .then(data => {
@@ -92,13 +93,14 @@ class App extends BaseApp {
92
93
  }
93
94
 
94
95
  loadWmProperties() {
96
+ {{#if profile.useLocalMetadata}}
97
+ return Promise.resolve(require('./src/wmProperties').default)
98
+ {{else}}
95
99
  return axios.get(this.baseUrl + '/services/application/wmProperties.js')
96
100
  .then((response) => {
97
101
  const data = response.data;
98
102
  return JSON.parse(data.substring(data.indexOf('{'), data.length - 1));
99
103
  })
100
- {{#if profile.useLocalMetadata}}
101
- .catch(() => import('./src/wmProperties').then(mod => mod.default))
102
104
  {{/if}}
103
105
  .then(appProperties => {
104
106
  this.appConfig.appProperties = appProperties;
@@ -242,9 +244,21 @@ class App extends BaseApp {
242
244
 
243
245
 
244
246
  {{#if sslPinning}}
245
- initSSLPininng() {
247
+ async initSSLPininng() {
248
+ let sslPinning = {{{stringify sslPinning}}}
246
249
  if (isSslPinningAvailable()) {
247
- return initializeSslPinning({{{stringify sslPinning}}}).then(() => true);
250
+ const updatedSslPinning = {};
251
+
252
+ for (const key of Object.keys(sslPinning)) {
253
+ const value = sslPinning[key];
254
+ if (value.loadOnStartup) {
255
+ const publickey = await getPublicHashKey(key);
256
+ value.publicKeyHashes = [(publickey), "NoBackUpKey" + publickey.substring(11)];
257
+ }
258
+ updatedSslPinning[key] = value; // Update the modified object
259
+ }
260
+
261
+ return initializeSslPinning(updatedSslPinning).then(() => true);
248
262
  }
249
263
  return Promise.resolve(false);
250
264
  }
@@ -254,33 +268,31 @@ class App extends BaseApp {
254
268
  {{#if animatedSplash}}
255
269
  SplashScreen.hideAsync().then(() => {});{{/if}}
256
270
  this.appConfig.getServiceDefinitions = this.getServiceDefinitions.bind(this);
257
- NetworkService.start(this.appConfig)
258
- {{#if profile.useLocalMetadata}}
259
- {{else}}
260
- .then(() => {
261
- NetworkService.connect(true);
262
- })
263
- {{/if}}
264
- .then(() => {console.log('NetworkService started')})
265
- .then(() => this.loadWmProperties())
266
- .then(() => {console.log('WmProperties loaded')})
267
- {{#if sslPinning}}
268
- .then(() => this.initSSLPininng())
269
- .then((flag) => {flag && console.log('SSL Pinning loaded')})
270
- {{/if}}
271
- .then(() => this.loadTheme())
271
+ Promise.all([
272
+ NetworkService.start(this.appConfig)
273
+ {{#if profile.useLocalMetadata}}
274
+ {{else}}
275
+ .then(() => {
276
+ NetworkService.connect(true);
277
+ })
278
+ {{/if}},
279
+ this.getSecurityInfo()
280
+ .then(() => {console.log('Security info loaded')}),
281
+ this.loadWmProperties()
282
+ {{#if sslPinning}}
283
+ .then(() => this.initSSLPininng())
284
+ .then((flag) => {flag && console.log('SSL Pinning loaded')})
285
+ {{/if}}
286
+ .then(() => this.loadTheme())
272
287
  .then(() => {console.log('Theme loaded')})
273
- .then(() => AppI18nService.init())
274
- .then(() => this.changeLocale())
288
+ .then(() => AppI18nService.init())
289
+ .then(() => this.changeLocale())
275
290
  .then(() => {console.log('Locale files loaded')})
276
- .then(() => this.getSecurityInfo())
277
- .then(() => {console.log('Security info loaded')})
278
- .then(() => this.loadFonts())
291
+ .then(() => this.loadFonts())
279
292
  .then(() => {console.log('Font files loaded')})
280
- .then(() => initializeDeviceOperations())
293
+ .then(() => initializeDeviceOperations())
281
294
  .then(() => {console.log('Loaded device operations loaded')})
282
- .then(() => this.bootstrap())
283
- .then(() => {console.log('Bootstrap Complete')})
295
+ .then(() => this.bootstrap())])
284
296
  .then(() => super.componentDidMount())
285
297
  .catch(error => {
286
298
  console.error(error);
@@ -2,7 +2,13 @@ module.exports = function(api) {
2
2
  api.cache(true);
3
3
  return {
4
4
  presets: ['babel-preset-expo'],
5
- plugins: ['react-native-reanimated/plugin',{{#if enableLogs}} {{else}}'transform-remove-console'{{/if}}],
5
+ plugins: [
6
+ {{#if enableLogs}} {{else}}'transform-remove-console', {{/if}}
7
+ ['@babel/plugin-transform-class-static-block', { "loose": true }],
8
+ ['@babel/plugin-transform-class-properties', { "loose": true }],
9
+ '@babel/plugin-proposal-export-namespace-from',
10
+ 'react-native-reanimated/plugin'
11
+ ],
6
12
  overrides: [{
7
13
  test: './src',
8
14
  plugins: ['./scripts/wm-babel.transform.plugin.js']
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
 
3
- import { ScrollView } from 'react-native';
3
+ import { ScrollView } from 'react-native-gesture-handler';
4
4
 
5
5
  import { AssetProvider } from '@wavemaker/app-rn-runtime/core/asset.provider';
6
6
  import Base{{typeLabel}} from '@wavemaker/app-rn-runtime/runtime/base-{{lType}}.component';
@@ -89,8 +89,7 @@ export default class {{name}}{{typeLabel}} extends Base{{typeLabel}} {
89
89
  componentDidMount() {
90
90
  {{#ifEquals lType 'prefab' this}}
91
91
  {{#if profile.useLocalMetadata}}
92
- import('../../../service-definitions.json')
93
- .then(mod => mod.default?.serviceDefs)
92
+ Promise.resolve(require('../../../service-definitions.json').serviceDefs)
94
93
  {{else}}
95
94
  this.getServiceDefinitions()
96
95
  {{/if}}
@@ -9,66 +9,68 @@
9
9
  "postinstall": "echo \"\""
10
10
  },
11
11
  "dependencies": {
12
- "@unimodules/react-native-adapter": "6.3.9",
13
- "@wavemaker/app-rn-runtime": "12.0.0-next.45002",
14
- "@wavemaker/variables": "12.0.0-next.45002",
15
- "@wavemaker/rn-codegen": "12.0.0-next.45002",
16
- "axios": "^1.4.0",
17
- "css-mediaquery": "^0.1.2",
18
- "deprecated-react-native-prop-types": "~4.1.0",
19
- "expo": "49.0.7",
20
- "@expo/vector-icons": "13.0.0",
21
- "expo-font": "11.4.0",
22
- "expo-file-system": "15.4.3",
23
- "expo-camera": "13.4.2",
24
- "expo-av": "13.4.1",
25
- "expo-barcode-scanner": "12.5.3",
26
- "expo-web-browser": "12.3.2",
27
- "expo-device": "5.4.0",
28
- "expo-network": "5.4.0",
29
- "expo-location": "16.1.0",
30
- "expo-localization": "14.3.0",
31
- "expo-contacts": "12.2.0",
32
- "expo-calendar": "11.3.0",
33
- "expo-splash-screen": "0.20.5",
34
- "expo-document-picker": "11.5.4",
35
- "expo-constants": "14.4.2",
12
+ "@wavemaker/app-rn-runtime": "12.0.0-next.45006",
13
+ "@wavemaker/variables": "12.0.0-next.45006",
14
+ "@wavemaker/rn-codegen": "12.0.0-next.45006",
15
+ "deprecated-react-native-prop-types": "4.1.0",
16
+ "expo": "50.0.17",
17
+ "expo-build-properties": "0.12.0",
18
+ "@expo/vector-icons": "14.0.0",
19
+ "@expo/metro-runtime": "3.1.3",
20
+ "expo-font": "11.10.3",
21
+ "expo-file-system": "16.0.9",
22
+ "expo-camera": "14.1.3",
23
+ "expo-av": "13.10.6",
24
+ "expo-barcode-scanner": "12.9.3",
25
+ "expo-web-browser": "12.8.2",
26
+ "expo-device": "5.9.4",
27
+ "expo-network": "5.8.0",
28
+ "expo-location": "16.5.5",
29
+ "expo-localization": "14.8.4",
30
+ "expo-contacts": "12.8.2",
31
+ "expo-calendar": "12.2.1",
32
+ "expo-splash-screen": "0.26.5",
33
+ "expo-document-picker": "11.10.1",
34
+ "expo-constants": "15.4.6",
35
+ "expo-modules-core": "1.11.13",
36
36
  "@react-native/assets": "1.0.0",
37
37
  "hermes-engine": "0.11.0",
38
- "imask": "^7.5.0",
38
+ "imask": "7.6.0",
39
39
  "react": "18.2.0",
40
40
  "react-dom": "18.2.0",
41
- "react-native": "0.72.4",
42
- "react-native-web": "0.18.12",
43
- "@react-native-async-storage/async-storage": "1.18.2",
44
- "@react-native-community/netinfo": "9.3.10",
45
- "react-native-gesture-handler": "2.12.1",
46
- "react-native-reanimated": "^1.13.2",
41
+ "react-native": "0.73.6",
42
+ "react-native-web": "0.19.6",
43
+ "@react-native/assets-registry": "0.74.83",
44
+ "@react-native-async-storage/async-storage": "1.21.0",
45
+ "@react-native-community/netinfo": "11.1.0",
46
+ "react-native-gesture-handler": "2.14.0",
47
+ "react-native-reanimated": "3.6.2",
47
48
  "react-native-bundle-splitter": "2.2.3",
48
- "react-native-safe-area-context": "4.6.3",
49
- "@react-native-community/datetimepicker": "7.2.0",
50
- "@react-native-community/slider": "4.4.2",
51
- "react-native-circular-progress": "1.3.9",
52
- "@react-native-masked-view/masked-view": "0.2.9",
49
+ "react-native-safe-area-context": "4.8.2",
50
+ "@react-native-community/datetimepicker": "7.6.3",
51
+ "@react-native-community/slider": "4.5.2",
52
+ "react-native-circular-progress": "1.4.0",
53
+ "@react-native-masked-view/masked-view": "0.3.0",
53
54
  "react-native-snap-carousel": "3.9.1",
54
55
  "react-native-svg": "13.4.0",
55
- "react-native-ssl-public-key-pinning": "1.1.1",
56
+ "react-native-ssl-public-key-pinning": "1.2.3",
57
+ "@wavemaker/react-native-ssl-publickey": "1.0.2",
56
58
  "victory-native": "36.6.11",
57
59
  "@react-navigation/native": "6.1.7",
58
- "react-native-pager-view": "6.2.0",
59
- "react-native-webview": "13.2.2",
60
- "react-native-vector-icons": "10.0.0",
60
+ "react-native-pager-view": "6.2.3",
61
+ "react-native-webview": "13.6.4",
62
+ "react-native-vector-icons": "10.0.3",
61
63
  "@react-navigation/drawer": "6.6.3",
62
- "react-native-screens": "3.22.0",
63
- "react-native-svg-transformer": "1.0.0",
64
- "lottie-react-native": "5.1.6",
65
- "react-lottie-player": "1.5.4",
66
- "expo-linear-gradient": "12.3.0",
64
+ "react-native-screens": "3.29.0",
65
+ "react-native-svg-transformer": "1.3.0",
66
+ "lottie-react-native": "6.5.1",
67
+ "react-lottie-player": "2.0.0",
68
+ "expo-linear-gradient": "12.7.2",
67
69
  "setimmediate": "1.0.5",
68
70
  "react-native-restart": "0.0.27",
69
- "@expo/webpack-config": "18.0.1",
71
+ "@expo/webpack-config": "19.0.1",
70
72
  "@babel/core": "7.20.2",
71
- "@babel/standalone": "^7.23.10",
73
+ "@babel/standalone": "7.23.10",
72
74
  "@babel/plugin-syntax-jsx": "7.21.4",
73
75
  "victory": "^36.5.3"
74
76
  },
@@ -79,15 +81,12 @@
79
81
  "esbuild": "0.15.15",
80
82
  "esbuild-plugin-resolve": "1.0.3",
81
83
  "fs-extra": "10.0.0",
82
- "expo-modules-autolinking": "1.5.0",
84
+ "@babel/plugin-proposal-export-namespace-from": "7.18.9",
83
85
  "babel-plugin-transform-remove-console": "6.9.4",
84
86
  "@babel/plugin-proposal-optional-chaining": "7.21.0",
85
87
  "@babel/plugin-proposal-nullish-coalescing-operator": "7.18.6",
86
- "@types/babel__standalone": "^7.1.7"
87
- },
88
- "resolutions": {
89
- "react-error-overlay": "6.0.9",
90
- "react-native-reanimated": "3.4.1"
88
+ "@types/babel__standalone": "7.1.7",
89
+ "@expo/metro-config": "^0.7.1"
91
90
  },
92
91
  "private": true
93
92
  }
@@ -34,6 +34,16 @@
34
34
  "web": {
35
35
  "bundler": "metro",
36
36
  "favicon": "./assets/favicon.png"
37
- }
37
+ },
38
+ "plugins": [
39
+ [
40
+ "expo-build-properties",
41
+ {
42
+ "android": {
43
+ "useLegacyPackaging": true
44
+ }
45
+ }
46
+ ]
47
+ ]
38
48
  }
39
49
  }
@@ -0,0 +1,303 @@
1
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
2
+ import * as React from 'react';
3
+ import { I18nManager, InteractionManager, Keyboard, Platform, StatusBar, StyleSheet, View } from 'react-native';
4
+ import { PanGestureHandler, State as GestureState } from 'react-native-gesture-handler';
5
+ import Animated, { interpolate, runOnJS, useAnimatedGestureHandler, useAnimatedStyle, useDerivedValue, useSharedValue, withSpring } from 'react-native-reanimated';
6
+ import DrawerProgressContext from '../../utils/DrawerProgressContext';
7
+ import Overlay from './Overlay';
8
+ const SWIPE_DISTANCE_MINIMUM = 5;
9
+ const DEFAULT_DRAWER_WIDTH = '80%';
10
+ const minmax = (value, start, end) => {
11
+ 'worklet';
12
+
13
+ return Math.min(Math.max(value, start), end);
14
+ };
15
+ export default function Drawer(_ref) {
16
+ let {
17
+ dimensions,
18
+ drawerPosition,
19
+ drawerStyle,
20
+ drawerType,
21
+ gestureHandlerProps,
22
+ hideStatusBarOnOpen,
23
+ keyboardDismissMode,
24
+ onClose,
25
+ onOpen,
26
+ open,
27
+ overlayStyle,
28
+ renderDrawerContent,
29
+ renderSceneContent,
30
+ statusBarAnimation,
31
+ swipeDistanceThreshold,
32
+ swipeEdgeWidth,
33
+ swipeEnabled,
34
+ swipeVelocityThreshold,
35
+ overlayAccessibilityLabel
36
+ } = _ref;
37
+ const getDrawerWidth = () => {
38
+ const {
39
+ width = DEFAULT_DRAWER_WIDTH
40
+ } = StyleSheet.flatten(drawerStyle) || {};
41
+ if (typeof width === 'string' && width.endsWith('%')) {
42
+ // Try to calculate width if a percentage is given
43
+ const percentage = Number(width.replace(/%$/, ''));
44
+ if (Number.isFinite(percentage)) {
45
+ return dimensions.width * (percentage / 100);
46
+ }
47
+ }
48
+ return typeof width === 'number' ? width : 0;
49
+ };
50
+ const drawerWidth = getDrawerWidth();
51
+ const isOpen = drawerType === 'permanent' ? true : open;
52
+ const isRight = drawerPosition === 'right';
53
+ const getDrawerTranslationX = React.useCallback(open => {
54
+ 'worklet';
55
+
56
+ if (drawerPosition === 'left') {
57
+ return open ? 0 : -drawerWidth;
58
+ }
59
+ return open ? 0 : drawerWidth;
60
+ }, [drawerPosition, drawerWidth]);
61
+ const hideStatusBar = React.useCallback(hide => {
62
+ if (hideStatusBarOnOpen) {
63
+ StatusBar.setHidden(hide, statusBarAnimation);
64
+ }
65
+ }, [hideStatusBarOnOpen, statusBarAnimation]);
66
+ React.useEffect(() => {
67
+ hideStatusBar(isOpen);
68
+ return () => hideStatusBar(false);
69
+ }, [isOpen, hideStatusBarOnOpen, statusBarAnimation, hideStatusBar]);
70
+ const interactionHandleRef = React.useRef(null);
71
+ const startInteraction = () => {
72
+ interactionHandleRef.current = InteractionManager.createInteractionHandle();
73
+ };
74
+ const endInteraction = () => {
75
+ if (interactionHandleRef.current != null) {
76
+ InteractionManager.clearInteractionHandle(interactionHandleRef.current);
77
+ interactionHandleRef.current = null;
78
+ }
79
+ };
80
+ const hideKeyboard = () => {
81
+ if (keyboardDismissMode === 'on-drag') {
82
+ Keyboard.dismiss();
83
+ }
84
+ };
85
+ const onGestureStart = () => {
86
+ startInteraction();
87
+ hideKeyboard();
88
+ hideStatusBar(true);
89
+ };
90
+ const onGestureFinish = () => {
91
+ endInteraction();
92
+ };
93
+
94
+ // FIXME: Currently hitSlop is broken when on Android when drawer is on right
95
+ // https://github.com/software-mansion/react-native-gesture-handler/issues/569
96
+ const hitSlop = isRight ?
97
+ // Extend hitSlop to the side of the screen when drawer is closed
98
+ // This lets the user drag the drawer from the side of the screen
99
+ {
100
+ right: 0,
101
+ width: isOpen ? undefined : swipeEdgeWidth
102
+ } : {
103
+ left: 0,
104
+ width: isOpen ? undefined : swipeEdgeWidth
105
+ };
106
+ const touchStartX = useSharedValue(0);
107
+ const touchX = useSharedValue(0);
108
+ const translationX = useSharedValue(getDrawerTranslationX(open));
109
+ const gestureState = useSharedValue(GestureState.UNDETERMINED);
110
+ const toggleDrawer = React.useCallback(_ref2 => {
111
+ 'worklet';
112
+
113
+ let {
114
+ open,
115
+ isUserInitiated,
116
+ velocity
117
+ } = _ref2;
118
+ const translateX = getDrawerTranslationX(open);
119
+ touchStartX.value = 0;
120
+ touchX.value = 0;
121
+ translationX.value = withSpring(translateX, {
122
+ velocity,
123
+ stiffness: 1000,
124
+ damping: 500,
125
+ mass: 3,
126
+ overshootClamping: true,
127
+ restDisplacementThreshold: 0.01,
128
+ restSpeedThreshold: 0.01
129
+ });
130
+ if (!isUserInitiated) {
131
+ return;
132
+ }
133
+ if (open) {
134
+ runOnJS(onOpen)();
135
+ } else {
136
+ runOnJS(onClose)();
137
+ }
138
+ }, [getDrawerTranslationX, onClose, onOpen, touchStartX, touchX, translationX]);
139
+ React.useEffect(() => toggleDrawer({
140
+ open,
141
+ isUserInitiated: false
142
+ }), [open, toggleDrawer]);
143
+ const onGestureEvent = useAnimatedGestureHandler({
144
+ onStart: (event, ctx) => {
145
+ ctx.hasCalledOnStart = false;
146
+ ctx.startX = translationX.value;
147
+ gestureState.value = event.state;
148
+ touchStartX.value = event.x;
149
+ },
150
+ onActive: (event, ctx) => {
151
+ touchX.value = event.x;
152
+ translationX.value = ctx.startX + event.translationX;
153
+ gestureState.value = event.state;
154
+
155
+ // onStart will _always_ be called, even when the activation
156
+ // criteria isn't met yet. This makes sure onGestureStart is only
157
+ // called when the criteria is really met.
158
+ if (!ctx.hasCalledOnStart) {
159
+ ctx.hasCalledOnStart = true;
160
+ runOnJS(onGestureStart)();
161
+ }
162
+ },
163
+ onEnd: event => {
164
+ gestureState.value = event.state;
165
+ const nextOpen = Math.abs(event.translationX) > SWIPE_DISTANCE_MINIMUM && Math.abs(event.translationX) > swipeVelocityThreshold || Math.abs(event.translationX) > swipeDistanceThreshold ? drawerPosition === 'left' ?
166
+ // If swiped to right, open the drawer, otherwise close it
167
+ (event.velocityX === 0 ? event.translationX : event.velocityX) > 0 :
168
+ // If swiped to left, open the drawer, otherwise close it
169
+ (event.velocityX === 0 ? event.translationX : event.velocityX) < 0 : open;
170
+ toggleDrawer({
171
+ open: nextOpen,
172
+ isUserInitiated: true,
173
+ velocity: event.velocityX
174
+ });
175
+ },
176
+ onFinish: () => {
177
+ runOnJS(onGestureFinish)();
178
+ }
179
+ });
180
+ const translateX = useDerivedValue(() => {
181
+ // Comment stolen from react-native-gesture-handler/DrawerLayout
182
+ //
183
+ // While closing the drawer when user starts gesture outside of its area (in greyed
184
+ // out part of the window), we want the drawer to follow only once finger reaches the
185
+ // edge of the drawer.
186
+ // E.g. on the diagram below drawer is illustrate by X signs and the greyed out area by
187
+ // dots. The touch gesture starts at '*' and moves left, touch path is indicated by
188
+ // an arrow pointing left
189
+ // 1) +---------------+ 2) +---------------+ 3) +---------------+ 4) +---------------+
190
+ // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
191
+ // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
192
+ // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
193
+ // |XXXXXXXX|......| |XXXXXXXX|.<-*..| |XXXXXXXX|<--*..| |XXXXX|<-----*..|
194
+ // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
195
+ // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
196
+ // |XXXXXXXX|......| |XXXXXXXX|......| |XXXXXXXX|......| |XXXXX|.........|
197
+ // +---------------+ +---------------+ +---------------+ +---------------+
198
+ //
199
+ // For the above to work properly we define animated value that will keep start position
200
+ // of the gesture. Then we use that value to calculate how much we need to subtract from
201
+ // the translationX. If the gesture started on the greyed out area we take the distance from the
202
+ // edge of the drawer to the start position. Otherwise we don't subtract at all and the
203
+ // drawer be pulled back as soon as you start the pan.
204
+ //
205
+ // This is used only when drawerType is "front"
206
+ const touchDistance = drawerType === 'front' && gestureState.value === GestureState.ACTIVE ? minmax(drawerPosition === 'left' ? touchStartX.value - drawerWidth : dimensions.width - drawerWidth - touchStartX.value, 0, dimensions.width) : 0;
207
+ const translateX = drawerPosition === 'left' ? minmax(translationX.value + touchDistance, -drawerWidth, 0) : minmax(translationX.value - touchDistance, 0, drawerWidth);
208
+ return translateX;
209
+ }, [
210
+ drawerType,
211
+ gestureState,
212
+ minmax,
213
+ drawerPosition,
214
+ touchStartX,
215
+ drawerWidth,
216
+ translationX,
217
+ ]);
218
+ const isRTL = I18nManager.getConstants().isRTL;
219
+ const drawerAnimatedStyle = useAnimatedStyle(() => {
220
+ const distanceFromEdge = dimensions.width - drawerWidth;
221
+ return {
222
+ transform: drawerType === 'permanent' ?
223
+ // Reanimated needs the property to be present, but it results in Browser bug
224
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=20574
225
+ [] : [{
226
+ translateX:
227
+ // The drawer stays in place when `drawerType` is `back`
228
+ (drawerType === 'back' ? 0 : translateX.value) + (drawerPosition === 'left' ? isRTL ? -distanceFromEdge : 0 : isRTL ? 0 : distanceFromEdge)
229
+ }]
230
+ };
231
+ }, [ drawerWidth, drawerType, translateX, drawerPosition, isRTL]);
232
+ const contentAnimatedStyle = useAnimatedStyle(() => {
233
+ return {
234
+ transform: drawerType === 'permanent' ?
235
+ // Reanimated needs the property to be present, but it results in Browser bug
236
+ // https://bugs.chromium.org/p/chromium/issues/detail?id=20574
237
+ [] : [{
238
+ translateX:
239
+ // The screen content stays in place when `drawerType` is `front`
240
+ drawerType === 'front' ? 0 : translateX.value + drawerWidth * (drawerPosition === 'left' ? 1 : -1)
241
+ }]
242
+ };
243
+ }, [drawerType, translateX, drawerWidth, drawerPosition]);
244
+ const progress = useDerivedValue(() => {
245
+ return drawerType === 'permanent' ? 1 : interpolate(translateX.value, [getDrawerTranslationX(false), getDrawerTranslationX(true)], [0, 1]);
246
+ }, [drawerType, interpolate, translateX, getDrawerTranslationX]);
247
+ return /*#__PURE__*/React.createElement(DrawerProgressContext.Provider, {
248
+ value: progress
249
+ }, /*#__PURE__*/React.createElement(PanGestureHandler, _extends({
250
+ activeOffsetX: [-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM],
251
+ failOffsetY: [-SWIPE_DISTANCE_MINIMUM, SWIPE_DISTANCE_MINIMUM],
252
+ hitSlop: hitSlop,
253
+ enabled: drawerType !== 'permanent' && swipeEnabled,
254
+ onGestureEvent: onGestureEvent
255
+ }, gestureHandlerProps), /*#__PURE__*/React.createElement(Animated.View, {
256
+ style: [styles.main, {
257
+ flexDirection: drawerType === 'permanent' && !isRight ? 'row-reverse' : 'row'
258
+ }]
259
+ }, /*#__PURE__*/React.createElement(Animated.View, {
260
+ style: [styles.content, contentAnimatedStyle]
261
+ }, /*#__PURE__*/React.createElement(View, {
262
+ accessibilityElementsHidden: isOpen && drawerType !== 'permanent',
263
+ importantForAccessibility: isOpen && drawerType !== 'permanent' ? 'no-hide-descendants' : 'auto',
264
+ style: styles.content
265
+ }, renderSceneContent()), drawerType !== 'permanent' ? /*#__PURE__*/React.createElement(Overlay, {
266
+ progress: progress,
267
+ onPress: () => toggleDrawer({
268
+ open: false,
269
+ isUserInitiated: true
270
+ }),
271
+ style: overlayStyle,
272
+ accessibilityLabel: overlayAccessibilityLabel
273
+ }) : null), /*#__PURE__*/React.createElement(Animated.View, {
274
+ removeClippedSubviews: Platform.OS !== 'ios',
275
+ style: [styles.container, {
276
+ position: drawerType === 'permanent' ? 'relative' : 'absolute',
277
+ zIndex: drawerType === 'back' ? -1 : 0
278
+ }, drawerAnimatedStyle, drawerStyle]
279
+ }, renderDrawerContent()))));
280
+ }
281
+ const styles = StyleSheet.create({
282
+ container: {
283
+ top: 0,
284
+ bottom: 0,
285
+ maxWidth: '100%',
286
+ width: DEFAULT_DRAWER_WIDTH
287
+ },
288
+ content: {
289
+ flex: 1
290
+ },
291
+ main: {
292
+ flex: 1,
293
+ ...Platform.select({
294
+ // FIXME: We need to hide `overflowX` on Web so the translated content doesn't show offscreen.
295
+ // But adding `overflowX: 'hidden'` prevents content from collapsing the URL bar.
296
+ web: null,
297
+ default: {
298
+ overflow: 'hidden'
299
+ }
300
+ })
301
+ }
302
+ });
303
+ //# sourceMappingURL=Drawer.js.map