capacitor-native-tabbar 0.0.1 → 0.0.2
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/README.md +46 -18
- package/README.ru.md +33 -14
- package/android/src/main/kotlin/com/antonseagull/cap/tabbar/CapTabbar.kt +15 -5
- package/android/src/main/kotlin/com/antonseagull/cap/tabbar/CapTabbarPlugin.kt +21 -4
- package/dist/docs.json +38 -11
- package/dist/esm/definitions.d.ts +15 -7
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +10 -2
- package/dist/esm/web.js +39 -8
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +39 -8
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +39 -8
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/CapTabbarPlugin/CapTabbar.swift +19 -5
- package/ios/Sources/CapTabbarPlugin/CapTabbarPlugin.swift +19 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,8 +45,8 @@ npx cap sync
|
|
|
45
45
|
```typescript
|
|
46
46
|
import { CapTabbar } from 'capacitor-native-tabbar';
|
|
47
47
|
|
|
48
|
-
//
|
|
49
|
-
CapTabbar.
|
|
48
|
+
// Initialize (create) the tab bar
|
|
49
|
+
CapTabbar.init({
|
|
50
50
|
tabs: [
|
|
51
51
|
{ id: 'home', label: 'Home' },
|
|
52
52
|
{ id: 'search', label: 'Search' },
|
|
@@ -63,11 +63,14 @@ CapTabbar.addListener('tabChange', (event) => {
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
// Get current state
|
|
66
|
-
const { visible, activeTabId } = await CapTabbar.getState();
|
|
66
|
+
const { initialized, visible, activeTabId } = await CapTabbar.getState();
|
|
67
67
|
|
|
68
|
-
// Hide / show
|
|
68
|
+
// Hide / show UI (tab bar stays in memory)
|
|
69
69
|
CapTabbar.hide();
|
|
70
|
-
CapTabbar.show(
|
|
70
|
+
CapTabbar.show();
|
|
71
|
+
|
|
72
|
+
// Destroy the tab bar completely
|
|
73
|
+
CapTabbar.destroy();
|
|
71
74
|
```
|
|
72
75
|
|
|
73
76
|
## Icons
|
|
@@ -101,7 +104,7 @@ Supports PNG and vector drawable (`.xml`) on Android. Use underscores for spaces
|
|
|
101
104
|
## Label colors
|
|
102
105
|
|
|
103
106
|
```typescript
|
|
104
|
-
CapTabbar.
|
|
107
|
+
CapTabbar.init({
|
|
105
108
|
tabs,
|
|
106
109
|
selectedId: 'home',
|
|
107
110
|
label_color: '#666666', // inactive
|
|
@@ -113,7 +116,9 @@ CapTabbar.show({
|
|
|
113
116
|
|
|
114
117
|
<docgen-index>
|
|
115
118
|
|
|
116
|
-
* [`
|
|
119
|
+
* [`init(...)`](#init)
|
|
120
|
+
* [`destroy()`](#destroy)
|
|
121
|
+
* [`show()`](#show)
|
|
117
122
|
* [`hide()`](#hide)
|
|
118
123
|
* [`setSelectedTab(...)`](#setselectedtab)
|
|
119
124
|
* [`getState()`](#getstate)
|
|
@@ -125,17 +130,39 @@ CapTabbar.show({
|
|
|
125
130
|
<docgen-api>
|
|
126
131
|
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
127
132
|
|
|
128
|
-
###
|
|
133
|
+
### init(...)
|
|
129
134
|
|
|
130
135
|
```typescript
|
|
131
|
-
|
|
136
|
+
init(options: InitOptions) => Promise<void>
|
|
132
137
|
```
|
|
133
138
|
|
|
134
|
-
|
|
139
|
+
Initialize (create) the tab bar with the given configuration
|
|
135
140
|
|
|
136
141
|
| Param | Type |
|
|
137
142
|
| ------------- | --------------------------------------------------- |
|
|
138
|
-
| **`options`** | <code><a href="#
|
|
143
|
+
| **`options`** | <code><a href="#initoptions">InitOptions</a></code> |
|
|
144
|
+
|
|
145
|
+
--------------------
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
### destroy()
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
destroy() => Promise<void>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Destroy the tab bar completely (remove from view hierarchy)
|
|
155
|
+
|
|
156
|
+
--------------------
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
### show()
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
show() => Promise<void>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
Show the tab bar UI (make visible). Tab bar must be initialized.
|
|
139
166
|
|
|
140
167
|
--------------------
|
|
141
168
|
|
|
@@ -146,7 +173,7 @@ Show the native tab bar with the given configuration
|
|
|
146
173
|
hide() => Promise<void>
|
|
147
174
|
```
|
|
148
175
|
|
|
149
|
-
Hide the tab bar
|
|
176
|
+
Hide the tab bar UI (make invisible). Tab bar stays in memory.
|
|
150
177
|
|
|
151
178
|
--------------------
|
|
152
179
|
|
|
@@ -172,7 +199,7 @@ Programmatically set the selected tab
|
|
|
172
199
|
getState() => Promise<GetStateResult>
|
|
173
200
|
```
|
|
174
201
|
|
|
175
|
-
Get current state: visible and active tab id
|
|
202
|
+
Get current state: initialized, visible and active tab id
|
|
176
203
|
|
|
177
204
|
**Returns:** <code>Promise<<a href="#getstateresult">GetStateResult</a>></code>
|
|
178
205
|
|
|
@@ -200,7 +227,7 @@ Add listener for tab change events (when user taps a tab)
|
|
|
200
227
|
### Interfaces
|
|
201
228
|
|
|
202
229
|
|
|
203
|
-
####
|
|
230
|
+
#### InitOptions
|
|
204
231
|
|
|
205
232
|
Icons: 2 variants (base64 has priority over bundle)
|
|
206
233
|
|
|
@@ -243,10 +270,11 @@ If an icon is missing, a placeholder is shown.
|
|
|
243
270
|
|
|
244
271
|
#### GetStateResult
|
|
245
272
|
|
|
246
|
-
| Prop | Type | Description
|
|
247
|
-
| ----------------- | -------------------- |
|
|
248
|
-
| **`
|
|
249
|
-
| **`
|
|
273
|
+
| Prop | Type | Description |
|
|
274
|
+
| ----------------- | -------------------- | ------------------------------------------------------------------------ |
|
|
275
|
+
| **`initialized`** | <code>boolean</code> | Whether the tab bar has been initialized (created) |
|
|
276
|
+
| **`visible`** | <code>boolean</code> | Whether the tab bar is currently visible to the user (false when hidden) |
|
|
277
|
+
| **`activeTabId`** | <code>string</code> | ID of the active/selected tab (empty when destroyed) |
|
|
250
278
|
|
|
251
279
|
|
|
252
280
|
#### TabChangeEvent
|
package/README.ru.md
CHANGED
|
@@ -45,8 +45,8 @@ npx cap sync
|
|
|
45
45
|
```typescript
|
|
46
46
|
import { CapTabbar } from 'capacitor-native-tabbar';
|
|
47
47
|
|
|
48
|
-
//
|
|
49
|
-
CapTabbar.
|
|
48
|
+
// Инициализировать (создать) таб-бар
|
|
49
|
+
CapTabbar.init({
|
|
50
50
|
tabs: [
|
|
51
51
|
{ id: 'home', label: 'Главная' },
|
|
52
52
|
{ id: 'search', label: 'Поиск' },
|
|
@@ -63,11 +63,14 @@ CapTabbar.addListener('tabChange', (event) => {
|
|
|
63
63
|
});
|
|
64
64
|
|
|
65
65
|
// Получить текущее состояние
|
|
66
|
-
const { visible, activeTabId } = await CapTabbar.getState();
|
|
66
|
+
const { initialized, visible, activeTabId } = await CapTabbar.getState();
|
|
67
67
|
|
|
68
|
-
// Скрыть / показать
|
|
68
|
+
// Скрыть / показать UI (таб-бар остаётся в памяти)
|
|
69
69
|
CapTabbar.hide();
|
|
70
|
-
CapTabbar.show(
|
|
70
|
+
CapTabbar.show();
|
|
71
|
+
|
|
72
|
+
// Полностью удалить таб-бар
|
|
73
|
+
CapTabbar.destroy();
|
|
71
74
|
```
|
|
72
75
|
|
|
73
76
|
## Иконки
|
|
@@ -101,7 +104,7 @@ CapTabbar.show({ tabs, selectedId: activeTabId });
|
|
|
101
104
|
## Цвета лейбла
|
|
102
105
|
|
|
103
106
|
```typescript
|
|
104
|
-
CapTabbar.
|
|
107
|
+
CapTabbar.init({
|
|
105
108
|
tabs,
|
|
106
109
|
selectedId: 'home',
|
|
107
110
|
label_color: '#666666', // неактивный
|
|
@@ -111,17 +114,33 @@ CapTabbar.show({
|
|
|
111
114
|
|
|
112
115
|
## API
|
|
113
116
|
|
|
114
|
-
###
|
|
117
|
+
### init(options)
|
|
118
|
+
|
|
119
|
+
Инициализировать (создать) таб-бар с заданной конфигурацией.
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
init(options: InitOptions) => Promise<void>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### destroy()
|
|
126
|
+
|
|
127
|
+
Полностью удалить таб-бар.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
destroy() => Promise<void>
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### show()
|
|
115
134
|
|
|
116
|
-
Показать
|
|
135
|
+
Показать UI таб-бара (сделать видимым). Таб-бар должен быть инициализирован.
|
|
117
136
|
|
|
118
137
|
```typescript
|
|
119
|
-
show(
|
|
138
|
+
show() => Promise<void>
|
|
120
139
|
```
|
|
121
140
|
|
|
122
141
|
### hide()
|
|
123
142
|
|
|
124
|
-
Скрыть
|
|
143
|
+
Скрыть UI таб-бара (сделать невидимым). Таб-бар остаётся в памяти.
|
|
125
144
|
|
|
126
145
|
```typescript
|
|
127
146
|
hide() => Promise<void>
|
|
@@ -137,10 +156,10 @@ setSelectedTab(options: SetSelectedTabOptions) => Promise<void>
|
|
|
137
156
|
|
|
138
157
|
### getState()
|
|
139
158
|
|
|
140
|
-
Вернуть текущее состояние: виден ли таб-бар и id активной вкладки.
|
|
159
|
+
Вернуть текущее состояние: инициализирован ли, виден ли таб-бар и id активной вкладки.
|
|
141
160
|
|
|
142
161
|
```typescript
|
|
143
|
-
getState() => Promise<{ visible: boolean, activeTabId: string }>
|
|
162
|
+
getState() => Promise<{ initialized: boolean, visible: boolean, activeTabId: string }>
|
|
144
163
|
```
|
|
145
164
|
|
|
146
165
|
### addListener('tabChange', listenerFunc)
|
|
@@ -153,13 +172,13 @@ addListener(eventName: 'tabChange', listenerFunc: (event: TabChangeEvent) => voi
|
|
|
153
172
|
|
|
154
173
|
## Интерфейсы
|
|
155
174
|
|
|
156
|
-
**
|
|
175
|
+
**InitOptions:** `tabs`, `selectedId`, `label_color?`, `label_color_active?`
|
|
157
176
|
|
|
158
177
|
**TabItem:** `id`, `label`, `base64_icon?`, `base64_active_icon?`
|
|
159
178
|
|
|
160
179
|
**SetSelectedTabOptions:** `tabId`
|
|
161
180
|
|
|
162
|
-
**GetStateResult:** `visible`, `activeTabId`
|
|
181
|
+
**GetStateResult:** `initialized`, `visible`, `activeTabId`
|
|
163
182
|
|
|
164
183
|
**TabChangeEvent:** `tabId`
|
|
165
184
|
|
|
@@ -102,7 +102,7 @@ class CapTabbar {
|
|
|
102
102
|
} catch (_: Exception) { null }
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
fun
|
|
105
|
+
fun initialize(parent: ViewGroup, tabs: List<TabItemData>, selectedId: String, labelColor: String? = null, labelColorActive: String? = null) {
|
|
106
106
|
this.parentView = parent
|
|
107
107
|
this.tabData = tabs
|
|
108
108
|
this.selectedId = selectedId
|
|
@@ -183,15 +183,25 @@ class CapTabbar {
|
|
|
183
183
|
|
|
184
184
|
parent.addView(bottomNav)
|
|
185
185
|
bottomNav.post { updateIcons() }
|
|
186
|
+
bottomNav.visibility = View.VISIBLE
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
fun
|
|
189
|
+
fun destroy() {
|
|
189
190
|
removeTabBar()
|
|
190
191
|
}
|
|
191
192
|
|
|
192
|
-
fun
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
fun show() {
|
|
194
|
+
bottomNav?.visibility = View.VISIBLE
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
fun hide() {
|
|
198
|
+
bottomNav?.visibility = View.GONE
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
fun getState(): Triple<Boolean, Boolean, String> {
|
|
202
|
+
val initialized = bottomNav != null
|
|
203
|
+
val visible = initialized && (bottomNav?.visibility == View.VISIBLE)
|
|
204
|
+
return Triple(initialized, visible, if (initialized) selectedId else "")
|
|
195
205
|
}
|
|
196
206
|
|
|
197
207
|
fun setSelectedTab(tabId: String) {
|
|
@@ -24,7 +24,7 @@ class CapTabbarPlugin : Plugin() {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
@PluginMethod
|
|
27
|
-
fun
|
|
27
|
+
fun `init`(call: PluginCall) {
|
|
28
28
|
val tabsArray = call.getArray("tabs")
|
|
29
29
|
val selectedId = call.getString("selectedId")
|
|
30
30
|
|
|
@@ -49,7 +49,23 @@ class CapTabbarPlugin : Plugin() {
|
|
|
49
49
|
call.reject("Could not find parent view to attach tab bar")
|
|
50
50
|
return@runOnUiThread
|
|
51
51
|
}
|
|
52
|
-
implementation.
|
|
52
|
+
implementation.initialize(parent, tabs, selectedId, labelColor, labelColorActive)
|
|
53
|
+
call.resolve()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@PluginMethod
|
|
58
|
+
fun destroy(call: PluginCall) {
|
|
59
|
+
getActivity().runOnUiThread {
|
|
60
|
+
implementation.destroy()
|
|
61
|
+
call.resolve()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@PluginMethod
|
|
66
|
+
fun show(call: PluginCall) {
|
|
67
|
+
getActivity().runOnUiThread {
|
|
68
|
+
implementation.show()
|
|
53
69
|
call.resolve()
|
|
54
70
|
}
|
|
55
71
|
}
|
|
@@ -79,8 +95,9 @@ class CapTabbarPlugin : Plugin() {
|
|
|
79
95
|
fun getState(call: PluginCall) {
|
|
80
96
|
val state = implementation.getState()
|
|
81
97
|
val result = JSObject().apply {
|
|
82
|
-
put("
|
|
83
|
-
put("
|
|
98
|
+
put("initialized", state.first)
|
|
99
|
+
put("visible", state.second)
|
|
100
|
+
put("activeTabId", state.third)
|
|
84
101
|
}
|
|
85
102
|
call.resolve(result)
|
|
86
103
|
}
|
package/dist/docs.json
CHANGED
|
@@ -6,21 +6,41 @@
|
|
|
6
6
|
"tags": [],
|
|
7
7
|
"methods": [
|
|
8
8
|
{
|
|
9
|
-
"name": "
|
|
10
|
-
"signature": "(options:
|
|
9
|
+
"name": "init",
|
|
10
|
+
"signature": "(options: InitOptions) => Promise<void>",
|
|
11
11
|
"parameters": [
|
|
12
12
|
{
|
|
13
13
|
"name": "options",
|
|
14
14
|
"docs": "",
|
|
15
|
-
"type": "
|
|
15
|
+
"type": "InitOptions"
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
18
|
"returns": "Promise<void>",
|
|
19
19
|
"tags": [],
|
|
20
|
-
"docs": "
|
|
20
|
+
"docs": "Initialize (create) the tab bar with the given configuration",
|
|
21
21
|
"complexTypes": [
|
|
22
|
-
"
|
|
22
|
+
"InitOptions"
|
|
23
23
|
],
|
|
24
|
+
"slug": "init"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"name": "destroy",
|
|
28
|
+
"signature": "() => Promise<void>",
|
|
29
|
+
"parameters": [],
|
|
30
|
+
"returns": "Promise<void>",
|
|
31
|
+
"tags": [],
|
|
32
|
+
"docs": "Destroy the tab bar completely (remove from view hierarchy)",
|
|
33
|
+
"complexTypes": [],
|
|
34
|
+
"slug": "destroy"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"name": "show",
|
|
38
|
+
"signature": "() => Promise<void>",
|
|
39
|
+
"parameters": [],
|
|
40
|
+
"returns": "Promise<void>",
|
|
41
|
+
"tags": [],
|
|
42
|
+
"docs": "Show the tab bar UI (make visible). Tab bar must be initialized.",
|
|
43
|
+
"complexTypes": [],
|
|
24
44
|
"slug": "show"
|
|
25
45
|
},
|
|
26
46
|
{
|
|
@@ -29,7 +49,7 @@
|
|
|
29
49
|
"parameters": [],
|
|
30
50
|
"returns": "Promise<void>",
|
|
31
51
|
"tags": [],
|
|
32
|
-
"docs": "Hide the tab bar",
|
|
52
|
+
"docs": "Hide the tab bar UI (make invisible). Tab bar stays in memory.",
|
|
33
53
|
"complexTypes": [],
|
|
34
54
|
"slug": "hide"
|
|
35
55
|
},
|
|
@@ -57,7 +77,7 @@
|
|
|
57
77
|
"parameters": [],
|
|
58
78
|
"returns": "Promise<GetStateResult>",
|
|
59
79
|
"tags": [],
|
|
60
|
-
"docs": "Get current state: visible and active tab id",
|
|
80
|
+
"docs": "Get current state: initialized, visible and active tab id",
|
|
61
81
|
"complexTypes": [
|
|
62
82
|
"GetStateResult"
|
|
63
83
|
],
|
|
@@ -91,8 +111,8 @@
|
|
|
91
111
|
},
|
|
92
112
|
"interfaces": [
|
|
93
113
|
{
|
|
94
|
-
"name": "
|
|
95
|
-
"slug": "
|
|
114
|
+
"name": "InitOptions",
|
|
115
|
+
"slug": "initoptions",
|
|
96
116
|
"docs": "Icons: 2 variants (base64 has priority over bundle)\n\n1) **Base64** – if `base64_icon` / `base64_active_icon` are set, they are used.\n\n2) **Bundle assets** – if base64 not set, icons are loaded from native resources:\n\n**Android** – `android/app/src/main/res/drawable/`:\n - `{id}.png` or `{id}.xml` – inactive icon\n - `{id}_active.png` or `{id}_active.xml` – active icon\n\n**iOS** – Assets.xcassets: Image Set `{id}` and `{id}_active`.\n\nIf an icon is missing, a placeholder is shown.",
|
|
97
117
|
"tags": [],
|
|
98
118
|
"methods": [],
|
|
@@ -189,17 +209,24 @@
|
|
|
189
209
|
"tags": [],
|
|
190
210
|
"methods": [],
|
|
191
211
|
"properties": [
|
|
212
|
+
{
|
|
213
|
+
"name": "initialized",
|
|
214
|
+
"tags": [],
|
|
215
|
+
"docs": "Whether the tab bar has been initialized (created)",
|
|
216
|
+
"complexTypes": [],
|
|
217
|
+
"type": "boolean"
|
|
218
|
+
},
|
|
192
219
|
{
|
|
193
220
|
"name": "visible",
|
|
194
221
|
"tags": [],
|
|
195
|
-
"docs": "Whether the tab bar is currently
|
|
222
|
+
"docs": "Whether the tab bar is currently visible to the user (false when hidden)",
|
|
196
223
|
"complexTypes": [],
|
|
197
224
|
"type": "boolean"
|
|
198
225
|
},
|
|
199
226
|
{
|
|
200
227
|
"name": "activeTabId",
|
|
201
228
|
"tags": [],
|
|
202
|
-
"docs": "ID of the active/selected tab (empty when
|
|
229
|
+
"docs": "ID of the active/selected tab (empty when destroyed)",
|
|
203
230
|
"complexTypes": [],
|
|
204
231
|
"type": "string"
|
|
205
232
|
}
|
|
@@ -23,7 +23,7 @@ export interface TabItem {
|
|
|
23
23
|
*
|
|
24
24
|
* If an icon is missing, a placeholder is shown.
|
|
25
25
|
*/
|
|
26
|
-
export interface
|
|
26
|
+
export interface InitOptions {
|
|
27
27
|
/** Array of tab items to display */
|
|
28
28
|
tabs: TabItem[];
|
|
29
29
|
/** ID of the initially selected tab */
|
|
@@ -33,6 +33,8 @@ export interface ShowOptions {
|
|
|
33
33
|
/** Label color for selected tab (hex, e.g. "#007AFF"). Default: blue */
|
|
34
34
|
label_color_active?: string;
|
|
35
35
|
}
|
|
36
|
+
/** @deprecated Use InitOptions */
|
|
37
|
+
export type ShowOptions = InitOptions;
|
|
36
38
|
export interface SetSelectedTabOptions {
|
|
37
39
|
/** ID of the tab to select */
|
|
38
40
|
tabId: string;
|
|
@@ -42,19 +44,25 @@ export interface TabChangeEvent {
|
|
|
42
44
|
tabId: string;
|
|
43
45
|
}
|
|
44
46
|
export interface GetStateResult {
|
|
45
|
-
/** Whether the tab bar
|
|
47
|
+
/** Whether the tab bar has been initialized (created) */
|
|
48
|
+
initialized: boolean;
|
|
49
|
+
/** Whether the tab bar is currently visible to the user (false when hidden) */
|
|
46
50
|
visible: boolean;
|
|
47
|
-
/** ID of the active/selected tab (empty when
|
|
51
|
+
/** ID of the active/selected tab (empty when destroyed) */
|
|
48
52
|
activeTabId: string;
|
|
49
53
|
}
|
|
50
54
|
export interface CapTabbarPlugin {
|
|
51
|
-
/**
|
|
52
|
-
|
|
53
|
-
/**
|
|
55
|
+
/** Initialize (create) the tab bar with the given configuration */
|
|
56
|
+
init(options: InitOptions): Promise<void>;
|
|
57
|
+
/** Destroy the tab bar completely (remove from view hierarchy) */
|
|
58
|
+
destroy(): Promise<void>;
|
|
59
|
+
/** Show the tab bar UI (make visible). Tab bar must be initialized. */
|
|
60
|
+
show(): Promise<void>;
|
|
61
|
+
/** Hide the tab bar UI (make invisible). Tab bar stays in memory. */
|
|
54
62
|
hide(): Promise<void>;
|
|
55
63
|
/** Programmatically set the selected tab */
|
|
56
64
|
setSelectedTab(options: SetSelectedTabOptions): Promise<void>;
|
|
57
|
-
/** Get current state: visible and active tab id */
|
|
65
|
+
/** Get current state: initialized, visible and active tab id */
|
|
58
66
|
getState(): Promise<GetStateResult>;
|
|
59
67
|
/** Add listener for tab change events (when user taps a tab) */
|
|
60
68
|
addListener(eventName: 'tabChange', listenerFunc: (event: TabChangeEvent) => void): Promise<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface TabItem {\n /** Unique identifier for the tab. Used for bundle assets: {id}.png, {id}_active.png */\n id: string;\n /** Display label */\n label: string;\n /** Base64-encoded image for inactive state. If set, overrides bundle assets */\n base64_icon?: string;\n /** Base64-encoded image for active/selected state. If set, overrides bundle assets */\n base64_active_icon?: string;\n}\n\n/**\n * Icons: 2 variants (base64 has priority over bundle)\n *\n * 1) **Base64** – if `base64_icon` / `base64_active_icon` are set, they are used.\n *\n * 2) **Bundle assets** – if base64 not set, icons are loaded from native resources:\n *\n * **Android** – `android/app/src/main/res/drawable/`:\n * - `{id}.png` or `{id}.xml` – inactive icon\n * - `{id}_active.png` or `{id}_active.xml` – active icon\n *\n * **iOS** – Assets.xcassets: Image Set `{id}` and `{id}_active`.\n *\n * If an icon is missing, a placeholder is shown.\n */\n\nexport interface
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface TabItem {\n /** Unique identifier for the tab. Used for bundle assets: {id}.png, {id}_active.png */\n id: string;\n /** Display label */\n label: string;\n /** Base64-encoded image for inactive state. If set, overrides bundle assets */\n base64_icon?: string;\n /** Base64-encoded image for active/selected state. If set, overrides bundle assets */\n base64_active_icon?: string;\n}\n\n/**\n * Icons: 2 variants (base64 has priority over bundle)\n *\n * 1) **Base64** – if `base64_icon` / `base64_active_icon` are set, they are used.\n *\n * 2) **Bundle assets** – if base64 not set, icons are loaded from native resources:\n *\n * **Android** – `android/app/src/main/res/drawable/`:\n * - `{id}.png` or `{id}.xml` – inactive icon\n * - `{id}_active.png` or `{id}_active.xml` – active icon\n *\n * **iOS** – Assets.xcassets: Image Set `{id}` and `{id}_active`.\n *\n * If an icon is missing, a placeholder is shown.\n */\n\nexport interface InitOptions {\n /** Array of tab items to display */\n tabs: TabItem[];\n /** ID of the initially selected tab */\n selectedId: string;\n /** Label color for inactive tabs (hex, e.g. \"#000000\"). Default: black */\n label_color?: string;\n /** Label color for selected tab (hex, e.g. \"#007AFF\"). Default: blue */\n label_color_active?: string;\n}\n\n/** @deprecated Use InitOptions */\nexport type ShowOptions = InitOptions;\n\nexport interface SetSelectedTabOptions {\n /** ID of the tab to select */\n tabId: string;\n}\n\nexport interface TabChangeEvent {\n /** ID of the newly selected tab */\n tabId: string;\n}\n\nexport interface GetStateResult {\n /** Whether the tab bar has been initialized (created) */\n initialized: boolean;\n /** Whether the tab bar is currently visible to the user (false when hidden) */\n visible: boolean;\n /** ID of the active/selected tab (empty when destroyed) */\n activeTabId: string;\n}\n\nexport interface CapTabbarPlugin {\n /** Initialize (create) the tab bar with the given configuration */\n init(options: InitOptions): Promise<void>;\n\n /** Destroy the tab bar completely (remove from view hierarchy) */\n destroy(): Promise<void>;\n\n /** Show the tab bar UI (make visible). Tab bar must be initialized. */\n show(): Promise<void>;\n\n /** Hide the tab bar UI (make invisible). Tab bar stays in memory. */\n hide(): Promise<void>;\n\n /** Programmatically set the selected tab */\n setSelectedTab(options: SetSelectedTabOptions): Promise<void>;\n\n /** Get current state: initialized, visible and active tab id */\n getState(): Promise<GetStateResult>;\n\n /** Add listener for tab change events (when user taps a tab) */\n addListener(\n eventName: 'tabChange',\n listenerFunc: (event: TabChangeEvent) => void\n ): Promise<{ remove: () => Promise<void> }>;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { CapTabbarPlugin, GetStateResult,
|
|
2
|
+
import type { CapTabbarPlugin, GetStateResult, InitOptions, SetSelectedTabOptions, TabChangeEvent } from './definitions';
|
|
3
3
|
export declare class CapTabbarWeb extends WebPlugin implements CapTabbarPlugin {
|
|
4
4
|
private tabBarContainer;
|
|
5
5
|
private tabItems;
|
|
@@ -7,7 +7,14 @@ export declare class CapTabbarWeb extends WebPlugin implements CapTabbarPlugin {
|
|
|
7
7
|
private labelColor;
|
|
8
8
|
private labelColorActive;
|
|
9
9
|
private tabElements;
|
|
10
|
-
|
|
10
|
+
private isVisible;
|
|
11
|
+
private tabChangeListeners;
|
|
12
|
+
addListener(_eventName: 'tabChange', listenerFunc: (event: TabChangeEvent) => void): Promise<{
|
|
13
|
+
remove: () => Promise<void>;
|
|
14
|
+
}>;
|
|
15
|
+
init(options: InitOptions): Promise<void>;
|
|
16
|
+
destroy(): Promise<void>;
|
|
17
|
+
show(): Promise<void>;
|
|
11
18
|
hide(): Promise<void>;
|
|
12
19
|
setSelectedTab(options: SetSelectedTabOptions): Promise<void>;
|
|
13
20
|
getState(): Promise<GetStateResult>;
|
|
@@ -15,5 +22,6 @@ export declare class CapTabbarWeb extends WebPlugin implements CapTabbarPlugin {
|
|
|
15
22
|
private removeTabBar;
|
|
16
23
|
private createTabBar;
|
|
17
24
|
private handleTabClick;
|
|
25
|
+
private emitTabChange;
|
|
18
26
|
private updateTabBarSelection;
|
|
19
27
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -8,31 +8,59 @@ export class CapTabbarWeb extends WebPlugin {
|
|
|
8
8
|
this.labelColor = '#000000';
|
|
9
9
|
this.labelColorActive = '#007AFF';
|
|
10
10
|
this.tabElements = new Map();
|
|
11
|
+
this.isVisible = false;
|
|
12
|
+
this.tabChangeListeners = [];
|
|
11
13
|
}
|
|
12
|
-
|
|
14
|
+
addListener(_eventName, listenerFunc) {
|
|
15
|
+
this.tabChangeListeners.push(listenerFunc);
|
|
16
|
+
return Promise.resolve({
|
|
17
|
+
remove: async () => {
|
|
18
|
+
const idx = this.tabChangeListeners.indexOf(listenerFunc);
|
|
19
|
+
if (idx >= 0)
|
|
20
|
+
this.tabChangeListeners.splice(idx, 1);
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
async init(options) {
|
|
13
25
|
var _a, _b;
|
|
14
26
|
this.tabItems = options.tabs;
|
|
15
27
|
this.selectedId = options.selectedId;
|
|
16
28
|
this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';
|
|
17
29
|
this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';
|
|
18
|
-
this.
|
|
30
|
+
this.destroy();
|
|
19
31
|
this.createTabBar();
|
|
32
|
+
this.isVisible = true;
|
|
20
33
|
}
|
|
21
|
-
async
|
|
34
|
+
async destroy() {
|
|
22
35
|
this.removeTabBar();
|
|
36
|
+
this.tabChangeListeners = [];
|
|
37
|
+
this.isVisible = false;
|
|
38
|
+
}
|
|
39
|
+
async show() {
|
|
40
|
+
if (this.tabBarContainer) {
|
|
41
|
+
this.tabBarContainer.style.display = 'flex';
|
|
42
|
+
this.isVisible = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async hide() {
|
|
46
|
+
if (this.tabBarContainer) {
|
|
47
|
+
this.tabBarContainer.style.display = 'none';
|
|
48
|
+
this.isVisible = false;
|
|
49
|
+
}
|
|
23
50
|
}
|
|
24
51
|
async setSelectedTab(options) {
|
|
25
52
|
if (this.selectedId === options.tabId)
|
|
26
53
|
return;
|
|
27
54
|
this.selectedId = options.tabId;
|
|
28
55
|
this.updateTabBarSelection();
|
|
29
|
-
this.
|
|
56
|
+
this.emitTabChange({ tabId: options.tabId });
|
|
30
57
|
}
|
|
31
58
|
async getState() {
|
|
32
|
-
const
|
|
59
|
+
const initialized = this.tabBarContainer != null;
|
|
33
60
|
return {
|
|
34
|
-
|
|
35
|
-
|
|
61
|
+
initialized,
|
|
62
|
+
visible: initialized && this.isVisible,
|
|
63
|
+
activeTabId: initialized ? this.selectedId : '',
|
|
36
64
|
};
|
|
37
65
|
}
|
|
38
66
|
base64ToDataUrl(base64, mime = 'image/png') {
|
|
@@ -109,7 +137,10 @@ export class CapTabbarWeb extends WebPlugin {
|
|
|
109
137
|
return;
|
|
110
138
|
this.selectedId = tabId;
|
|
111
139
|
this.updateTabBarSelection();
|
|
112
|
-
this.
|
|
140
|
+
this.emitTabChange({ tabId });
|
|
141
|
+
}
|
|
142
|
+
emitTabChange(event) {
|
|
143
|
+
this.tabChangeListeners.forEach((fn) => fn(event));
|
|
113
144
|
}
|
|
114
145
|
updateTabBarSelection() {
|
|
115
146
|
this.tabItems.forEach((tab) => {
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,OAAO,YAAa,SAAQ,SAAS;IAA3C;;QACU,oBAAe,GAAuB,IAAI,CAAC;QAC3C,aAAQ,GAAuF,EAAE,CAAC;QAClG,eAAU,GAAW,EAAE,CAAC;QACxB,eAAU,GAAW,SAAS,CAAC;QAC/B,qBAAgB,GAAW,SAAS,CAAC;QACrC,gBAAW,GAGf,IAAI,GAAG,EAAE,CAAC;IA+HhB,CAAC;IA7HC,KAAK,CAAC,IAAI,CAAC,OAAoB;;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,WAAW,mCAAI,SAA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AC,UAAU,CAAC;YACjF,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapTabbarPlugin,\n GetStateResult,\n ShowOptions,\n SetSelectedTabOptions,\n TabChangeEvent,\n} from './definitions';\n\nexport class CapTabbarWeb extends WebPlugin implements CapTabbarPlugin {\n private tabBarContainer: HTMLElement | null = null;\n private tabItems: { id: string; label: string; base64_icon?: string; base64_active_icon?: string }[] = [];\n private selectedId: string = '';\n private labelColor: string = '#000000';\n private labelColorActive: string = '#007AFF';\n private tabElements: Map<\n string,\n { iconEl: HTMLImageElement; labelEl: HTMLSpanElement }\n > = new Map();\n\n async show(options: ShowOptions): Promise<void> {\n this.tabItems = options.tabs;\n this.selectedId = options.selectedId;\n this.labelColor = options.label_color ?? '#000000';\n this.labelColorActive = options.label_color_active ?? '#007AFF';\n\n this.removeTabBar();\n this.createTabBar();\n }\n\n async hide(): Promise<void> {\n this.removeTabBar();\n }\n\n async setSelectedTab(options: SetSelectedTabOptions): Promise<void> {\n if (this.selectedId === options.tabId) return;\n this.selectedId = options.tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId: options.tabId });\n }\n\n async getState(): Promise<GetStateResult> {\n const visible = this.tabBarContainer != null;\n return {\n visible,\n activeTabId: visible ? this.selectedId : '',\n };\n }\n\n private base64ToDataUrl(base64: string, mime = 'image/png'): string {\n const clean = base64.startsWith('data:') ? (base64.match(/base64,(.+)$/)?.[1] ?? base64) : base64;\n return `data:${mime};base64,${clean}`;\n }\n\n private removeTabBar(): void {\n if (this.tabBarContainer) {\n this.tabBarContainer.remove();\n this.tabBarContainer = null;\n this.tabElements.clear();\n }\n }\n\n private createTabBar(): void {\n const container = document.createElement('div');\n container.id = 'capacitor-native-tabbar-web';\n Object.assign(container.style, {\n position: 'fixed',\n bottom: '0',\n left: '0',\n right: '0',\n height: '56px',\n display: 'flex',\n backgroundColor: '#ffffff',\n borderTop: '1px solid #e0e0e0',\n boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',\n zIndex: '9999',\n });\n\n this.tabItems.forEach((tab) => {\n const tabEl = document.createElement('button');\n tabEl.dataset.tabId = tab.id;\n tabEl.type = 'button';\n Object.assign(tabEl.style, {\n flex: '1',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: '4px',\n border: 'none',\n background: 'transparent',\n cursor: 'pointer',\n padding: '8px 4px',\n });\n\n const iconEl = document.createElement('img');\n iconEl.style.width = '24px';\n iconEl.style.height = '24px';\n iconEl.style.objectFit = 'contain';\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? (tab.base64_active_icon ?? tab.base64_icon) : (tab.base64_icon ?? tab.base64_active_icon);\n iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><circle cx=\"12\" cy=\"12\" r=\"8\"/></svg>';\n\n const labelEl = document.createElement('span');\n labelEl.textContent = tab.label;\n Object.assign(labelEl.style, {\n fontSize: '10px',\n color: isActive ? this.labelColorActive : this.labelColor,\n });\n\n tabEl.appendChild(iconEl);\n tabEl.appendChild(labelEl);\n\n tabEl.addEventListener('click', () => {\n this.handleTabClick(tab.id);\n });\n\n container.appendChild(tabEl);\n this.tabElements.set(tab.id, { iconEl, labelEl });\n });\n\n document.body.appendChild(container);\n this.tabBarContainer = container;\n }\n\n private handleTabClick(tabId: string): void {\n const tab = this.tabItems.find((t) => t.id === tabId);\n if (!tab || this.selectedId === tabId) return;\n\n this.selectedId = tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId } as TabChangeEvent);\n }\n\n private updateTabBarSelection(): void {\n this.tabItems.forEach((tab) => {\n const entry = this.tabElements.get(tab.id);\n if (entry) {\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? (tab.base64_active_icon ?? tab.base64_icon) : (tab.base64_icon ?? tab.base64_active_icon);\n if (iconData) entry.iconEl.src = this.base64ToDataUrl(iconData);\n entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;\n }\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAU5C,MAAM,OAAO,YAAa,SAAQ,SAAS;IAA3C;;QACU,oBAAe,GAAuB,IAAI,CAAC;QAC3C,aAAQ,GAAuF,EAAE,CAAC;QAClG,eAAU,GAAW,EAAE,CAAC;QACxB,eAAU,GAAW,SAAS,CAAC;QAC/B,qBAAgB,GAAW,SAAS,CAAC;QACrC,gBAAW,GAGf,IAAI,GAAG,EAAE,CAAC;QACN,cAAS,GAAG,KAAK,CAAC;QAClB,uBAAkB,GAA2C,EAAE,CAAC;IAkK1E,CAAC;IAhKC,WAAW,CACT,UAAuB,EACvB,YAA6C;QAE7C,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QAC3C,OAAO,OAAO,CAAC,OAAO,CAAC;YACrB,MAAM,EAAE,KAAK,IAAI,EAAE;gBACjB,MAAM,GAAG,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;gBAC1D,IAAI,GAAG,IAAI,CAAC;oBAAE,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;YACvD,CAAC;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAoB;;QAC7B,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;QAC7B,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,MAAA,OAAO,CAAC,WAAW,mCAAI,SAAS,CAAC;QACnD,IAAI,CAAC,gBAAg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C,GAAG,EAAE,EAAE;;YAC5B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;YAC3C,IAAI,KAAK,EAAE,CAAC;gBACV,MAAM,QAAQ,GAAG,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,UAAU,CAAC;gBAC5C,MAAM,QAAQ,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,MAAA,GAAG,CAAC,kBAAkB,mCAAI,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAA,GAAG,CAAC,WAAW,mCAAI,GAAG,CAAC,kBAAkB,CAAC,CAAC;gBACtH,IAAI,QAAQ;oBAAE,KAAK,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;gBAChE,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC;YACjF,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import { WebPlugin } from '@capacitor/core';\n\nimport type {\n CapTabbarPlugin,\n GetStateResult,\n InitOptions,\n SetSelectedTabOptions,\n TabChangeEvent,\n} from './definitions';\n\nexport class CapTabbarWeb extends WebPlugin implements CapTabbarPlugin {\n private tabBarContainer: HTMLElement | null = null;\n private tabItems: { id: string; label: string; base64_icon?: string; base64_active_icon?: string }[] = [];\n private selectedId: string = '';\n private labelColor: string = '#000000';\n private labelColorActive: string = '#007AFF';\n private tabElements: Map<\n string,\n { iconEl: HTMLImageElement; labelEl: HTMLSpanElement }\n > = new Map();\n private isVisible = false;\n private tabChangeListeners: Array<(event: TabChangeEvent) => void> = [];\n\n addListener(\n _eventName: 'tabChange',\n listenerFunc: (event: TabChangeEvent) => void\n ): Promise<{ remove: () => Promise<void> }> {\n this.tabChangeListeners.push(listenerFunc);\n return Promise.resolve({\n remove: async () => {\n const idx = this.tabChangeListeners.indexOf(listenerFunc);\n if (idx >= 0) this.tabChangeListeners.splice(idx, 1);\n },\n });\n }\n\n async init(options: InitOptions): Promise<void> {\n this.tabItems = options.tabs;\n this.selectedId = options.selectedId;\n this.labelColor = options.label_color ?? '#000000';\n this.labelColorActive = options.label_color_active ?? '#007AFF';\n\n this.destroy();\n this.createTabBar();\n this.isVisible = true;\n }\n\n async destroy(): Promise<void> {\n this.removeTabBar();\n this.tabChangeListeners = [];\n this.isVisible = false;\n }\n\n async show(): Promise<void> {\n if (this.tabBarContainer) {\n this.tabBarContainer.style.display = 'flex';\n this.isVisible = true;\n }\n }\n\n async hide(): Promise<void> {\n if (this.tabBarContainer) {\n this.tabBarContainer.style.display = 'none';\n this.isVisible = false;\n }\n }\n\n async setSelectedTab(options: SetSelectedTabOptions): Promise<void> {\n if (this.selectedId === options.tabId) return;\n this.selectedId = options.tabId;\n this.updateTabBarSelection();\n this.emitTabChange({ tabId: options.tabId });\n }\n\n async getState(): Promise<GetStateResult> {\n const initialized = this.tabBarContainer != null;\n return {\n initialized,\n visible: initialized && this.isVisible,\n activeTabId: initialized ? this.selectedId : '',\n };\n }\n\n private base64ToDataUrl(base64: string, mime = 'image/png'): string {\n const clean = base64.startsWith('data:') ? (base64.match(/base64,(.+)$/)?.[1] ?? base64) : base64;\n return `data:${mime};base64,${clean}`;\n }\n\n private removeTabBar(): void {\n if (this.tabBarContainer) {\n this.tabBarContainer.remove();\n this.tabBarContainer = null;\n this.tabElements.clear();\n }\n }\n\n private createTabBar(): void {\n const container = document.createElement('div');\n container.id = 'capacitor-native-tabbar-web';\n Object.assign(container.style, {\n position: 'fixed',\n bottom: '0',\n left: '0',\n right: '0',\n height: '56px',\n display: 'flex',\n backgroundColor: '#ffffff',\n borderTop: '1px solid #e0e0e0',\n boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',\n zIndex: '9999',\n });\n\n this.tabItems.forEach((tab) => {\n const tabEl = document.createElement('button');\n tabEl.dataset.tabId = tab.id;\n tabEl.type = 'button';\n Object.assign(tabEl.style, {\n flex: '1',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: '4px',\n border: 'none',\n background: 'transparent',\n cursor: 'pointer',\n padding: '8px 4px',\n });\n\n const iconEl = document.createElement('img');\n iconEl.style.width = '24px';\n iconEl.style.height = '24px';\n iconEl.style.objectFit = 'contain';\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? (tab.base64_active_icon ?? tab.base64_icon) : (tab.base64_icon ?? tab.base64_active_icon);\n iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><circle cx=\"12\" cy=\"12\" r=\"8\"/></svg>';\n\n const labelEl = document.createElement('span');\n labelEl.textContent = tab.label;\n Object.assign(labelEl.style, {\n fontSize: '10px',\n color: isActive ? this.labelColorActive : this.labelColor,\n });\n\n tabEl.appendChild(iconEl);\n tabEl.appendChild(labelEl);\n\n tabEl.addEventListener('click', () => {\n this.handleTabClick(tab.id);\n });\n\n container.appendChild(tabEl);\n this.tabElements.set(tab.id, { iconEl, labelEl });\n });\n\n document.body.appendChild(container);\n this.tabBarContainer = container;\n }\n\n private handleTabClick(tabId: string): void {\n const tab = this.tabItems.find((t) => t.id === tabId);\n if (!tab || this.selectedId === tabId) return;\n\n this.selectedId = tabId;\n this.updateTabBarSelection();\n this.emitTabChange({ tabId });\n }\n\n private emitTabChange(event: TabChangeEvent): void {\n this.tabChangeListeners.forEach((fn) => fn(event));\n }\n\n private updateTabBarSelection(): void {\n this.tabItems.forEach((tab) => {\n const entry = this.tabElements.get(tab.id);\n if (entry) {\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? (tab.base64_active_icon ?? tab.base64_icon) : (tab.base64_icon ?? tab.base64_active_icon);\n if (iconData) entry.iconEl.src = this.base64ToDataUrl(iconData);\n entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;\n }\n });\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -15,31 +15,59 @@ class CapTabbarWeb extends core.WebPlugin {
|
|
|
15
15
|
this.labelColor = '#000000';
|
|
16
16
|
this.labelColorActive = '#007AFF';
|
|
17
17
|
this.tabElements = new Map();
|
|
18
|
+
this.isVisible = false;
|
|
19
|
+
this.tabChangeListeners = [];
|
|
18
20
|
}
|
|
19
|
-
|
|
21
|
+
addListener(_eventName, listenerFunc) {
|
|
22
|
+
this.tabChangeListeners.push(listenerFunc);
|
|
23
|
+
return Promise.resolve({
|
|
24
|
+
remove: async () => {
|
|
25
|
+
const idx = this.tabChangeListeners.indexOf(listenerFunc);
|
|
26
|
+
if (idx >= 0)
|
|
27
|
+
this.tabChangeListeners.splice(idx, 1);
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async init(options) {
|
|
20
32
|
var _a, _b;
|
|
21
33
|
this.tabItems = options.tabs;
|
|
22
34
|
this.selectedId = options.selectedId;
|
|
23
35
|
this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';
|
|
24
36
|
this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';
|
|
25
|
-
this.
|
|
37
|
+
this.destroy();
|
|
26
38
|
this.createTabBar();
|
|
39
|
+
this.isVisible = true;
|
|
27
40
|
}
|
|
28
|
-
async
|
|
41
|
+
async destroy() {
|
|
29
42
|
this.removeTabBar();
|
|
43
|
+
this.tabChangeListeners = [];
|
|
44
|
+
this.isVisible = false;
|
|
45
|
+
}
|
|
46
|
+
async show() {
|
|
47
|
+
if (this.tabBarContainer) {
|
|
48
|
+
this.tabBarContainer.style.display = 'flex';
|
|
49
|
+
this.isVisible = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
async hide() {
|
|
53
|
+
if (this.tabBarContainer) {
|
|
54
|
+
this.tabBarContainer.style.display = 'none';
|
|
55
|
+
this.isVisible = false;
|
|
56
|
+
}
|
|
30
57
|
}
|
|
31
58
|
async setSelectedTab(options) {
|
|
32
59
|
if (this.selectedId === options.tabId)
|
|
33
60
|
return;
|
|
34
61
|
this.selectedId = options.tabId;
|
|
35
62
|
this.updateTabBarSelection();
|
|
36
|
-
this.
|
|
63
|
+
this.emitTabChange({ tabId: options.tabId });
|
|
37
64
|
}
|
|
38
65
|
async getState() {
|
|
39
|
-
const
|
|
66
|
+
const initialized = this.tabBarContainer != null;
|
|
40
67
|
return {
|
|
41
|
-
|
|
42
|
-
|
|
68
|
+
initialized,
|
|
69
|
+
visible: initialized && this.isVisible,
|
|
70
|
+
activeTabId: initialized ? this.selectedId : '',
|
|
43
71
|
};
|
|
44
72
|
}
|
|
45
73
|
base64ToDataUrl(base64, mime = 'image/png') {
|
|
@@ -116,7 +144,10 @@ class CapTabbarWeb extends core.WebPlugin {
|
|
|
116
144
|
return;
|
|
117
145
|
this.selectedId = tabId;
|
|
118
146
|
this.updateTabBarSelection();
|
|
119
|
-
this.
|
|
147
|
+
this.emitTabChange({ tabId });
|
|
148
|
+
}
|
|
149
|
+
emitTabChange(event) {
|
|
150
|
+
this.tabChangeListeners.forEach((fn) => fn(event));
|
|
120
151
|
}
|
|
121
152
|
updateTabBarSelection() {
|
|
122
153
|
this.tabItems.forEach((tab) => {
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapTabbar = registerPlugin('CapTabbar', {\n web: () => import('./web').then((m) => new m.CapTabbarWeb()),\n});\nexport * from './definitions';\nexport { CapTabbar };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapTabbarWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.tabBarContainer = null;\n this.tabItems = [];\n this.selectedId = '';\n this.labelColor = '#000000';\n this.labelColorActive = '#007AFF';\n this.tabElements = new Map();\n }\n async show(options) {\n var _a, _b;\n this.tabItems = options.tabs;\n this.selectedId = options.selectedId;\n this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';\n this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';\n this.removeTabBar();\n this.createTabBar();\n }\n async hide() {\n this.removeTabBar();\n }\n async setSelectedTab(options) {\n if (this.selectedId === options.tabId)\n return;\n this.selectedId = options.tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId: options.tabId });\n }\n async getState() {\n const visible = this.tabBarContainer != null;\n return {\n visible,\n activeTabId: visible ? this.selectedId : '',\n };\n }\n base64ToDataUrl(base64, mime = 'image/png') {\n var _a, _b;\n const clean = base64.startsWith('data:') ? ((_b = (_a = base64.match(/base64,(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : base64) : base64;\n return `data:${mime};base64,${clean}`;\n }\n removeTabBar() {\n if (this.tabBarContainer) {\n this.tabBarContainer.remove();\n this.tabBarContainer = null;\n this.tabElements.clear();\n }\n }\n createTabBar() {\n const container = document.createElement('div');\n container.id = 'capacitor-native-tabbar-web';\n Object.assign(container.style, {\n position: 'fixed',\n bottom: '0',\n left: '0',\n right: '0',\n height: '56px',\n display: 'flex',\n backgroundColor: '#ffffff',\n borderTop: '1px solid #e0e0e0',\n boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',\n zIndex: '9999',\n });\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const tabEl = document.createElement('button');\n tabEl.dataset.tabId = tab.id;\n tabEl.type = 'button';\n Object.assign(tabEl.style, {\n flex: '1',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: '4px',\n border: 'none',\n background: 'transparent',\n cursor: 'pointer',\n padding: '8px 4px',\n });\n const iconEl = document.createElement('img');\n iconEl.style.width = '24px';\n iconEl.style.height = '24px';\n iconEl.style.objectFit = 'contain';\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><circle cx=\"12\" cy=\"12\" r=\"8\"/></svg>';\n const labelEl = document.createElement('span');\n labelEl.textContent = tab.label;\n Object.assign(labelEl.style, {\n fontSize: '10px',\n color: isActive ? this.labelColorActive : this.labelColor,\n });\n tabEl.appendChild(iconEl);\n tabEl.appendChild(labelEl);\n tabEl.addEventListener('click', () => {\n this.handleTabClick(tab.id);\n });\n container.appendChild(tabEl);\n this.tabElements.set(tab.id, { iconEl, labelEl });\n });\n document.body.appendChild(container);\n this.tabBarContainer = container;\n }\n handleTabClick(tabId) {\n const tab = this.tabItems.find((t) => t.id === tabId);\n if (!tab || this.selectedId === tabId)\n return;\n this.selectedId = tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId });\n }\n updateTabBarSelection() {\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const entry = this.tabElements.get(tab.id);\n if (entry) {\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n if (iconData)\n entry.iconEl.src = this.base64ToDataUrl(iconData);\n entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;\n }\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,SAAS,GAAGA,mBAAc,CAAC,WAAW,EAAE;AAC9C,IAAI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G,GAAG,CAAC,kBAAkB,CAAC;AAC/M,gBAAgB,IAAI,QAAQ;AAC5B,oBAAoB,KAAK,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC;AACrE,gBAAgB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,UAAU;AAC9F,YAAY;AACZ,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapTabbar = registerPlugin('CapTabbar', {\n web: () => import('./web').then((m) => new m.CapTabbarWeb()),\n});\nexport * from './definitions';\nexport { CapTabbar };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapTabbarWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.tabBarContainer = null;\n this.tabItems = [];\n this.selectedId = '';\n this.labelColor = '#000000';\n this.labelColorActive = '#007AFF';\n this.tabElements = new Map();\n this.isVisible = false;\n this.tabChangeListeners = [];\n }\n addListener(_eventName, listenerFunc) {\n this.tabChangeListeners.push(listenerFunc);\n return Promise.resolve({\n remove: async () => {\n const idx = this.tabChangeListeners.indexOf(listenerFunc);\n if (idx >= 0)\n this.tabChangeListeners.splice(idx, 1);\n },\n });\n }\n async init(options) {\n var _a, _b;\n this.tabItems = options.tabs;\n this.selectedId = options.selectedId;\n this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';\n this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';\n this.destroy();\n this.createTabBar();\n this.isVisible = true;\n }\n async destroy() {\n this.removeTabBar();\n this.tabChangeListeners = [];\n this.isVisible = false;\n }\n async show() {\n if (this.tabBarContainer) {\n this.tabBarContainer.style.display = 'flex';\n this.isVisible = true;\n }\n }\n async hide() {\n if (this.tabBarContainer) {\n this.tabBarContainer.style.display = 'none';\n this.isVisible = false;\n }\n }\n async setSelectedTab(options) {\n if (this.selectedId === options.tabId)\n return;\n this.selectedId = options.tabId;\n this.updateTabBarSelection();\n this.emitTabChange({ tabId: options.tabId });\n }\n async getState() {\n const initialized = this.tabBarContainer != null;\n return {\n initialized,\n visible: initialized && this.isVisible,\n activeTabId: initialized ? this.selectedId : '',\n };\n }\n base64ToDataUrl(base64, mime = 'image/png') {\n var _a, _b;\n const clean = base64.startsWith('data:') ? ((_b = (_a = base64.match(/base64,(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : base64) : base64;\n return `data:${mime};base64,${clean}`;\n }\n removeTabBar() {\n if (this.tabBarContainer) {\n this.tabBarContainer.remove();\n this.tabBarContainer = null;\n this.tabElements.clear();\n }\n }\n createTabBar() {\n const container = document.createElement('div');\n container.id = 'capacitor-native-tabbar-web';\n Object.assign(container.style, {\n position: 'fixed',\n bottom: '0',\n left: '0',\n right: '0',\n height: '56px',\n display: 'flex',\n backgroundColor: '#ffffff',\n borderTop: '1px solid #e0e0e0',\n boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',\n zIndex: '9999',\n });\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const tabEl = document.createElement('button');\n tabEl.dataset.tabId = tab.id;\n tabEl.type = 'button';\n Object.assign(tabEl.style, {\n flex: '1',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: '4px',\n border: 'none',\n background: 'transparent',\n cursor: 'pointer',\n padding: '8px 4px',\n });\n const iconEl = document.createElement('img');\n iconEl.style.width = '24px';\n iconEl.style.height = '24px';\n iconEl.style.objectFit = 'contain';\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><circle cx=\"12\" cy=\"12\" r=\"8\"/></svg>';\n const labelEl = document.createElement('span');\n labelEl.textContent = tab.label;\n Object.assign(labelEl.style, {\n fontSize: '10px',\n color: isActive ? this.labelColorActive : this.labelColor,\n });\n tabEl.appendChild(iconEl);\n tabEl.appendChild(labelEl);\n tabEl.addEventListener('click', () => {\n this.handleTabClick(tab.id);\n });\n container.appendChild(tabEl);\n this.tabElements.set(tab.id, { iconEl, labelEl });\n });\n document.body.appendChild(container);\n this.tabBarContainer = container;\n }\n handleTabClick(tabId) {\n const tab = this.tabItems.find((t) => t.id === tabId);\n if (!tab || this.selectedId === tabId)\n return;\n this.selectedId = tabId;\n this.updateTabBarSelection();\n this.emitTabChange({ tabId });\n }\n emitTabChange(event) {\n this.tabChangeListeners.forEach((fn) => fn(event));\n }\n updateTabBarSelection() {\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const entry = this.tabElements.get(tab.id);\n if (entry) {\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n if (iconData)\n entry.iconEl.src = this.base64ToDataUrl(iconData);\n entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;\n }\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;AACK,MAAC,SAAS,GAAGA,mBAAc,CAAC,WAAW,EAAE;AAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,YAAY,EAAE,CAAC;AAChE,CAAC;;ACFM,MAAM,YAAY,SAASC,cAAS,CAAC;AAC5C,IAAI,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AC;AACrE,gBAAgB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,UAAU;AAC9F,YAAY;AACZ,QAAQ,CAAC,CAAC;AACV,IAAI;AACJ;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -14,31 +14,59 @@ var capacitorCapTabbar = (function (exports, core) {
|
|
|
14
14
|
this.labelColor = '#000000';
|
|
15
15
|
this.labelColorActive = '#007AFF';
|
|
16
16
|
this.tabElements = new Map();
|
|
17
|
+
this.isVisible = false;
|
|
18
|
+
this.tabChangeListeners = [];
|
|
17
19
|
}
|
|
18
|
-
|
|
20
|
+
addListener(_eventName, listenerFunc) {
|
|
21
|
+
this.tabChangeListeners.push(listenerFunc);
|
|
22
|
+
return Promise.resolve({
|
|
23
|
+
remove: async () => {
|
|
24
|
+
const idx = this.tabChangeListeners.indexOf(listenerFunc);
|
|
25
|
+
if (idx >= 0)
|
|
26
|
+
this.tabChangeListeners.splice(idx, 1);
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
async init(options) {
|
|
19
31
|
var _a, _b;
|
|
20
32
|
this.tabItems = options.tabs;
|
|
21
33
|
this.selectedId = options.selectedId;
|
|
22
34
|
this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';
|
|
23
35
|
this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';
|
|
24
|
-
this.
|
|
36
|
+
this.destroy();
|
|
25
37
|
this.createTabBar();
|
|
38
|
+
this.isVisible = true;
|
|
26
39
|
}
|
|
27
|
-
async
|
|
40
|
+
async destroy() {
|
|
28
41
|
this.removeTabBar();
|
|
42
|
+
this.tabChangeListeners = [];
|
|
43
|
+
this.isVisible = false;
|
|
44
|
+
}
|
|
45
|
+
async show() {
|
|
46
|
+
if (this.tabBarContainer) {
|
|
47
|
+
this.tabBarContainer.style.display = 'flex';
|
|
48
|
+
this.isVisible = true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
async hide() {
|
|
52
|
+
if (this.tabBarContainer) {
|
|
53
|
+
this.tabBarContainer.style.display = 'none';
|
|
54
|
+
this.isVisible = false;
|
|
55
|
+
}
|
|
29
56
|
}
|
|
30
57
|
async setSelectedTab(options) {
|
|
31
58
|
if (this.selectedId === options.tabId)
|
|
32
59
|
return;
|
|
33
60
|
this.selectedId = options.tabId;
|
|
34
61
|
this.updateTabBarSelection();
|
|
35
|
-
this.
|
|
62
|
+
this.emitTabChange({ tabId: options.tabId });
|
|
36
63
|
}
|
|
37
64
|
async getState() {
|
|
38
|
-
const
|
|
65
|
+
const initialized = this.tabBarContainer != null;
|
|
39
66
|
return {
|
|
40
|
-
|
|
41
|
-
|
|
67
|
+
initialized,
|
|
68
|
+
visible: initialized && this.isVisible,
|
|
69
|
+
activeTabId: initialized ? this.selectedId : '',
|
|
42
70
|
};
|
|
43
71
|
}
|
|
44
72
|
base64ToDataUrl(base64, mime = 'image/png') {
|
|
@@ -115,7 +143,10 @@ var capacitorCapTabbar = (function (exports, core) {
|
|
|
115
143
|
return;
|
|
116
144
|
this.selectedId = tabId;
|
|
117
145
|
this.updateTabBarSelection();
|
|
118
|
-
this.
|
|
146
|
+
this.emitTabChange({ tabId });
|
|
147
|
+
}
|
|
148
|
+
emitTabChange(event) {
|
|
149
|
+
this.tabChangeListeners.forEach((fn) => fn(event));
|
|
119
150
|
}
|
|
120
151
|
updateTabBarSelection() {
|
|
121
152
|
this.tabItems.forEach((tab) => {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapTabbar = registerPlugin('CapTabbar', {\n web: () => import('./web').then((m) => new m.CapTabbarWeb()),\n});\nexport * from './definitions';\nexport { CapTabbar };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapTabbarWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.tabBarContainer = null;\n this.tabItems = [];\n this.selectedId = '';\n this.labelColor = '#000000';\n this.labelColorActive = '#007AFF';\n this.tabElements = new Map();\n }\n async show(options) {\n var _a, _b;\n this.tabItems = options.tabs;\n this.selectedId = options.selectedId;\n this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';\n this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';\n this.removeTabBar();\n this.createTabBar();\n }\n async hide() {\n this.removeTabBar();\n }\n async setSelectedTab(options) {\n if (this.selectedId === options.tabId)\n return;\n this.selectedId = options.tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId: options.tabId });\n }\n async getState() {\n const visible = this.tabBarContainer != null;\n return {\n visible,\n activeTabId: visible ? this.selectedId : '',\n };\n }\n base64ToDataUrl(base64, mime = 'image/png') {\n var _a, _b;\n const clean = base64.startsWith('data:') ? ((_b = (_a = base64.match(/base64,(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : base64) : base64;\n return `data:${mime};base64,${clean}`;\n }\n removeTabBar() {\n if (this.tabBarContainer) {\n this.tabBarContainer.remove();\n this.tabBarContainer = null;\n this.tabElements.clear();\n }\n }\n createTabBar() {\n const container = document.createElement('div');\n container.id = 'capacitor-native-tabbar-web';\n Object.assign(container.style, {\n position: 'fixed',\n bottom: '0',\n left: '0',\n right: '0',\n height: '56px',\n display: 'flex',\n backgroundColor: '#ffffff',\n borderTop: '1px solid #e0e0e0',\n boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',\n zIndex: '9999',\n });\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const tabEl = document.createElement('button');\n tabEl.dataset.tabId = tab.id;\n tabEl.type = 'button';\n Object.assign(tabEl.style, {\n flex: '1',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: '4px',\n border: 'none',\n background: 'transparent',\n cursor: 'pointer',\n padding: '8px 4px',\n });\n const iconEl = document.createElement('img');\n iconEl.style.width = '24px';\n iconEl.style.height = '24px';\n iconEl.style.objectFit = 'contain';\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><circle cx=\"12\" cy=\"12\" r=\"8\"/></svg>';\n const labelEl = document.createElement('span');\n labelEl.textContent = tab.label;\n Object.assign(labelEl.style, {\n fontSize: '10px',\n color: isActive ? this.labelColorActive : this.labelColor,\n });\n tabEl.appendChild(iconEl);\n tabEl.appendChild(labelEl);\n tabEl.addEventListener('click', () => {\n this.handleTabClick(tab.id);\n });\n container.appendChild(tabEl);\n this.tabElements.set(tab.id, { iconEl, labelEl });\n });\n document.body.appendChild(container);\n this.tabBarContainer = container;\n }\n handleTabClick(tabId) {\n const tab = this.tabItems.find((t) => t.id === tabId);\n if (!tab || this.selectedId === tabId)\n return;\n this.selectedId = tabId;\n this.updateTabBarSelection();\n this.notifyListeners('tabChange', { tabId });\n }\n updateTabBarSelection() {\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const entry = this.tabElements.get(tab.id);\n if (entry) {\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n if (iconData)\n entry.iconEl.src = this.base64ToDataUrl(iconData);\n entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;\n }\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlug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,EAAE,GAAG,GAAG,CAAC,WAAW,MAAM,IAAI,IAAI,EAAE,KAAK,MAAM,GAAG,EAAE,GAAG,GAAG,CAAC,kBAAkB,CAAC;IAC/M,gBAAgB,IAAI,QAAQ;IAC5B,oBAAoB,KAAK,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC;IACrE,gBAAgB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,UAAU;IAC9F,YAAY;IACZ,QAAQ,CAAC,CAAC;IACV,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst CapTabbar = registerPlugin('CapTabbar', {\n web: () => import('./web').then((m) => new m.CapTabbarWeb()),\n});\nexport * from './definitions';\nexport { CapTabbar };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nexport class CapTabbarWeb extends WebPlugin {\n constructor() {\n super(...arguments);\n this.tabBarContainer = null;\n this.tabItems = [];\n this.selectedId = '';\n this.labelColor = '#000000';\n this.labelColorActive = '#007AFF';\n this.tabElements = new Map();\n this.isVisible = false;\n this.tabChangeListeners = [];\n }\n addListener(_eventName, listenerFunc) {\n this.tabChangeListeners.push(listenerFunc);\n return Promise.resolve({\n remove: async () => {\n const idx = this.tabChangeListeners.indexOf(listenerFunc);\n if (idx >= 0)\n this.tabChangeListeners.splice(idx, 1);\n },\n });\n }\n async init(options) {\n var _a, _b;\n this.tabItems = options.tabs;\n this.selectedId = options.selectedId;\n this.labelColor = (_a = options.label_color) !== null && _a !== void 0 ? _a : '#000000';\n this.labelColorActive = (_b = options.label_color_active) !== null && _b !== void 0 ? _b : '#007AFF';\n this.destroy();\n this.createTabBar();\n this.isVisible = true;\n }\n async destroy() {\n this.removeTabBar();\n this.tabChangeListeners = [];\n this.isVisible = false;\n }\n async show() {\n if (this.tabBarContainer) {\n this.tabBarContainer.style.display = 'flex';\n this.isVisible = true;\n }\n }\n async hide() {\n if (this.tabBarContainer) {\n this.tabBarContainer.style.display = 'none';\n this.isVisible = false;\n }\n }\n async setSelectedTab(options) {\n if (this.selectedId === options.tabId)\n return;\n this.selectedId = options.tabId;\n this.updateTabBarSelection();\n this.emitTabChange({ tabId: options.tabId });\n }\n async getState() {\n const initialized = this.tabBarContainer != null;\n return {\n initialized,\n visible: initialized && this.isVisible,\n activeTabId: initialized ? this.selectedId : '',\n };\n }\n base64ToDataUrl(base64, mime = 'image/png') {\n var _a, _b;\n const clean = base64.startsWith('data:') ? ((_b = (_a = base64.match(/base64,(.+)$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : base64) : base64;\n return `data:${mime};base64,${clean}`;\n }\n removeTabBar() {\n if (this.tabBarContainer) {\n this.tabBarContainer.remove();\n this.tabBarContainer = null;\n this.tabElements.clear();\n }\n }\n createTabBar() {\n const container = document.createElement('div');\n container.id = 'capacitor-native-tabbar-web';\n Object.assign(container.style, {\n position: 'fixed',\n bottom: '0',\n left: '0',\n right: '0',\n height: '56px',\n display: 'flex',\n backgroundColor: '#ffffff',\n borderTop: '1px solid #e0e0e0',\n boxShadow: '0 -2px 10px rgba(0,0,0,0.1)',\n zIndex: '9999',\n });\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const tabEl = document.createElement('button');\n tabEl.dataset.tabId = tab.id;\n tabEl.type = 'button';\n Object.assign(tabEl.style, {\n flex: '1',\n display: 'flex',\n flexDirection: 'column',\n alignItems: 'center',\n justifyContent: 'center',\n gap: '4px',\n border: 'none',\n background: 'transparent',\n cursor: 'pointer',\n padding: '8px 4px',\n });\n const iconEl = document.createElement('img');\n iconEl.style.width = '24px';\n iconEl.style.height = '24px';\n iconEl.style.objectFit = 'contain';\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n iconEl.src = iconData ? this.base64ToDataUrl(iconData) : 'data:image/svg+xml,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"24\" height=\"24\" viewBox=\"0 0 24 24\" fill=\"currentColor\"><circle cx=\"12\" cy=\"12\" r=\"8\"/></svg>';\n const labelEl = document.createElement('span');\n labelEl.textContent = tab.label;\n Object.assign(labelEl.style, {\n fontSize: '10px',\n color: isActive ? this.labelColorActive : this.labelColor,\n });\n tabEl.appendChild(iconEl);\n tabEl.appendChild(labelEl);\n tabEl.addEventListener('click', () => {\n this.handleTabClick(tab.id);\n });\n container.appendChild(tabEl);\n this.tabElements.set(tab.id, { iconEl, labelEl });\n });\n document.body.appendChild(container);\n this.tabBarContainer = container;\n }\n handleTabClick(tabId) {\n const tab = this.tabItems.find((t) => t.id === tabId);\n if (!tab || this.selectedId === tabId)\n return;\n this.selectedId = tabId;\n this.updateTabBarSelection();\n this.emitTabChange({ tabId });\n }\n emitTabChange(event) {\n this.tabChangeListeners.forEach((fn) => fn(event));\n }\n updateTabBarSelection() {\n this.tabItems.forEach((tab) => {\n var _a, _b;\n const entry = this.tabElements.get(tab.id);\n if (entry) {\n const isActive = tab.id === this.selectedId;\n const iconData = isActive ? ((_a = tab.base64_active_icon) !== null && _a !== void 0 ? _a : tab.base64_icon) : ((_b = tab.base64_icon) !== null && _b !== void 0 ? _b : tab.base64_active_icon);\n if (iconData)\n entry.iconEl.src = this.base64ToDataUrl(iconData);\n entry.labelEl.style.color = isActive ? this.labelColorActive : this.labelColor;\n }\n });\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,SAAS,GAAGA,mBAAc,CAAC,WAAW,EAAE;IAC9C,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CA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AC5B,oBAAoB,KAAK,CAAC,MAAM,CAAC,GAAG,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC;IACrE,gBAAgB,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAC,gBAAgB,GAAG,IAAI,CAAC,UAAU;IAC9F,YAAY;IACZ,QAAQ,CAAC,CAAC;IACV,IAAI;IACJ;;;;;;;;;;;;;;;"}
|
|
@@ -70,7 +70,7 @@ import WebKit
|
|
|
70
70
|
return UIColor(red: r, green: g, blue: b, alpha: a)
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
func
|
|
73
|
+
func initialize(parent: UIView, tabs: [TabItemData], selectedId: String, labelColor: String? = nil, labelColorActive: String? = nil) {
|
|
74
74
|
self.parentView = parent
|
|
75
75
|
self.tabItems = tabs
|
|
76
76
|
self.selectedId = selectedId
|
|
@@ -117,14 +117,27 @@ import WebKit
|
|
|
117
117
|
|
|
118
118
|
captureBaseInsetsIfNeeded(from: parent)
|
|
119
119
|
applyWebViewInsets(to: parent)
|
|
120
|
+
tabBar.isHidden = false
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
func
|
|
123
|
+
func destroy() {
|
|
123
124
|
guard let parent = parentView else { return removeTabBar() }
|
|
124
125
|
removeWebViewInsets(from: parent)
|
|
125
126
|
removeTabBar()
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
func show() {
|
|
130
|
+
guard let parent = parentView, let tabBar = tabBar else { return }
|
|
131
|
+
tabBar.isHidden = false
|
|
132
|
+
applyWebViewInsets(to: parent)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
func hide() {
|
|
136
|
+
guard let parent = parentView, let tabBar = tabBar else { return }
|
|
137
|
+
tabBar.isHidden = true
|
|
138
|
+
removeWebViewInsets(from: parent)
|
|
139
|
+
}
|
|
140
|
+
|
|
128
141
|
func setSelectedTab(tabId: String) {
|
|
129
142
|
guard let index = tabItems.firstIndex(where: { $0.id == tabId }) else { return }
|
|
130
143
|
guard selectedId != tabId else { return }
|
|
@@ -133,9 +146,10 @@ import WebKit
|
|
|
133
146
|
updateItemImages()
|
|
134
147
|
}
|
|
135
148
|
|
|
136
|
-
func getState() -> (visible: Bool, activeTabId: String) {
|
|
137
|
-
let
|
|
138
|
-
|
|
149
|
+
func getState() -> (initialized: Bool, visible: Bool, activeTabId: String) {
|
|
150
|
+
let initialized = tabBar != nil
|
|
151
|
+
let visible = initialized && (tabBar?.isHidden == false)
|
|
152
|
+
return (initialized, visible, initialized ? selectedId : "")
|
|
139
153
|
}
|
|
140
154
|
|
|
141
155
|
private func imageFromBundle(_ name: String) -> UIImage? {
|
|
@@ -7,6 +7,8 @@ public class CapTabbarPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
7
7
|
public let identifier = "CapTabbarPlugin"
|
|
8
8
|
public let jsName = "CapTabbar"
|
|
9
9
|
public let pluginMethods: [CAPPluginMethod] = [
|
|
10
|
+
CAPPluginMethod(name: "init", returnType: CAPPluginReturnPromise),
|
|
11
|
+
CAPPluginMethod(name: "destroy", returnType: CAPPluginReturnPromise),
|
|
10
12
|
CAPPluginMethod(name: "show", returnType: CAPPluginReturnPromise),
|
|
11
13
|
CAPPluginMethod(name: "hide", returnType: CAPPluginReturnPromise),
|
|
12
14
|
CAPPluginMethod(name: "setSelectedTab", returnType: CAPPluginReturnPromise),
|
|
@@ -20,7 +22,7 @@ public class CapTabbarPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
20
22
|
}
|
|
21
23
|
}
|
|
22
24
|
|
|
23
|
-
@objc func
|
|
25
|
+
@objc func `init`(_ call: CAPPluginCall) {
|
|
24
26
|
guard let tabsArray = call.getArray("tabs"),
|
|
25
27
|
let selectedId = call.getString("selectedId") else {
|
|
26
28
|
call.reject("tabs and selectedId are required")
|
|
@@ -42,7 +44,21 @@ public class CapTabbarPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
42
44
|
call.reject("Could not find view to attach tab bar")
|
|
43
45
|
return
|
|
44
46
|
}
|
|
45
|
-
self.implementation.
|
|
47
|
+
self.implementation.initialize(parent: view, tabs: tabs, selectedId: selectedId, labelColor: labelColor, labelColorActive: labelColorActive)
|
|
48
|
+
call.resolve()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@objc func destroy(_ call: CAPPluginCall) {
|
|
53
|
+
DispatchQueue.main.async { [weak self] in
|
|
54
|
+
self?.implementation.destroy()
|
|
55
|
+
call.resolve()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@objc func show(_ call: CAPPluginCall) {
|
|
60
|
+
DispatchQueue.main.async { [weak self] in
|
|
61
|
+
self?.implementation.show()
|
|
46
62
|
call.resolve()
|
|
47
63
|
}
|
|
48
64
|
}
|
|
@@ -68,6 +84,7 @@ public class CapTabbarPlugin: CAPPlugin, CAPBridgedPlugin {
|
|
|
68
84
|
@objc func getState(_ call: CAPPluginCall) {
|
|
69
85
|
let state = implementation.getState()
|
|
70
86
|
call.resolve([
|
|
87
|
+
"initialized": state.initialized,
|
|
71
88
|
"visible": state.visible,
|
|
72
89
|
"activeTabId": state.activeTabId
|
|
73
90
|
])
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "capacitor-native-tabbar",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Native tab bar for Capacitor apps — UITabBar on iOS, BottomNavigationView on Android, overlays the WebView",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|