react-native-kookit 0.1.3 → 0.1.5
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_NEW.md +10 -0
- package/RELEASE_CHECKLIST.md +115 -0
- package/TROUBLESHOOTING.md +132 -0
- package/app.plugin.js +8 -1
- package/package.json +7 -7
package/README_NEW.md
CHANGED
|
@@ -112,6 +112,16 @@ export default function App() {
|
|
|
112
112
|
|
|
113
113
|
A: 插件需要修改原生 Android 代码,prebuild 会应用所有插件修改。
|
|
114
114
|
|
|
115
|
+
### Q: 遇到 "Plugin is an unexpected type: undefined" 错误怎么办?
|
|
116
|
+
|
|
117
|
+
A:
|
|
118
|
+
|
|
119
|
+
1. 确保已正确安装:`npm install react-native-kookit`
|
|
120
|
+
2. 清理重装:`rm -rf node_modules && npm install`
|
|
121
|
+
3. 重新预构建:`npx expo prebuild --clean`
|
|
122
|
+
|
|
123
|
+
详细故障排除请查看 [TROUBLESHOOTING.md](./TROUBLESHOOTING.md)
|
|
124
|
+
|
|
115
125
|
### Q: 音量键无响应怎么办?
|
|
116
126
|
|
|
117
127
|
A:
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# React Native Kookit - 发布前检查
|
|
2
|
+
|
|
3
|
+
## 修复的主要问题
|
|
4
|
+
|
|
5
|
+
✅ **Plugin undefined 错误**
|
|
6
|
+
|
|
7
|
+
- 修复了 package.json 中插件配置位置
|
|
8
|
+
- 添加了 @expo/config-plugins 依赖
|
|
9
|
+
- 改进了 app.plugin.js 的错误处理
|
|
10
|
+
|
|
11
|
+
✅ **插件导出问题**
|
|
12
|
+
|
|
13
|
+
- 确保插件正确导出为 ConfigPlugin 函数
|
|
14
|
+
- 添加了fallback处理
|
|
15
|
+
|
|
16
|
+
## 当前文件结构
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
react-native-kookit/
|
|
20
|
+
├── package.json # 主包配置,包含插件配置
|
|
21
|
+
├── app.plugin.js # 插件入口文件
|
|
22
|
+
├── plugin/ # 插件源码目录
|
|
23
|
+
│ ├── package.json # 插件依赖
|
|
24
|
+
│ ├── tsconfig.json # TypeScript 配置
|
|
25
|
+
│ ├── src/
|
|
26
|
+
│ │ └── withVolumeKeyIntercept.ts # 插件实现
|
|
27
|
+
│ └── build/ # 编译后的插件
|
|
28
|
+
│ └── withVolumeKeyIntercept.js
|
|
29
|
+
├── README_NEW.md # 更新的文档
|
|
30
|
+
├── TROUBLESHOOTING.md # 故障排除指南
|
|
31
|
+
└── EXPO_PLUGIN_README.md # 插件详细说明
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## 测试步骤
|
|
35
|
+
|
|
36
|
+
### 1. 本地测试插件加载
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
cd /path/to/react-native-kookit
|
|
40
|
+
node -e "
|
|
41
|
+
const plugin = require('./app.plugin.js');
|
|
42
|
+
console.log('Plugin type:', typeof plugin);
|
|
43
|
+
console.log('Plugin loaded:', typeof plugin === 'function' ? '✅ Success' : '❌ Failed');
|
|
44
|
+
"
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. 在测试项目中验证
|
|
48
|
+
|
|
49
|
+
1. 创建新的 Expo 项目:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npx create-expo-app TestKookit
|
|
53
|
+
cd TestKookit
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
2. 添加本地模块:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npm install ../react-native-kookit
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
3. 配置 app.json:
|
|
63
|
+
|
|
64
|
+
```json
|
|
65
|
+
{
|
|
66
|
+
"expo": {
|
|
67
|
+
"plugins": ["react-native-kookit"]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
4. 预构建:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
npx expo prebuild --clean
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
5. 检查生成的 MainActivity 是否包含必要代码
|
|
79
|
+
|
|
80
|
+
### 3. 发布验证
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
# 构建插件
|
|
84
|
+
npm run build-plugin
|
|
85
|
+
|
|
86
|
+
# 检查文件
|
|
87
|
+
ls -la plugin/build/
|
|
88
|
+
|
|
89
|
+
# 发布(测试版本)
|
|
90
|
+
npm publish --tag beta
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## 用户使用流程验证
|
|
94
|
+
|
|
95
|
+
### 正确的用户步骤:
|
|
96
|
+
|
|
97
|
+
1. ✅ `npm install react-native-kookit`
|
|
98
|
+
2. ✅ 在 app.json 添加 `"plugins": ["react-native-kookit"]`
|
|
99
|
+
3. ✅ `npx expo prebuild --clean`
|
|
100
|
+
4. ✅ `npx expo run:android`
|
|
101
|
+
|
|
102
|
+
### 预期结果:
|
|
103
|
+
|
|
104
|
+
- MainActivity 自动包含 VolumeKeyInterceptActivity 接口
|
|
105
|
+
- 音量键监听功能正常工作
|
|
106
|
+
- 无需手动修改原生代码
|
|
107
|
+
|
|
108
|
+
## 发布清单
|
|
109
|
+
|
|
110
|
+
- [ ] 插件本地测试通过
|
|
111
|
+
- [ ] 在新项目中端到端测试
|
|
112
|
+
- [ ] 文档更新完成
|
|
113
|
+
- [ ] 版本号更新
|
|
114
|
+
- [ ] README 更新为 README_NEW.md
|
|
115
|
+
- [ ] 发布到 npm
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# react-native-kookit 配置示例
|
|
2
|
+
|
|
3
|
+
## 正确的 app.json 配置
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{
|
|
7
|
+
"expo": {
|
|
8
|
+
"name": "Your App Name",
|
|
9
|
+
"slug": "your-app-slug",
|
|
10
|
+
"version": "1.0.0",
|
|
11
|
+
"orientation": "portrait",
|
|
12
|
+
"icon": "./assets/icon.png",
|
|
13
|
+
"userInterfaceStyle": "light",
|
|
14
|
+
"splash": {
|
|
15
|
+
"image": "./assets/splash.png",
|
|
16
|
+
"resizeMode": "contain",
|
|
17
|
+
"backgroundColor": "#ffffff"
|
|
18
|
+
},
|
|
19
|
+
"plugins": ["react-native-kookit"],
|
|
20
|
+
"android": {
|
|
21
|
+
"adaptiveIcon": {
|
|
22
|
+
"foregroundImage": "./assets/adaptive-icon.png",
|
|
23
|
+
"backgroundColor": "#ffffff"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"web": {
|
|
27
|
+
"favicon": "./assets/favicon.png"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## 故障排除
|
|
34
|
+
|
|
35
|
+
### 错误:Plugin is an unexpected type: undefined
|
|
36
|
+
|
|
37
|
+
**原因:** 插件未正确安装或构建
|
|
38
|
+
|
|
39
|
+
**解决方案:**
|
|
40
|
+
|
|
41
|
+
1. 确保 react-native-kookit 已正确安装:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install react-native-kookit
|
|
45
|
+
# 或
|
|
46
|
+
yarn add react-native-kookit
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
2. 清理并重新安装依赖:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
rm -rf node_modules package-lock.json
|
|
53
|
+
npm install
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
3. 重新预构建:
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
npx expo prebuild --clean
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### 其他常见错误
|
|
63
|
+
|
|
64
|
+
#### 错误:Cannot find module '@expo/config-plugins'
|
|
65
|
+
|
|
66
|
+
**解决方案:**
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm install @expo/config-plugins
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
#### 错误:Plugin configuration is invalid
|
|
73
|
+
|
|
74
|
+
检查 app.json 格式是否正确,确保 plugins 数组正确配置。
|
|
75
|
+
|
|
76
|
+
## 验证插件是否工作
|
|
77
|
+
|
|
78
|
+
运行以下命令检查插件是否正确加载:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
node -e "
|
|
82
|
+
const plugin = require('react-native-kookit/app.plugin.js');
|
|
83
|
+
console.log('Plugin loaded successfully:', typeof plugin === 'function');
|
|
84
|
+
"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
如果输出 `Plugin loaded successfully: true`,说明插件正确安装。
|
|
88
|
+
|
|
89
|
+
## 完整的使用流程
|
|
90
|
+
|
|
91
|
+
1. **安装模块**
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
npm install react-native-kookit
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
2. **配置 app.json**
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"expo": {
|
|
102
|
+
"plugins": ["react-native-kookit"]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
3. **预构建项目**
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npx expo prebuild --clean
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
4. **运行项目**
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
npx expo run:android
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
5. **在代码中使用**
|
|
120
|
+
|
|
121
|
+
```javascript
|
|
122
|
+
import ReactNativeKookit from "react-native-kookit";
|
|
123
|
+
|
|
124
|
+
const subscription = ReactNativeKookit.addListener(
|
|
125
|
+
"onVolumeButtonPressed",
|
|
126
|
+
(event) => {
|
|
127
|
+
console.log("Volume button:", event.key);
|
|
128
|
+
}
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
ReactNativeKookit.enableVolumeKeyInterception();
|
|
132
|
+
```
|
package/app.plugin.js
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
try {
|
|
2
|
+
const { default: withVolumeKeyIntercept } = require('./plugin/build/withVolumeKeyIntercept');
|
|
3
|
+
module.exports = withVolumeKeyIntercept;
|
|
4
|
+
} catch (error) {
|
|
5
|
+
console.warn('Failed to load react-native-kookit plugin:', error.message);
|
|
6
|
+
// Return a no-op plugin as fallback
|
|
7
|
+
module.exports = (config) => config;
|
|
8
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-kookit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.5",
|
|
4
4
|
"description": "React Native module for intercepting volume button presses on iOS and Android",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -32,7 +32,9 @@
|
|
|
32
32
|
"author": "troyeguo <13820674+troyeguo@users.noreply.github.com> (https://github.com/troyeguo)",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"homepage": "https://github.com/troyeguo/react-native-kookit#readme",
|
|
35
|
-
"dependencies": {
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@expo/config-plugins": "^8.0.0"
|
|
37
|
+
},
|
|
36
38
|
"devDependencies": {
|
|
37
39
|
"@types/react": "~19.0.0",
|
|
38
40
|
"expo-module-scripts": "^4.1.10",
|
|
@@ -45,10 +47,8 @@
|
|
|
45
47
|
"react-native": "*"
|
|
46
48
|
},
|
|
47
49
|
"expo": {
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
|
|
51
|
-
]
|
|
52
|
-
}
|
|
50
|
+
"configPlugins": [
|
|
51
|
+
"./app.plugin.js"
|
|
52
|
+
]
|
|
53
53
|
}
|
|
54
54
|
}
|