react-native-fxview 1.0.0 → 1.0.2-beta1

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.
@@ -0,0 +1,352 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FXViewManager = void 0;
4
+ const FXViewController_1 = require("./FXViewController");
5
+ const PriorityQueue_1 = require("./queue/PriorityQueue");
6
+ class FXViewManager {
7
+ constructor() {
8
+ // 存储视图控制器
9
+ this.viewControllerMap = new Map();
10
+ this.fxViewIdQueue = new PriorityQueue_1.PriorityQueue(PriorityQueue_1.HeapType.MAX_HEAP, PriorityQueue_1.PriorityOrder.LIFO);
11
+ this.viewLifecycleCallbacks = [];
12
+ //#endregion
13
+ }
14
+ static getInstance() {
15
+ if (!FXViewManager.instance) {
16
+ FXViewManager.instance = new FXViewManager();
17
+ }
18
+ return FXViewManager.instance;
19
+ }
20
+ //#region ========== 主要 API 方法 ==========
21
+ /**
22
+ * 创建并显示组件
23
+ * @param component 组件内容
24
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
25
+ * @param categoryId 分类 ID(可选,默认 "default")
26
+ * @param componentId 组件 ID(可选,自动生成)
27
+ * @returns 组件控制器
28
+ */
29
+ add(component, fxViewId, categoryId, componentId) {
30
+ console.log("FXViewManager.add", {
31
+ fxViewId,
32
+ categoryId,
33
+ componentId,
34
+ });
35
+ const viewController = this.getViewControllerOrCreate(fxViewId);
36
+ return viewController.add(component, categoryId, componentId);
37
+ }
38
+ /**
39
+ * 创建但不显示组件
40
+ * @param component 组件内容
41
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
42
+ * @param categoryId 分类 ID(可选,默认 "default")
43
+ * @param componentId 组件 ID(可选,自动生成)
44
+ * @returns 组件控制器
45
+ */
46
+ build(component, fxViewId, categoryId, componentId) {
47
+ console.log("FXViewManager.build", {
48
+ fxViewId,
49
+ categoryId,
50
+ componentId,
51
+ });
52
+ const viewController = this.getViewControllerOrCreate(fxViewId);
53
+ return viewController.build(component, categoryId, componentId);
54
+ }
55
+ /**
56
+ * 显示已存在的组件
57
+ * @param componentId 组件 ID
58
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
59
+ * @param categoryId 分类 ID(可选,默认 "default")
60
+ */
61
+ show(componentId, fxViewId, categoryId) {
62
+ console.log("FXViewManager.show", {
63
+ fxViewId,
64
+ categoryId,
65
+ componentId,
66
+ });
67
+ const viewController = this.getViewController(fxViewId);
68
+ if (!viewController) {
69
+ console.warn(`FXView ${fxViewId || "latest"} not found`);
70
+ return;
71
+ }
72
+ viewController.show(componentId, categoryId);
73
+ }
74
+ /**
75
+ * 隐藏但不删除组件
76
+ * @param componentId 组件 ID
77
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
78
+ * @param categoryId 分类 ID(可选,默认 "default")
79
+ */
80
+ hide(componentId, fxViewId, categoryId) {
81
+ console.log("FXViewManager.hide", {
82
+ fxViewId,
83
+ categoryId,
84
+ componentId,
85
+ });
86
+ const viewController = this.getViewController(fxViewId);
87
+ if (!viewController) {
88
+ console.warn(`FXView ${fxViewId || "latest"} not found`);
89
+ return;
90
+ }
91
+ viewController.hide(componentId, categoryId);
92
+ }
93
+ /**
94
+ * 更新组件内容
95
+ * @param componentId 组件 ID
96
+ * @param component 新的组件内容
97
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
98
+ * @param categoryId 分类 ID(可选,默认 "default")
99
+ */
100
+ update(componentId, component, fxViewId, categoryId) {
101
+ console.log("FXViewManager.update", {
102
+ fxViewId,
103
+ categoryId,
104
+ componentId,
105
+ });
106
+ const viewController = this.getViewController(fxViewId);
107
+ if (!viewController) {
108
+ console.warn(`FXView ${fxViewId || "latest"} not found`);
109
+ return;
110
+ }
111
+ viewController.update(componentId, component, categoryId);
112
+ }
113
+ /**
114
+ * 彻底删除组件
115
+ * @param componentId 组件 ID
116
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
117
+ * @param categoryId 分类 ID(可选,默认 "default")
118
+ */
119
+ remove(componentId, fxViewId, categoryId) {
120
+ console.log("FXViewManager.remove", {
121
+ fxViewId,
122
+ categoryId,
123
+ componentId,
124
+ });
125
+ const viewController = this.getViewController(fxViewId);
126
+ if (!viewController) {
127
+ console.warn(`FXView ${fxViewId || "latest"} not found`);
128
+ return;
129
+ }
130
+ viewController.remove(componentId, categoryId);
131
+ }
132
+ /**
133
+ * 移除最后一个组件(向后兼容)
134
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
135
+ * @param categoryId 分类 ID(可选,默认 "default")
136
+ */
137
+ removeLast(fxViewId, categoryId) {
138
+ console.log("FXViewManager.removeLast", {
139
+ fxViewId,
140
+ categoryId,
141
+ });
142
+ const viewController = this.getViewController(fxViewId);
143
+ if (!viewController) {
144
+ console.warn(`FXView ${fxViewId || "latest"} not found`);
145
+ return;
146
+ }
147
+ viewController.removeLast(categoryId);
148
+ }
149
+ /**
150
+ * 清空指定视图的所有组件
151
+ * @param fxViewId 视图 ID(可选,清空所有视图)
152
+ */
153
+ clearAll(fxViewId) {
154
+ console.log("FXViewManager.clearAll", { fxViewId });
155
+ if (fxViewId) {
156
+ // 清空指定视图
157
+ const viewController = this.getViewController(fxViewId);
158
+ if (viewController) {
159
+ viewController.clearAll();
160
+ }
161
+ }
162
+ else {
163
+ // 清空所有视图
164
+ this.viewControllerMap.forEach((controller) => {
165
+ controller.clearAll();
166
+ });
167
+ }
168
+ }
169
+ /**
170
+ * 清空指定分类的所有组件
171
+ * @param categoryId 分类 ID
172
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
173
+ */
174
+ clearCategory(categoryId, fxViewId) {
175
+ console.log("FXViewManager.clearCategory", { fxViewId, categoryId });
176
+ const viewController = this.getViewController(fxViewId);
177
+ if (!viewController) {
178
+ console.warn(`FXView ${fxViewId || "latest"} not found`);
179
+ return;
180
+ }
181
+ viewController.clearCategory(categoryId);
182
+ }
183
+ //#endregion
184
+ //#region ========== 视图管理方法 ==========
185
+ /**
186
+ * 注册视图(FXView 挂载时调用)
187
+ * @param fxViewId 视图 ID
188
+ * @param updateCallback 更新回调函数
189
+ * @returns 视图控制器
190
+ */
191
+ registerView(fxViewId, updateCallback) {
192
+ console.log("FXViewManager.registerView", fxViewId);
193
+ let viewController = this.viewControllerMap.get(fxViewId);
194
+ if (!viewController) {
195
+ viewController = new FXViewController_1.FXViewController(fxViewId);
196
+ this.viewControllerMap.set(fxViewId, viewController);
197
+ }
198
+ // 注册更新回调
199
+ viewController.registerUpdateCallback(updateCallback);
200
+ this.fxViewIdQueue.remove(fxViewId);
201
+ this.fxViewIdQueue.enqueue(fxViewId);
202
+ this.viewLifecycleCallbacks.forEach((callback) => {
203
+ var _a;
204
+ (_a = callback.didMount) === null || _a === void 0 ? void 0 : _a.call(callback, fxViewId);
205
+ });
206
+ return viewController;
207
+ }
208
+ /**
209
+ * 注销视图(FXView 卸载时调用)
210
+ * @param fxViewId 视图 ID
211
+ * @returns 是否成功注销
212
+ */
213
+ unregisterView(fxViewId) {
214
+ console.log("FXViewManager.unregisterView", fxViewId);
215
+ const viewController = this.getViewController(fxViewId);
216
+ if (!viewController) {
217
+ console.warn(`FXView ${fxViewId} not found, cannot unregister`);
218
+ return false;
219
+ }
220
+ // 清空回调
221
+ viewController.registerUpdateCallback(undefined);
222
+ // 清空所有组件
223
+ viewController.clearAll();
224
+ // 从队列中移除
225
+ this.fxViewIdQueue.remove(fxViewId);
226
+ // 从 Map 中删除
227
+ this.viewControllerMap.delete(fxViewId);
228
+ this.viewLifecycleCallbacks.forEach((callback) => {
229
+ var _a;
230
+ (_a = callback.willUnmount) === null || _a === void 0 ? void 0 : _a.call(callback, fxViewId);
231
+ });
232
+ return true;
233
+ }
234
+ registerLifecycleCallbacks(callbacks) {
235
+ console.log("FXViewManager.registerLifecycleCallbacks");
236
+ this.viewLifecycleCallbacks.push(callbacks);
237
+ }
238
+ unregisterLifecycleCallbacks(callbacks) {
239
+ console.log("FXViewManager.unregisterLifecycleCallbacks");
240
+ this.viewLifecycleCallbacks = this.viewLifecycleCallbacks.filter((callback) => callback !== callbacks);
241
+ }
242
+ /**
243
+ * 获取最近使用的视图 ID(栈顶)
244
+ * @returns 最近的视图 ID 或 null
245
+ */
246
+ getLatestFXViewId() {
247
+ return this.fxViewIdQueue.peek() || null;
248
+ }
249
+ /**
250
+ * 获取组件列表
251
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
252
+ * @param categoryId 分类 ID(可选)
253
+ * @returns 组件列表
254
+ */
255
+ getComponents(fxViewId, categoryId) {
256
+ console.log("FXViewManager.getComponents", { fxViewId, categoryId });
257
+ const finalFXViewId = fxViewId || this.getLatestFXViewId();
258
+ if (!finalFXViewId) {
259
+ console.warn("No FXView available");
260
+ return [];
261
+ }
262
+ const viewController = this.getViewController(finalFXViewId);
263
+ if (!viewController) {
264
+ console.warn(`FXViewController ${finalFXViewId} not found`);
265
+ return [];
266
+ }
267
+ return viewController.getComponents(categoryId);
268
+ }
269
+ /**
270
+ * 获取组件数量
271
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
272
+ * @returns 组件数量
273
+ */
274
+ getComponentCount(fxViewId) {
275
+ var _a;
276
+ const viewController = this.getViewController(fxViewId);
277
+ return (_a = viewController === null || viewController === void 0 ? void 0 : viewController.getComponentCount()) !== null && _a !== void 0 ? _a : 0;
278
+ }
279
+ /**
280
+ * 获取可见组件数量
281
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
282
+ * @returns 可见组件数量
283
+ */
284
+ getVisibleComponentCount(fxViewId) {
285
+ var _a;
286
+ const viewController = this.getViewController(fxViewId);
287
+ return (_a = viewController === null || viewController === void 0 ? void 0 : viewController.getVisibleComponentCount()) !== null && _a !== void 0 ? _a : 0;
288
+ }
289
+ /**
290
+ * 检查组件是否存在
291
+ * @param componentId 组件 ID
292
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
293
+ * @param categoryId 分类 ID(可选)
294
+ * @returns 是否存在
295
+ */
296
+ hasComponent(componentId, fxViewId, categoryId) {
297
+ var _a;
298
+ const viewController = this.getViewController(fxViewId);
299
+ return (_a = viewController === null || viewController === void 0 ? void 0 : viewController.hasComponent(componentId, categoryId)) !== null && _a !== void 0 ? _a : false;
300
+ }
301
+ /**
302
+ * 检查组件是否可见
303
+ * @param componentId 组件 ID
304
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
305
+ * @param categoryId 分类 ID(可选)
306
+ * @returns 是否可见
307
+ */
308
+ isComponentVisible(componentId, fxViewId, categoryId) {
309
+ var _a;
310
+ const viewController = this.getViewController(fxViewId);
311
+ return (_a = viewController === null || viewController === void 0 ? void 0 : viewController.isComponentVisible(componentId, categoryId)) !== null && _a !== void 0 ? _a : false;
312
+ }
313
+ //#endregion
314
+ //#region ========== 私有方法 ==========
315
+ /**
316
+ * 获取视图控制器
317
+ * @param fxViewId 视图 ID(可选,使用最近的视图)
318
+ * @returns 视图控制器或 null
319
+ */
320
+ getViewController(fxViewId) {
321
+ const finalFXViewId = fxViewId || this.getLatestFXViewId();
322
+ if (!finalFXViewId) {
323
+ console.warn("FXViewManager.getViewController: no fxViewId available");
324
+ return null;
325
+ }
326
+ return this.viewControllerMap.get(finalFXViewId) || null;
327
+ }
328
+ /**
329
+ * 获取或创建视图控制器
330
+ * @param fxViewId 视图 ID(可选,使用最近的视图或创建新的)
331
+ * @returns 视图控制器
332
+ */
333
+ getViewControllerOrCreate(fxViewId) {
334
+ const finalFXViewId = fxViewId || this.getLatestFXViewId() || this.autoFXViewId();
335
+ let viewController = this.viewControllerMap.get(finalFXViewId);
336
+ if (!viewController) {
337
+ console.warn(`FXViewController ${finalFXViewId} not registered, creating a temporary one`);
338
+ viewController = new FXViewController_1.FXViewController(finalFXViewId);
339
+ this.viewControllerMap.set(finalFXViewId, viewController);
340
+ this.fxViewIdQueue.enqueue(finalFXViewId);
341
+ }
342
+ return viewController;
343
+ }
344
+ /**
345
+ * 自动生成 fxViewId
346
+ * @returns 生成的 fxViewId
347
+ */
348
+ autoFXViewId() {
349
+ return `fxView_${Date.now()}_${Math.random().toString(36).substring(2, 9)}`;
350
+ }
351
+ }
352
+ exports.FXViewManager = FXViewManager;
package/FXViewManager.ts CHANGED
@@ -1,15 +1,22 @@
1
1
  import React from "react";
2
- import { ComponentController, ComponentItem } from "./types";
2
+ import {
3
+ FXComponentController,
4
+ FXComponentItem,
5
+ FXLifecycleCallbacks,
6
+ } from "./types";
3
7
  import { FXViewController } from "./FXViewController";
4
- import { HeapType, PriorityOrder, PriorityQueue } from "../queue/PriorityQueue";
8
+ import { HeapType, PriorityOrder, PriorityQueue } from "./queue/PriorityQueue";
5
9
 
6
10
  export class FXViewManager {
7
11
  private static instance: FXViewManager;
8
12
 
9
13
  // 存储视图控制器
10
14
  private viewControllerMap: Map<string, FXViewController> = new Map();
11
- private viewControllerQueue: PriorityQueue<FXViewController> =
12
- new PriorityQueue(HeapType.MAX_HEAP, PriorityOrder.LIFO);
15
+ private fxViewIdQueue: PriorityQueue<string> = new PriorityQueue(
16
+ HeapType.MAX_HEAP,
17
+ PriorityOrder.LIFO,
18
+ );
19
+ private viewLifecycleCallbacks: Array<FXLifecycleCallbacks> = [];
13
20
 
14
21
  static getInstance(): FXViewManager {
15
22
  if (!FXViewManager.instance) {
@@ -33,7 +40,7 @@ export class FXViewManager {
33
40
  fxViewId?: string,
34
41
  categoryId?: string,
35
42
  componentId?: string,
36
- ): ComponentController {
43
+ ): FXComponentController {
37
44
  console.log("FXViewManager.add", {
38
45
  fxViewId,
39
46
  categoryId,
@@ -57,7 +64,7 @@ export class FXViewManager {
57
64
  fxViewId?: string,
58
65
  categoryId?: string,
59
66
  componentId?: string,
60
- ): ComponentController {
67
+ ): FXComponentController {
61
68
  console.log("FXViewManager.build", {
62
69
  fxViewId,
63
70
  categoryId,
@@ -242,16 +249,11 @@ export class FXViewManager {
242
249
 
243
250
  // 注册更新回调
244
251
  viewController.registerUpdateCallback(updateCallback);
245
-
246
- // 更新视图栈(移除旧的引用,添加新的)
247
- const existingController = this.viewControllerQueue
248
- .getAll()
249
- .find((vc) => vc.fxViewId === fxViewId);
250
- if (existingController) {
251
- this.viewControllerQueue.remove(existingController);
252
- }
253
- this.viewControllerQueue.enqueue(viewController);
254
-
252
+ this.fxViewIdQueue.remove(fxViewId);
253
+ this.fxViewIdQueue.enqueue(fxViewId);
254
+ this.viewLifecycleCallbacks.forEach((callback) => {
255
+ callback.didMount?.(fxViewId);
256
+ });
255
257
  return viewController;
256
258
  }
257
259
 
@@ -276,20 +278,36 @@ export class FXViewManager {
276
278
  viewController.clearAll();
277
279
 
278
280
  // 从队列中移除
279
- this.viewControllerQueue.remove(viewController);
281
+ this.fxViewIdQueue.remove(fxViewId);
280
282
 
281
283
  // 从 Map 中删除
282
284
  this.viewControllerMap.delete(fxViewId);
283
285
 
286
+ this.viewLifecycleCallbacks.forEach((callback) => {
287
+ callback.willUnmount?.(fxViewId);
288
+ });
289
+
284
290
  return true;
285
291
  }
286
292
 
293
+ registerLifecycleCallbacks(callbacks: FXLifecycleCallbacks): void {
294
+ console.log("FXViewManager.registerLifecycleCallbacks");
295
+ this.viewLifecycleCallbacks.push(callbacks);
296
+ }
297
+
298
+ unregisterLifecycleCallbacks(callbacks: FXLifecycleCallbacks): void {
299
+ console.log("FXViewManager.unregisterLifecycleCallbacks");
300
+ this.viewLifecycleCallbacks = this.viewLifecycleCallbacks.filter(
301
+ (callback) => callback !== callbacks,
302
+ );
303
+ }
304
+
287
305
  /**
288
306
  * 获取最近使用的视图 ID(栈顶)
289
307
  * @returns 最近的视图 ID 或 null
290
308
  */
291
309
  getLatestFXViewId(): string | null {
292
- return this.viewControllerQueue.peek()?.fxViewId || null;
310
+ return this.fxViewIdQueue.peek() || null;
293
311
  }
294
312
 
295
313
  /**
@@ -298,7 +316,7 @@ export class FXViewManager {
298
316
  * @param categoryId 分类 ID(可选)
299
317
  * @returns 组件列表
300
318
  */
301
- getComponents(fxViewId?: string, categoryId?: string): ComponentItem[] {
319
+ getComponents(fxViewId?: string, categoryId?: string): FXComponentItem[] {
302
320
  console.log("FXViewManager.getComponents", { fxViewId, categoryId });
303
321
 
304
322
  const finalFXViewId = fxViewId || this.getLatestFXViewId();
@@ -403,7 +421,7 @@ export class FXViewManager {
403
421
  );
404
422
  viewController = new FXViewController(finalFXViewId);
405
423
  this.viewControllerMap.set(finalFXViewId, viewController);
406
- this.viewControllerQueue.enqueue(viewController);
424
+ this.fxViewIdQueue.enqueue(finalFXViewId);
407
425
  }
408
426
 
409
427
  return viewController;
package/README.md ADDED
@@ -0,0 +1,209 @@
1
+ # React Native FXView
2
+
3
+ 一个革命性的React Native动态UI预埋框架,支持在任何位置预埋容器,然后通过全局管理器在运行时动态注入和控制React组件。
4
+
5
+ ## 🎯 核心概念
6
+
7
+ FXView采用**预埋+注入**的设计模式:
8
+
9
+ 1. **预埋容器**:在应用的任何位置预埋`FXView`容器
10
+ 2. **动态注入**:通过`FXViewManager`在任何时间、任何位置动态注入React组件
11
+ 3. **全局控制**:支持跨组件、跨页面的全局UI管理和状态控制
12
+
13
+ ## ✨ 功能特性
14
+
15
+ - 🎯 **动态组件注入** - 运行时在任何预埋位置注入React组件
16
+ - 🔄 **实时UI更新** - 支持组件内容的实时更新和状态管理
17
+ - 📂 **智能分类管理** - 按分类组织和管理动态组件
18
+ - 👁️ **显示/隐藏控制** - 灵活控制组件的显示状态
19
+ - 🌍 **全局访问** - 从应用的任何地方访问和管理UI
20
+ - 🚀 **轻量级高性能** - 优化的渲染性能和内存管理
21
+
22
+ ## 📦 安装
23
+
24
+ ```bash
25
+ npm install react-native-fxview
26
+ # 或者
27
+ yarn add react-native-fxview
28
+ ```
29
+
30
+ ## 🚀 快速开始
31
+
32
+ ### 1. 预埋FXView容器
33
+
34
+ 在任何需要动态注入UI的位置预埋FXView:
35
+
36
+ ```javascript
37
+ import React from 'react';
38
+ import { View, Text } from 'react-native';
39
+ import { FXView } from 'react-native-fxview';
40
+
41
+ export default function App() {
42
+ return (
43
+ <View style={{ flex: 1 }}>
44
+ <Text>静态内容</Text>
45
+
46
+ {/* 预埋动态UI容器 */}
47
+ <FXView fxViewId="headerArea" style={{ height: 60 }} />
48
+
49
+ <Text>更多静态内容</Text>
50
+
51
+ {/* 在底部预埋另一个容器 */}
52
+ <FXView fxViewId="bottomSheet" style={{ position: 'absolute', bottom: 0 }} />
53
+ </View>
54
+ );
55
+ }
56
+ ```
57
+
58
+ ### 2. 动态注入组件
59
+
60
+ 从应用的任何地方(甚至不同的页面或组件)动态注入UI:
61
+
62
+ ```javascript
63
+ import { FXViewManager } from 'react-native-fxview';
64
+ import { Button, View, Text } from 'react-native';
65
+
66
+ // 在headerArea注入一个搜索栏
67
+ const searchBarController = FXViewManager.getInstance().add(
68
+ <View style={{ backgroundColor: '#f0f0f0', padding: 10 }}>
69
+ <Text>搜索栏组件</Text>
70
+ </View>,
71
+ 'headerArea', // fxViewId
72
+ 'navigation' // categoryId
73
+ );
74
+
75
+ // 在bottomSheet注入一个弹窗
76
+ const sheetController = FXViewManager.getInstance().add(
77
+ <View style={{ backgroundColor: 'white', padding: 20, borderRadius: 10 }}>
78
+ <Text>底部弹窗内容</Text>
79
+ <Button title="关闭" onPress={() => sheetController.hide()} />
80
+ </View>,
81
+ 'bottomSheet',
82
+ 'modals'
83
+ );
84
+ ```
85
+
86
+ ### 3. 运行时控制
87
+
88
+ ```javascript
89
+ // 隐藏搜索栏
90
+ searchBarController.hide();
91
+
92
+ // 更新搜索栏内容
93
+ searchBarController.update(
94
+ <View style={{ backgroundColor: 'blue', padding: 10 }}>
95
+ <Text style={{ color: 'white' }}>更新后的搜索栏</Text>
96
+ </View>
97
+ );
98
+
99
+ // 显示搜索栏
100
+ searchBarController.show();
101
+
102
+ // 完全移除组件
103
+ searchBarController.remove();
104
+ ```
105
+
106
+ ## 📖 API 参考
107
+
108
+ ### FXView Props
109
+
110
+ - `fxViewId` (string, optional): 容器唯一标识符,用于后续注入组件时的定位
111
+
112
+ ### FXViewManager 主要方法
113
+
114
+ #### 组件管理
115
+ - `add(component, fxViewId?, category?, componentId?)` - 创建并显示组件
116
+ - `build(component, fxViewId?, category?, componentId?)` - 创建但不显示组件
117
+ - `show(componentId, fxViewId?, category?)` - 显示已存在的组件
118
+ - `hide(componentId, fxViewId?, category?)` - 隐藏组件
119
+ - `update(componentId, newComponent, fxViewId?, category?)` - 更新组件内容
120
+ - `remove(componentId, fxViewId?, category?)` - 移除组件
121
+
122
+ #### 批量操作
123
+ - `clearAll(fxViewId?)` - 清空指定或所有容器
124
+ - `clearCategory(categoryId, fxViewId?)` - 清空指定分类
125
+
126
+ #### 查询方法
127
+ - `getComponents(fxViewId?, category?)` - 获取组件列表
128
+ - `hasComponent(componentId, fxViewId?, category?)` - 检查组件是否存在
129
+ - `isComponentVisible(componentId, fxViewId?, category?)` - 检查组件是否可见
130
+
131
+ ### 组件控制器 (FXComponentController)
132
+
133
+ - `show()` - 显示组件
134
+ - `hide()` - 隐藏组件
135
+ - `remove()` - 移除组件
136
+ - `update(newComponent)` - 更新组件内容
137
+ - `isVisible()` - 获取可见状态
138
+ - `exists()` - 检查组件是否存在
139
+
140
+ ## 💡 使用场景
141
+
142
+ ### 1. 动态导航栏
143
+ 在不同页面根据状态动态改变顶部导航栏内容
144
+
145
+ ### 2. 全局弹窗系统
146
+ 从任何地方触发全局弹窗、通知、确认框等
147
+
148
+ ### 3. 动态表单
149
+ 根据用户操作动态添加、移除、更新表单字段
150
+
151
+ ### 4. 插件化UI
152
+ 支持第三方插件动态注入UI组件到主应用
153
+
154
+ ### 5. A/B测试
155
+ 动态切换不同的UI组件进行A/B测试
156
+
157
+ ## 🎯 最佳实践
158
+
159
+ ### 分类管理
160
+ 使用分类来组织不同类型的动态组件:
161
+
162
+ ```javascript
163
+ // 导航相关
164
+ FXViewManager.getInstance().add(navComponent, 'header', 'navigation');
165
+
166
+ // 弹窗相关
167
+ FXViewManager.getInstance().add(modalComponent, 'overlay', 'modals');
168
+
169
+ // 通知相关
170
+ FXViewManager.getInstance().add(toastComponent, 'notification', 'notifications');
171
+ ```
172
+
173
+ ### 生命周期管理
174
+ ```javascript
175
+ // 创建时
176
+ const controller = FXViewManager.getInstance().build(component, 'container');
177
+
178
+ // 需要时显示
179
+ controller.show();
180
+
181
+ // 不需要时隐藏
182
+ controller.hide();
183
+
184
+ // 完全清理
185
+ controller.remove();
186
+ ```
187
+
188
+ ## 🔧 高级用法
189
+
190
+ ### 生命周期回调
191
+ ```javascript
192
+ FXViewManager.getInstance().registerLifecycleCallbacks({
193
+ didMount: (fxViewId) => console.log('FXView挂载:', fxViewId),
194
+ willUnmount: (fxViewId) => console.log('FXView卸载:', fxViewId)
195
+ });
196
+ ```
197
+
198
+ ### 组件查询和批量操作
199
+ ```javascript
200
+ // 获取所有导航组件
201
+ const navComponents = FXViewManager.getInstance().getComponents(null, 'navigation');
202
+
203
+ // 清空所有弹窗
204
+ FXViewManager.getInstance().clearCategory('modals');
205
+ ```
206
+
207
+ ## 📄 许可证
208
+
209
+ MIT
package/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { default as FXView } from "./FXView";
2
+ export { FXViewManager } from "./FXViewManager";
3
+ export { FXViewController } from "./FXViewController";
4
+ export { FXCategoryController } from "./FXCategoryController";
5
+ export * from "./types";