@sigmela/router 0.3.7 → 0.5.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.
- package/CHANGELOG.md +38 -0
- package/LICENSE +2 -1
- package/README.md +127 -471
- package/dist/Router.d.ts +190 -0
- package/dist/Router.d.ts.map +1 -0
- package/dist/components/Modal.d.ts +56 -0
- package/dist/components/Modal.d.ts.map +1 -0
- package/dist/components/OverlayContentScope.d.ts +8 -0
- package/dist/components/OverlayContentScope.d.ts.map +1 -0
- package/dist/components/RouterCloseButton.d.ts +9 -0
- package/dist/components/RouterCloseButton.d.ts.map +1 -0
- package/dist/components/Sheet.d.ts +56 -0
- package/dist/components/Sheet.d.ts.map +1 -0
- package/dist/components/SheetSurface.d.ts +27 -0
- package/dist/components/SheetSurface.d.ts.map +1 -0
- package/dist/components/index.d.ts +4 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/components/pageScrollLock.d.ts +3 -0
- package/dist/components/pageScrollLock.d.ts.map +1 -0
- package/dist/components/sheetDragEngine.d.ts +27 -0
- package/dist/components/sheetDragEngine.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3696 -0
- package/dist/index.js.map +1 -0
- package/dist/navigationHistory.d.ts +17 -0
- package/dist/navigationHistory.d.ts.map +1 -0
- package/dist/router.css +975 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/id.d.ts +2 -0
- package/dist/utils/id.d.ts.map +1 -0
- package/package.json +73 -174
- package/lib/module/Drawer/Drawer.js +0 -250
- package/lib/module/Drawer/DrawerContext.js +0 -4
- package/lib/module/Drawer/DrawerIcon.web.js +0 -47
- package/lib/module/Drawer/RenderDrawer.native.js +0 -248
- package/lib/module/Drawer/RenderDrawer.web.js +0 -197
- package/lib/module/Drawer/useDrawer.js +0 -11
- package/lib/module/Navigation.js +0 -80
- package/lib/module/NavigationStack.js +0 -254
- package/lib/module/Router.js +0 -2171
- package/lib/module/RouterContext.js +0 -33
- package/lib/module/ScreenStack/ScreenStack.native.js +0 -3
- package/lib/module/ScreenStack/ScreenStack.web.js +0 -561
- package/lib/module/ScreenStack/ScreenStackContext.js +0 -21
- package/lib/module/ScreenStack/animationHelpers.js +0 -87
- package/lib/module/ScreenStack/index.js +0 -3
- package/lib/module/ScreenStackItem/ScreenStackItem.js +0 -70
- package/lib/module/ScreenStackItem/ScreenStackItem.types.js +0 -3
- package/lib/module/ScreenStackItem/ScreenStackItem.web.js +0 -171
- package/lib/module/ScreenStackItem/index.js +0 -3
- package/lib/module/ScreenStackSheetItem/ScreenStackSheetItem.native.js +0 -70
- package/lib/module/ScreenStackSheetItem/ScreenStackSheetItem.web.js +0 -5
- package/lib/module/ScreenStackSheetItem/index.js +0 -3
- package/lib/module/SplitView/RenderSplitView.native.js +0 -101
- package/lib/module/SplitView/RenderSplitView.web.js +0 -107
- package/lib/module/SplitView/SplitView.js +0 -97
- package/lib/module/SplitView/SplitViewContext.js +0 -4
- package/lib/module/SplitView/index.js +0 -5
- package/lib/module/SplitView/useSplitView.js +0 -11
- package/lib/module/StackRenderer.js +0 -42
- package/lib/module/TabBar/RenderTabBar.native.js +0 -418
- package/lib/module/TabBar/RenderTabBar.web.js +0 -218
- package/lib/module/TabBar/TabBar.js +0 -208
- package/lib/module/TabBar/TabBarContext.js +0 -4
- package/lib/module/TabBar/TabIcon.web.js +0 -47
- package/lib/module/TabBar/index.js +0 -6
- package/lib/module/TabBar/useTabBar.js +0 -11
- package/lib/module/TabBar/useTabBarHeight.js +0 -22
- package/lib/module/createController.js +0 -5
- package/lib/module/index.js +0 -15
- package/lib/module/navigationNode.js +0 -3
- package/lib/module/package.json +0 -1
- package/lib/module/styles.css +0 -1111
- package/lib/module/types.js +0 -13
- package/lib/typescript/package.json +0 -1
- package/lib/typescript/src/Drawer/Drawer.d.ts +0 -100
- package/lib/typescript/src/Drawer/DrawerContext.d.ts +0 -3
- package/lib/typescript/src/Drawer/DrawerIcon.web.d.ts +0 -7
- package/lib/typescript/src/Drawer/RenderDrawer.native.d.ts +0 -8
- package/lib/typescript/src/Drawer/RenderDrawer.web.d.ts +0 -8
- package/lib/typescript/src/Drawer/useDrawer.d.ts +0 -2
- package/lib/typescript/src/Navigation.d.ts +0 -17
- package/lib/typescript/src/NavigationStack.d.ts +0 -46
- package/lib/typescript/src/Router.d.ts +0 -232
- package/lib/typescript/src/RouterContext.d.ts +0 -18
- package/lib/typescript/src/ScreenStack/ScreenStack.native.d.ts +0 -2
- package/lib/typescript/src/ScreenStack/ScreenStack.web.d.ts +0 -9
- package/lib/typescript/src/ScreenStack/ScreenStackContext.d.ts +0 -31
- package/lib/typescript/src/ScreenStack/animationHelpers.d.ts +0 -6
- package/lib/typescript/src/ScreenStack/index.d.ts +0 -2
- package/lib/typescript/src/ScreenStackItem/ScreenStackItem.d.ts +0 -3
- package/lib/typescript/src/ScreenStackItem/ScreenStackItem.types.d.ts +0 -14
- package/lib/typescript/src/ScreenStackItem/ScreenStackItem.web.d.ts +0 -3
- package/lib/typescript/src/ScreenStackItem/index.d.ts +0 -3
- package/lib/typescript/src/ScreenStackSheetItem/ScreenStackSheetItem.native.d.ts +0 -11
- package/lib/typescript/src/ScreenStackSheetItem/ScreenStackSheetItem.web.d.ts +0 -2
- package/lib/typescript/src/ScreenStackSheetItem/index.d.ts +0 -2
- package/lib/typescript/src/SplitView/RenderSplitView.native.d.ts +0 -19
- package/lib/typescript/src/SplitView/RenderSplitView.web.d.ts +0 -8
- package/lib/typescript/src/SplitView/SplitView.d.ts +0 -33
- package/lib/typescript/src/SplitView/SplitViewContext.d.ts +0 -3
- package/lib/typescript/src/SplitView/index.d.ts +0 -5
- package/lib/typescript/src/SplitView/useSplitView.d.ts +0 -2
- package/lib/typescript/src/StackRenderer.d.ts +0 -8
- package/lib/typescript/src/TabBar/RenderTabBar.native.d.ts +0 -8
- package/lib/typescript/src/TabBar/RenderTabBar.web.d.ts +0 -8
- package/lib/typescript/src/TabBar/TabBar.d.ts +0 -112
- package/lib/typescript/src/TabBar/TabBarContext.d.ts +0 -3
- package/lib/typescript/src/TabBar/TabIcon.web.d.ts +0 -7
- package/lib/typescript/src/TabBar/index.d.ts +0 -5
- package/lib/typescript/src/TabBar/useTabBar.d.ts +0 -2
- package/lib/typescript/src/TabBar/useTabBarHeight.d.ts +0 -18
- package/lib/typescript/src/createController.d.ts +0 -15
- package/lib/typescript/src/index.d.ts +0 -21
- package/lib/typescript/src/navigationNode.d.ts +0 -41
- package/lib/typescript/src/types.d.ts +0 -140
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,kBAAkB,GAAG,oBAAoB,CAAC;AACxE,MAAM,MAAM,mBAAmB,GAAG,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id.d.ts","sourceRoot":"","sources":["../../src/utils/id.ts"],"names":[],"mappings":"AAAA,wBAAgB,cAAc,IAAI,MAAM,CAavC"}
|
package/package.json
CHANGED
|
@@ -1,192 +1,91 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigmela/router",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "React
|
|
5
|
-
"
|
|
6
|
-
"
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "Native-feeling router for React web apps: screen stacks with gesture-driven back, modals, sheets, tab bars, drawers and split views.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Sigmela",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"sideEffects": [
|
|
9
|
+
"**/*.css"
|
|
10
|
+
],
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"module": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts",
|
|
7
14
|
"exports": {
|
|
8
15
|
".": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"default": "./
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"default": "./dist/index.js"
|
|
12
19
|
},
|
|
13
|
-
"./
|
|
14
|
-
"./
|
|
15
|
-
"source": "./src/styles.css",
|
|
16
|
-
"default": "./lib/module/styles.css"
|
|
17
|
-
}
|
|
20
|
+
"./router.css": "./dist/router.css",
|
|
21
|
+
"./package.json": "./package.json"
|
|
18
22
|
},
|
|
19
23
|
"files": [
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"*.podspec",
|
|
25
|
-
"react-native.config.js",
|
|
26
|
-
"!ios/build",
|
|
27
|
-
"!android/build",
|
|
28
|
-
"!android/gradle",
|
|
29
|
-
"!android/gradlew",
|
|
30
|
-
"!android/gradlew.bat",
|
|
31
|
-
"!android/local.properties",
|
|
32
|
-
"!**/__tests__",
|
|
33
|
-
"!**/__fixtures__",
|
|
34
|
-
"!**/__mocks__",
|
|
35
|
-
"!**/.*"
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md",
|
|
26
|
+
"CHANGELOG.md",
|
|
27
|
+
"LICENSE"
|
|
36
28
|
],
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"test": "jest",
|
|
40
|
-
"typecheck": "tsc",
|
|
41
|
-
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
42
|
-
"clean": "del-cli lib",
|
|
43
|
-
"prepare": "bob build && del-cli \"lib/**/*.map\"",
|
|
44
|
-
"release": "release-it --only-version"
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=20"
|
|
45
31
|
},
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
"url": "git+https://github.com/sigmela/router.git"
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup && tsc -p tsconfig.build.json",
|
|
34
|
+
"clean": "rm -rf dist",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"test:watch": "vitest",
|
|
38
|
+
"lint": "eslint .",
|
|
39
|
+
"prepublishOnly": "yarn clean && yarn typecheck && yarn test && yarn build",
|
|
40
|
+
"example": "vite --config example/vite.config.ts",
|
|
41
|
+
"example:build": "vite build --config example/vite.config.ts"
|
|
57
42
|
},
|
|
58
|
-
"
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
"url": "https://github.com/sigmela/router/issues"
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"react": ">=19.0.0",
|
|
45
|
+
"react-dom": ">=19.0.0"
|
|
62
46
|
},
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
"
|
|
66
|
-
"
|
|
47
|
+
"dependencies": {
|
|
48
|
+
"@fluejs/noscroll": "^1.0.0",
|
|
49
|
+
"motion": "^12.40.0",
|
|
50
|
+
"react-transition-state": "^2.4.0",
|
|
51
|
+
"wouter": "^3.10.0"
|
|
67
52
|
},
|
|
68
53
|
"devDependencies": {
|
|
69
|
-
"@
|
|
70
|
-
"@
|
|
71
|
-
"@
|
|
72
|
-
"@
|
|
73
|
-
"@
|
|
74
|
-
"@react-
|
|
75
|
-
"@
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"eslint
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"react": "19.2.0",
|
|
88
|
-
"react-native": "0.83.2",
|
|
89
|
-
"react-native-builder-bob": "^0.40.18",
|
|
90
|
-
"react-native-reanimated": "^4.2.2",
|
|
91
|
-
"react-native-safe-area-context": "^5.7.0",
|
|
92
|
-
"react-native-screens": "^4.24.0",
|
|
93
|
-
"react-native-worklets": "^0.7.4",
|
|
94
|
-
"release-it": "^19.0.4",
|
|
95
|
-
"typescript": "^5.9.2"
|
|
96
|
-
},
|
|
97
|
-
"peerDependencies": {
|
|
98
|
-
"@sigmela/native-sheet": ">=0.0.1",
|
|
99
|
-
"react": "*",
|
|
100
|
-
"react-native": ">=0.72.0",
|
|
101
|
-
"react-native-reanimated": ">=3.0.0",
|
|
102
|
-
"react-native-safe-area-context": ">=4.0.0",
|
|
103
|
-
"react-native-screens": ">=4.18.0"
|
|
104
|
-
},
|
|
105
|
-
"peerDependenciesMeta": {
|
|
106
|
-
"@sigmela/native-sheet": {
|
|
107
|
-
"optional": true
|
|
108
|
-
},
|
|
109
|
-
"react-native-reanimated": {
|
|
110
|
-
"optional": true
|
|
111
|
-
},
|
|
112
|
-
"react-native-safe-area-context": {
|
|
113
|
-
"optional": true
|
|
114
|
-
}
|
|
54
|
+
"@eslint/js": "^9.39.1",
|
|
55
|
+
"@testing-library/dom": "10.4.1",
|
|
56
|
+
"@testing-library/react": "16.3.2",
|
|
57
|
+
"@types/node": "^26.1.1",
|
|
58
|
+
"@types/react": "19.2.14",
|
|
59
|
+
"@types/react-dom": "^19.2.3",
|
|
60
|
+
"@vitejs/plugin-react": "^5.2.0",
|
|
61
|
+
"eslint": "^9.39.1",
|
|
62
|
+
"eslint-plugin-react-hooks": "^7.1.0",
|
|
63
|
+
"globals": "^16.5.0",
|
|
64
|
+
"jsdom": "^29.1.1",
|
|
65
|
+
"react": "19.2.3",
|
|
66
|
+
"react-dom": "19.2.3",
|
|
67
|
+
"tsup": "^8.5.0",
|
|
68
|
+
"typescript": "~6.0.3",
|
|
69
|
+
"typescript-eslint": "^8.47.0",
|
|
70
|
+
"vite": "^7.3.6",
|
|
71
|
+
"vitest": "4.1.10"
|
|
115
72
|
},
|
|
116
|
-
"
|
|
117
|
-
"
|
|
73
|
+
"keywords": [
|
|
74
|
+
"react",
|
|
75
|
+
"router",
|
|
76
|
+
"navigation",
|
|
77
|
+
"modal",
|
|
78
|
+
"bottom-sheet",
|
|
79
|
+
"tabs",
|
|
80
|
+
"drawer",
|
|
81
|
+
"split-view",
|
|
82
|
+
"mobile",
|
|
83
|
+
"spa"
|
|
118
84
|
],
|
|
119
|
-
"
|
|
120
|
-
|
|
121
|
-
"preset": "react-native",
|
|
122
|
-
"modulePathIgnorePatterns": [
|
|
123
|
-
"<rootDir>/example/node_modules",
|
|
124
|
-
"<rootDir>/lib/",
|
|
125
|
-
"<rootDir>/.worktrees/"
|
|
126
|
-
],
|
|
127
|
-
"transformIgnorePatterns": [
|
|
128
|
-
"node_modules/(?!((jest-)?react-native|@react-native|react-native-screens|@sigmela/native-sheet|nanoid|query-string|decode-uri-component|split-on-first|filter-obj)/)"
|
|
129
|
-
]
|
|
130
|
-
},
|
|
131
|
-
"commitlint": {
|
|
132
|
-
"extends": [
|
|
133
|
-
"@commitlint/config-conventional"
|
|
134
|
-
]
|
|
135
|
-
},
|
|
136
|
-
"release-it": {
|
|
137
|
-
"git": {
|
|
138
|
-
"commitMessage": "chore: release ${version}",
|
|
139
|
-
"tagName": "v${version}"
|
|
140
|
-
},
|
|
141
|
-
"npm": {
|
|
142
|
-
"publish": true
|
|
143
|
-
},
|
|
144
|
-
"github": {
|
|
145
|
-
"release": true
|
|
146
|
-
},
|
|
147
|
-
"plugins": {
|
|
148
|
-
"@release-it/conventional-changelog": {
|
|
149
|
-
"preset": {
|
|
150
|
-
"name": "angular"
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
"prettier": {
|
|
156
|
-
"quoteProps": "consistent",
|
|
157
|
-
"singleQuote": true,
|
|
158
|
-
"tabWidth": 2,
|
|
159
|
-
"trailingComma": "es5",
|
|
160
|
-
"useTabs": false
|
|
161
|
-
},
|
|
162
|
-
"react-native-builder-bob": {
|
|
163
|
-
"source": "src",
|
|
164
|
-
"output": "lib",
|
|
165
|
-
"targets": [
|
|
166
|
-
[
|
|
167
|
-
"module",
|
|
168
|
-
{
|
|
169
|
-
"esm": true,
|
|
170
|
-
"sourceMaps": false
|
|
171
|
-
}
|
|
172
|
-
],
|
|
173
|
-
[
|
|
174
|
-
"typescript",
|
|
175
|
-
{
|
|
176
|
-
"project": "tsconfig.build.json"
|
|
177
|
-
}
|
|
178
|
-
]
|
|
179
|
-
]
|
|
180
|
-
},
|
|
181
|
-
"create-react-native-library": {
|
|
182
|
-
"languages": "js",
|
|
183
|
-
"type": "library",
|
|
184
|
-
"version": "0.54.3"
|
|
85
|
+
"publishConfig": {
|
|
86
|
+
"access": "public"
|
|
185
87
|
},
|
|
186
|
-
"
|
|
187
|
-
"
|
|
188
|
-
"path-to-regexp": "^8.3.0",
|
|
189
|
-
"query-string": "^9.3.1",
|
|
190
|
-
"react-transition-state": "^2.3.3"
|
|
88
|
+
"allowScripts": {
|
|
89
|
+
"esbuild@0.27.7": true
|
|
191
90
|
}
|
|
192
91
|
}
|
|
@@ -1,250 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { RenderDrawer } from './RenderDrawer';
|
|
5
|
-
export class Drawer {
|
|
6
|
-
screens = {};
|
|
7
|
-
stacks = {};
|
|
8
|
-
nodes = {};
|
|
9
|
-
listeners = new Set();
|
|
10
|
-
openListeners = new Set();
|
|
11
|
-
constructor(options = {}) {
|
|
12
|
-
this.drawerId = `drawer-${Math.random().toString(36).slice(2)}`;
|
|
13
|
-
this.width = options.width ?? 280;
|
|
14
|
-
this.state = {
|
|
15
|
-
tabs: [],
|
|
16
|
-
index: options.initialIndex ?? 0,
|
|
17
|
-
config: {
|
|
18
|
-
component: options.component
|
|
19
|
-
},
|
|
20
|
-
isOpen: false
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
getId() {
|
|
24
|
-
return this.drawerId;
|
|
25
|
-
}
|
|
26
|
-
addTab(tab) {
|
|
27
|
-
const sourcesCount = (tab.stack ? 1 : 0) + (tab.node ? 1 : 0) + (tab.screen ? 1 : 0);
|
|
28
|
-
if (sourcesCount !== 1) {
|
|
29
|
-
throw new Error(`Drawer.addTab: exactly one of { stack, node, screen } must be provided (got ${sourcesCount})`);
|
|
30
|
-
}
|
|
31
|
-
const {
|
|
32
|
-
key,
|
|
33
|
-
...rest
|
|
34
|
-
} = tab;
|
|
35
|
-
const nextIndex = this.state.tabs.length;
|
|
36
|
-
const tabKey = key ?? `drawer-item-${nextIndex}`;
|
|
37
|
-
const nextTabs = [...this.state.tabs, {
|
|
38
|
-
tabKey,
|
|
39
|
-
tabPrefix: tab.prefix,
|
|
40
|
-
title: rest.title,
|
|
41
|
-
icon: rest.icon,
|
|
42
|
-
selectedIcon: rest.selectedIcon,
|
|
43
|
-
badgeValue: rest.badgeValue
|
|
44
|
-
}];
|
|
45
|
-
this.setState({
|
|
46
|
-
tabs: nextTabs
|
|
47
|
-
});
|
|
48
|
-
if (tab.stack) {
|
|
49
|
-
this.stacks[tabKey] = tab.stack;
|
|
50
|
-
} else if (tab.node) {
|
|
51
|
-
this.nodes[tabKey] = tab.node;
|
|
52
|
-
} else if (tab.screen) {
|
|
53
|
-
this.screens[tabKey] = tab.screen;
|
|
54
|
-
}
|
|
55
|
-
return this;
|
|
56
|
-
}
|
|
57
|
-
setBadge(tabIndex, badge) {
|
|
58
|
-
this.setState({
|
|
59
|
-
tabs: this.state.tabs.map((item, index) => index === tabIndex ? {
|
|
60
|
-
...item,
|
|
61
|
-
badgeValue: badge ?? undefined
|
|
62
|
-
} : item)
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
setTabBarConfig(config) {
|
|
66
|
-
this.setState({
|
|
67
|
-
config: {
|
|
68
|
-
...this.state.config,
|
|
69
|
-
...config
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
onIndexChange(index) {
|
|
74
|
-
this.setState({
|
|
75
|
-
index
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ---- Open/Close state ----
|
|
80
|
-
|
|
81
|
-
open() {
|
|
82
|
-
if (!this.state.isOpen) {
|
|
83
|
-
this.setState({
|
|
84
|
-
isOpen: true
|
|
85
|
-
});
|
|
86
|
-
this.notifyOpenListeners(true);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
close() {
|
|
90
|
-
if (this.state.isOpen) {
|
|
91
|
-
this.setState({
|
|
92
|
-
isOpen: false
|
|
93
|
-
});
|
|
94
|
-
this.notifyOpenListeners(false);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
toggle() {
|
|
98
|
-
if (this.state.isOpen) {
|
|
99
|
-
this.close();
|
|
100
|
-
} else {
|
|
101
|
-
this.open();
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
getIsOpen() {
|
|
105
|
-
return this.state.isOpen;
|
|
106
|
-
}
|
|
107
|
-
subscribeOpenState(listener) {
|
|
108
|
-
this.openListeners.add(listener);
|
|
109
|
-
return () => {
|
|
110
|
-
this.openListeners.delete(listener);
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
notifyOpenListeners(isOpen) {
|
|
114
|
-
for (const listener of Array.from(this.openListeners)) {
|
|
115
|
-
try {
|
|
116
|
-
listener(isOpen);
|
|
117
|
-
} catch (e) {
|
|
118
|
-
if (__DEV__) {
|
|
119
|
-
console.error('[Drawer] openListener error', e);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
// ---- Standard TabBar-like methods ----
|
|
126
|
-
|
|
127
|
-
getState = () => {
|
|
128
|
-
return this.state;
|
|
129
|
-
};
|
|
130
|
-
setState(state) {
|
|
131
|
-
this.state = {
|
|
132
|
-
...this.state,
|
|
133
|
-
...state
|
|
134
|
-
};
|
|
135
|
-
this.notifyListeners();
|
|
136
|
-
}
|
|
137
|
-
notifyListeners() {
|
|
138
|
-
for (const listener of Array.from(this.listeners)) {
|
|
139
|
-
try {
|
|
140
|
-
listener();
|
|
141
|
-
} catch (e) {
|
|
142
|
-
if (__DEV__) {
|
|
143
|
-
console.error('[Drawer] listener error', e);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
subscribe(listener) {
|
|
149
|
-
this.listeners.add(listener);
|
|
150
|
-
return () => {
|
|
151
|
-
this.listeners.delete(listener);
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
getTabs() {
|
|
155
|
-
return this.state.tabs.slice();
|
|
156
|
-
}
|
|
157
|
-
getInitialIndex() {
|
|
158
|
-
return this.state.index ?? 0;
|
|
159
|
-
}
|
|
160
|
-
getActiveChildId() {
|
|
161
|
-
const activeTab = this.state.tabs[this.state.index];
|
|
162
|
-
if (!activeTab) return undefined;
|
|
163
|
-
const node = this.nodes[activeTab.tabKey] ?? this.stacks[activeTab.tabKey];
|
|
164
|
-
return node?.getId();
|
|
165
|
-
}
|
|
166
|
-
switchToRoute(routeId) {
|
|
167
|
-
const idx = this.findTabIndexByRoute(routeId);
|
|
168
|
-
if (idx === -1) return;
|
|
169
|
-
if (idx === this.state.index) return;
|
|
170
|
-
this.setState({
|
|
171
|
-
index: idx
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
hasRoute(routeId) {
|
|
175
|
-
return this.findTabIndexByRoute(routeId) !== -1;
|
|
176
|
-
}
|
|
177
|
-
setActiveChildByRoute(routeId) {
|
|
178
|
-
this.switchToRoute(routeId);
|
|
179
|
-
}
|
|
180
|
-
getNodeRoutes() {
|
|
181
|
-
return [];
|
|
182
|
-
}
|
|
183
|
-
getNodeChildren() {
|
|
184
|
-
const children = [];
|
|
185
|
-
for (let idx = 0; idx < this.state.tabs.length; idx++) {
|
|
186
|
-
const tab = this.state.tabs[idx];
|
|
187
|
-
const node = tab ? this.nodes[tab.tabKey] ?? this.stacks[tab.tabKey] : undefined;
|
|
188
|
-
if (node) {
|
|
189
|
-
children.push({
|
|
190
|
-
prefix: tab?.tabPrefix ?? '',
|
|
191
|
-
node,
|
|
192
|
-
onMatch: () => this.onIndexChange(idx)
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
return children;
|
|
197
|
-
}
|
|
198
|
-
getRenderer() {
|
|
199
|
-
const drawerInstance = this;
|
|
200
|
-
return function DrawerScreen(props) {
|
|
201
|
-
return /*#__PURE__*/React.createElement(RenderDrawer, {
|
|
202
|
-
drawer: drawerInstance,
|
|
203
|
-
appearance: props?.appearance
|
|
204
|
-
});
|
|
205
|
-
};
|
|
206
|
-
}
|
|
207
|
-
seed() {
|
|
208
|
-
const activeTab = this.state.tabs[this.state.index];
|
|
209
|
-
if (!activeTab) return null;
|
|
210
|
-
const node = this.nodes[activeTab.tabKey];
|
|
211
|
-
if (node) {
|
|
212
|
-
return node.seed?.() ?? null;
|
|
213
|
-
}
|
|
214
|
-
const stack = this.stacks[activeTab.tabKey];
|
|
215
|
-
if (!stack) return null;
|
|
216
|
-
const firstRoute = stack.getFirstRoute();
|
|
217
|
-
if (!firstRoute) return null;
|
|
218
|
-
return {
|
|
219
|
-
routeId: firstRoute.routeId,
|
|
220
|
-
path: firstRoute.path,
|
|
221
|
-
stackId: stack.getId()
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
findTabIndexByRoute(routeId) {
|
|
225
|
-
for (let i = 0; i < this.state.tabs.length; i++) {
|
|
226
|
-
const tab = this.state.tabs[i];
|
|
227
|
-
const node = tab ? this.nodes[tab.tabKey] ?? this.stacks[tab.tabKey] : undefined;
|
|
228
|
-
if (!node) continue;
|
|
229
|
-
const hasRoute = this.nodeHasRoute(node, routeId);
|
|
230
|
-
if (hasRoute) {
|
|
231
|
-
return i;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return -1;
|
|
235
|
-
}
|
|
236
|
-
nodeHasRoute(node, routeId) {
|
|
237
|
-
const routes = node.getNodeRoutes();
|
|
238
|
-
for (const r of routes) {
|
|
239
|
-
if (r.routeId === routeId) return true;
|
|
240
|
-
if (r.childNode) {
|
|
241
|
-
if (this.nodeHasRoute(r.childNode, routeId)) return true;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
const children = node.getNodeChildren();
|
|
245
|
-
for (const child of children) {
|
|
246
|
-
if (this.nodeHasRoute(child.node, routeId)) return true;
|
|
247
|
-
}
|
|
248
|
-
return false;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { memo, useMemo } from 'react';
|
|
4
|
-
import { Image } from 'react-native';
|
|
5
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
|
-
const resolveImageUri = source => {
|
|
7
|
-
if (!source) return undefined;
|
|
8
|
-
const resolved = typeof Image.resolveAssetSource === 'function' ? Image.resolveAssetSource(source) : undefined;
|
|
9
|
-
if (resolved?.uri) return resolved.uri;
|
|
10
|
-
if (Array.isArray(source)) {
|
|
11
|
-
const first = source[0];
|
|
12
|
-
if (first && typeof first === 'object' && 'uri' in first) return first.uri;
|
|
13
|
-
}
|
|
14
|
-
if (typeof source === 'object' && source && 'uri' in source) return source.uri;
|
|
15
|
-
return undefined;
|
|
16
|
-
};
|
|
17
|
-
export const DrawerIcon = /*#__PURE__*/memo(({
|
|
18
|
-
source,
|
|
19
|
-
tintColor
|
|
20
|
-
}) => {
|
|
21
|
-
const iconUri = resolveImageUri(source);
|
|
22
|
-
const useMask = Boolean(tintColor && iconUri);
|
|
23
|
-
const maskStyle = useMemo(() => {
|
|
24
|
-
if (!useMask || !iconUri) return undefined;
|
|
25
|
-
return {
|
|
26
|
-
backgroundColor: tintColor,
|
|
27
|
-
WebkitMaskImage: `url(${iconUri})`,
|
|
28
|
-
WebkitMaskSize: 'contain',
|
|
29
|
-
WebkitMaskRepeat: 'no-repeat',
|
|
30
|
-
WebkitMaskPosition: 'center',
|
|
31
|
-
maskImage: `url(${iconUri})`,
|
|
32
|
-
maskSize: 'contain',
|
|
33
|
-
maskRepeat: 'no-repeat',
|
|
34
|
-
maskPosition: 'center',
|
|
35
|
-
width: '100%',
|
|
36
|
-
height: '100%'
|
|
37
|
-
};
|
|
38
|
-
}, [tintColor, iconUri, useMask]);
|
|
39
|
-
if (maskStyle) {
|
|
40
|
-
return /*#__PURE__*/_jsx("div", {
|
|
41
|
-
style: maskStyle
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
return /*#__PURE__*/_jsx(Image, {
|
|
45
|
-
source: source
|
|
46
|
-
});
|
|
47
|
-
});
|