react-native-fxview 1.0.1 → 1.0.2-beta12

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 CHANGED
@@ -1,16 +1,25 @@
1
1
  # React Native FXView
2
2
 
3
- 一个用于React Native的动态视图组件,支持运行时UI更新和组件管理。
3
+ 一个革命性的React Native动态UI预埋框架,支持在任何位置预埋容器,然后通过全局管理器在运行时动态注入和控制React组件。
4
4
 
5
- ## 功能特性
5
+ ## 🎯 核心概念
6
6
 
7
- - 🎯 动态组件管理
8
- - 🔄 运行时UI更新
9
- - 📂 组件分类管理
10
- - 👁️ 组件显示/隐藏控制
11
- - 🚀 轻量级和高性能
7
+ FXView采用**预埋+注入**的设计模式:
12
8
 
13
- ## 安装
9
+ 1. **预埋容器**:在应用的任何位置预埋`FXView`容器
10
+ 2. **动态注入**:通过`FXViewManager`在任何时间、任何位置动态注入React组件
11
+ 3. **全局控制**:支持跨组件、跨页面的全局UI管理和状态控制
12
+
13
+ ## ✨ 功能特性
14
+
15
+ - 🎯 **动态组件注入** - 运行时在任何预埋位置注入React组件
16
+ - 🔄 **实时UI更新** - 支持组件内容的实时更新和状态管理
17
+ - 📂 **智能分类管理** - 按分类组织和管理动态组件
18
+ - 👁️ **显示/隐藏控制** - 灵活控制组件的显示状态
19
+ - 🌍 **全局访问** - 从应用的任何地方访问和管理UI
20
+ - 🚀 **轻量级高性能** - 优化的渲染性能和内存管理
21
+
22
+ ## 📦 安装
14
23
 
15
24
  ```bash
16
25
  npm install react-native-fxview
@@ -18,44 +27,183 @@ npm install react-native-fxview
18
27
  yarn add react-native-fxview
19
28
  ```
20
29
 
21
- ## 快速开始
30
+ ## 🚀 快速开始
31
+
32
+ ### 1. 预埋FXView容器
33
+
34
+ 在任何需要动态注入UI的位置预埋FXView:
22
35
 
23
36
  ```javascript
24
37
  import React from 'react';
25
- import { Text } from 'react-native';
38
+ import { View, Text } from 'react-native';
26
39
  import { FXView } from 'react-native-fxview';
27
40
 
28
41
  export default function App() {
29
42
  return (
30
- <FXView fxViewId="myView">
31
- <Text>Hello World</Text>
32
- </FXView>
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>
33
54
  );
34
55
  }
35
56
  ```
36
57
 
37
- ## API 文档
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 参考
38
107
 
39
108
  ### FXView Props
40
109
 
41
- - `fxViewId` (string, optional): 视图唯一标识符,如果不提供则自动生成
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?)` - 检查组件是否可见
42
130
 
43
- ### FXViewManager
131
+ ### 组件控制器 (FXComponentController)
44
132
 
45
- 用于管理所有FXView实例的全局管理器。
133
+ - `show()` - 显示组件
134
+ - `hide()` - 隐藏组件
135
+ - `remove()` - 移除组件
136
+ - `update(newComponent)` - 更新组件内容
137
+ - `isVisible()` - 获取可见状态
138
+ - `exists()` - 检查组件是否存在
46
139
 
47
- ### FXViewController
140
+ ## 💡 使用场景
48
141
 
49
- 用于控制单个组件的控制器。
142
+ ### 1. 动态导航栏
143
+ 在不同页面根据状态动态改变顶部导航栏内容
50
144
 
51
- ### FXViewCategoryController
145
+ ### 2. 全局弹窗系统
146
+ 从任何地方触发全局弹窗、通知、确认框等
52
147
 
53
- 用于控制组件分类的控制器。
148
+ ### 3. 动态表单
149
+ 根据用户操作动态添加、移除、更新表单字段
54
150
 
55
- ## 示例
151
+ ### 4. 插件化UI
152
+ 支持第三方插件动态注入UI组件到主应用
56
153
 
57
- 查看项目中的示例代码了解更多用法。
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
+ ```
58
206
 
59
- ## 许可证
207
+ ## 📄 许可证
60
208
 
61
- MIT
209
+ MIT
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { default as FXView } from "./FXView";
2
2
  export { FXViewManager } from "./FXViewManager";
3
3
  export { FXViewController } from "./FXViewController";
4
- export { FXViewCategoryController } from "./FXViewCategoryController";
4
+ export { FXCategoryController } from "./FXCategoryController";
5
5
  export * from "./types";
package/index.js CHANGED
@@ -17,7 +17,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
17
17
  return (mod && mod.__esModule) ? mod : { "default": mod };
18
18
  };
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
- exports.FXViewCategoryController = exports.FXViewController = exports.FXViewManager = exports.FXView = void 0;
20
+ exports.FXCategoryController = exports.FXViewController = exports.FXViewManager = exports.FXView = void 0;
21
21
  // 主入口文件
22
22
  var FXView_1 = require("./FXView");
23
23
  Object.defineProperty(exports, "FXView", { enumerable: true, get: function () { return __importDefault(FXView_1).default; } });
@@ -25,6 +25,6 @@ var FXViewManager_1 = require("./FXViewManager");
25
25
  Object.defineProperty(exports, "FXViewManager", { enumerable: true, get: function () { return FXViewManager_1.FXViewManager; } });
26
26
  var FXViewController_1 = require("./FXViewController");
27
27
  Object.defineProperty(exports, "FXViewController", { enumerable: true, get: function () { return FXViewController_1.FXViewController; } });
28
- var FXViewCategoryController_1 = require("./FXViewCategoryController");
29
- Object.defineProperty(exports, "FXViewCategoryController", { enumerable: true, get: function () { return FXViewCategoryController_1.FXViewCategoryController; } });
28
+ var FXCategoryController_1 = require("./FXCategoryController");
29
+ Object.defineProperty(exports, "FXCategoryController", { enumerable: true, get: function () { return FXCategoryController_1.FXCategoryController; } });
30
30
  __exportStar(require("./types"), exports);
package/index.ts CHANGED
@@ -2,5 +2,5 @@
2
2
  export { default as FXView } from "./FXView";
3
3
  export { FXViewManager } from "./FXViewManager";
4
4
  export { FXViewController } from "./FXViewController";
5
- export { FXViewCategoryController } from "./FXViewCategoryController";
5
+ export { FXCategoryController } from "./FXCategoryController";
6
6
  export * from "./types";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-fxview",
3
- "version": "1.0.1",
3
+ "version": "1.0.2-beta12",
4
4
  "description": "A dynamic view component for React Native that allows runtime UI updates and component management",
5
5
  "main": "index.ts",
6
6
  "types": "index.d.ts",
@@ -8,6 +8,10 @@
8
8
  "*.js",
9
9
  "*.ts",
10
10
  "*.tsx",
11
+ "*.d.ts",
12
+ "queue/**/*.js",
13
+ "queue/**/*.ts",
14
+ "queue/**/*.d.ts",
11
15
  "README.md",
12
16
  "LICENSE"
13
17
  ],
@@ -0,0 +1,153 @@
1
+ /**
2
+ * 通用的优先级队列 - 支持泛型存储,可切换大顶堆/小顶堆模式
3
+ * 支持优先级相同时的排序策略:先入先出(FIFO)或后入先出(LIFO)
4
+ */
5
+ export declare enum HeapType {
6
+ MAX_HEAP = "max",// 大顶堆:优先级高的在前
7
+ MIN_HEAP = "min"
8
+ }
9
+ export declare enum PriorityOrder {
10
+ FIFO = "fifo",// 先入先出:优先级相同时,先入队的在前
11
+ LIFO = "lifo"
12
+ }
13
+ export declare class PriorityQueue<T> {
14
+ private items;
15
+ private heapType;
16
+ private priorityOrder;
17
+ constructor(heapType?: HeapType, priorityOrder?: PriorityOrder);
18
+ /**
19
+ * 设置堆类型(可选参数)
20
+ */
21
+ setHeapType(heapType?: HeapType): void;
22
+ /**
23
+ * 获取当前堆类型
24
+ */
25
+ getHeapType(): HeapType;
26
+ /**
27
+ * 设置优先级相同时的排序策略(可选参数)
28
+ */
29
+ setPriorityOrder(order?: PriorityOrder): void;
30
+ /**
31
+ * 获取当前优先级相同时的排序策略
32
+ */
33
+ getPriorityOrder(): PriorityOrder;
34
+ /**
35
+ * 入队 - 按当前堆类型和排序策略排序
36
+ */
37
+ enqueue(item: T, priority?: number, timestamp?: number): void;
38
+ /**
39
+ * 批量入队(可选参数)
40
+ */
41
+ enqueueMultiple(items: T[], priority?: number): void;
42
+ /**
43
+ * 出队 - 返回队首元素(最高或最低优先级)
44
+ */
45
+ dequeue(): T | null;
46
+ /**
47
+ * 批量出队(可选参数)
48
+ */
49
+ dequeueMultiple(count?: number): T[];
50
+ /**
51
+ * 查看队首元素(不移除)
52
+ */
53
+ peek(): T | null;
54
+ /**
55
+ * 查看队首元素的优先级
56
+ */
57
+ peekPriority(): number | null;
58
+ /**
59
+ * 查看前N个元素(可选参数)
60
+ */
61
+ peekMultiple(count?: number): T[];
62
+ /**
63
+ * 队列是否为空
64
+ */
65
+ isEmpty(): boolean;
66
+ /**
67
+ * 队列大小
68
+ */
69
+ size(): number;
70
+ /**
71
+ * 清空队列
72
+ */
73
+ clear(): void;
74
+ /**
75
+ * 获取所有元素(按当前堆类型排序)
76
+ */
77
+ getAll(): T[];
78
+ /**
79
+ * 获取所有元素及其优先级
80
+ */
81
+ getAllWithPriority(): Array<{
82
+ item: T;
83
+ priority: number;
84
+ }>;
85
+ /**
86
+ * 获取所有元素及其详细信息
87
+ */
88
+ getAllWithDetails(): Array<{
89
+ item: T;
90
+ priority: number;
91
+ timestamp: number;
92
+ }>;
93
+ /**
94
+ * 获取指定索引的元素(可选参数)
95
+ */
96
+ getAt(index?: number): T | null;
97
+ /**
98
+ * 获取指定范��的元素(可选参数)
99
+ */
100
+ getRange(start?: number, end?: number): T[];
101
+ /**
102
+ * 移除指定元素
103
+ */
104
+ remove(item: T): boolean;
105
+ /**
106
+ * 移除指定索引的元素(可选参数)
107
+ */
108
+ removeAt(index?: number): T | null;
109
+ /**
110
+ * 更新元素的优先级
111
+ */
112
+ updatePriority(item: T, newPriority?: number): boolean;
113
+ /**
114
+ * 查找指定元素
115
+ */
116
+ find(predicate: (item: T) => boolean): T | null;
117
+ /**
118
+ * 查找所有符合条件的元素
119
+ */
120
+ findAll(predicate: (item: T) => boolean): T[];
121
+ /**
122
+ * 过滤元素
123
+ */
124
+ filter(predicate: (item: T) => boolean): T[];
125
+ /**
126
+ * 遍历元素
127
+ */
128
+ forEach(callback: (item: T, priority: number, index: number) => void): void;
129
+ /**
130
+ * 映射元素
131
+ */
132
+ map<U>(callback: (item: T, priority: number, index: number) => U): U[];
133
+ /**
134
+ * 判断是否应该插入到指定元素之前
135
+ */
136
+ private shouldInsertBefore;
137
+ /**
138
+ * 重新排序所有元素
139
+ */
140
+ private resort;
141
+ /**
142
+ * 转换为数组
143
+ */
144
+ toArray(): T[];
145
+ /**
146
+ * 转换为JSON字符串
147
+ */
148
+ toJSON(): string;
149
+ /**
150
+ * 克隆队列
151
+ */
152
+ clone(): PriorityQueue<T>;
153
+ }