react-native-live-widgets 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +221 -2
- package/android/build.gradle +49 -0
- package/android/src/main/AndroidManifest.xml +38 -0
- package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityModule.kt +440 -0
- package/android/src/main/java/com/reactnativeliveactivity/bridge/LiveActivityPackage.kt +17 -0
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityHeadlessTaskService.kt +24 -0
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityNotifier.kt +410 -0
- package/android/src/main/java/com/reactnativeliveactivity/liveactivity/LiveActivityReceiver.kt +67 -0
- package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicNodeRegistry.kt +64 -0
- package/android/src/main/java/com/reactnativeliveactivity/renderer/DynamicWidgetCanvasRenderer.kt +1223 -0
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetImageCache.kt +120 -0
- package/android/src/main/java/com/reactnativeliveactivity/storage/DynamicWidgetStateStore.kt +281 -0
- package/android/src/main/java/com/reactnativeliveactivity/widgets/DynamicHomeScreenWidgetProvider.kt +229 -0
- package/android/src/main/res/layout/rn_live_widget_host.xml +113 -0
- package/android/src/main/res/xml/rn_live_widget_info.xml +14 -0
- package/assets/dashboard_features.png +0 -0
- package/assets/dynamic_island_expanded.png +0 -0
- package/assets/home_widget_interactive.png +0 -0
- package/assets/lock_screen_live_activity.png +0 -0
- package/cli/setup.js +94 -0
- package/docs/GUIDE-EN.md +804 -0
- package/docs/GUIDE-VI.md +802 -0
- package/docs/widgets.md +52 -0
- package/ios/Bridge/LiveActivityModule.m +105 -0
- package/ios/Bridge/LiveActivityModule.swift +957 -0
- package/ios/Intents/DynamicWidgetActionIntent.swift +38 -0
- package/ios/Models/DynamicActivityAttributes.swift +22 -0
- package/ios/Models/DynamicLayoutModels.swift +243 -0
- package/ios/Renderer/ColorHexExtension.swift +49 -0
- package/ios/Renderer/DynamicNodeRegistry.swift +54 -0
- package/ios/Renderer/DynamicNodeView.swift +1060 -0
- package/ios/Storage/DynamicWidgetImageCache.swift +137 -0
- package/ios/Storage/DynamicWidgetStateStore.swift +162 -0
- package/ios/Widgets/DynamicHomeScreenWidget.swift +435 -0
- package/ios/Widgets/DynamicLiveActivityWidget.swift +79 -0
- package/lib/builder.d.ts +60 -0
- package/lib/builder.d.ts.map +1 -0
- package/lib/builder.js +296 -0
- package/lib/builder.js.map +1 -0
- package/lib/dispatcher.d.ts +16 -0
- package/lib/dispatcher.d.ts.map +1 -0
- package/lib/dispatcher.js +23 -0
- package/lib/dispatcher.js.map +1 -0
- package/lib/index.d.ts +199 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +634 -0
- package/lib/index.js.map +1 -0
- package/lib/types.d.ts +489 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/types.js +10 -0
- package/lib/types.js.map +1 -0
- package/package.json +68 -4
- package/react-native-live-widgets.podspec +38 -0
- package/src/builder.ts +409 -0
- package/src/dispatcher.ts +25 -0
- package/src/index.ts +681 -0
- package/src/types.ts +595 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:id="@+id/rn_widget_root"
|
|
4
|
+
android:layout_width="match_parent"
|
|
5
|
+
android:layout_height="match_parent">
|
|
6
|
+
|
|
7
|
+
<!-- Lớp Canvas vẽ toàn bộ cây giao diện UI.VStack / HStack / Progress / Image / Text / Timer -->
|
|
8
|
+
<ImageView
|
|
9
|
+
android:id="@+id/rn_widget_canvas"
|
|
10
|
+
android:layout_width="match_parent"
|
|
11
|
+
android:layout_height="match_parent"
|
|
12
|
+
android:scaleType="fitCenter"
|
|
13
|
+
android:contentDescription="Live Widget Content" />
|
|
14
|
+
|
|
15
|
+
<!-- Lớp vùng bấm tương tác (Interactive Hit Zones) cho các UI.Button trên Widget -->
|
|
16
|
+
<LinearLayout
|
|
17
|
+
android:layout_width="match_parent"
|
|
18
|
+
android:layout_height="match_parent"
|
|
19
|
+
android:orientation="vertical"
|
|
20
|
+
android:weightSum="100">
|
|
21
|
+
|
|
22
|
+
<!-- Hàng trên cùng (dành cho thanh Tab Bar chuyển trang: page:shift, page:todo, page:okr, page:next) -->
|
|
23
|
+
<LinearLayout
|
|
24
|
+
android:id="@+id/rn_widget_row_top"
|
|
25
|
+
android:layout_width="match_parent"
|
|
26
|
+
android:layout_height="0dp"
|
|
27
|
+
android:layout_weight="22"
|
|
28
|
+
android:orientation="horizontal">
|
|
29
|
+
|
|
30
|
+
<TextView
|
|
31
|
+
android:id="@+id/rn_hit_top_1"
|
|
32
|
+
android:layout_width="0dp"
|
|
33
|
+
android:layout_height="match_parent"
|
|
34
|
+
android:layout_weight="1"
|
|
35
|
+
android:background="@android:color/transparent" />
|
|
36
|
+
|
|
37
|
+
<TextView
|
|
38
|
+
android:id="@+id/rn_hit_top_2"
|
|
39
|
+
android:layout_width="0dp"
|
|
40
|
+
android:layout_height="match_parent"
|
|
41
|
+
android:layout_weight="1"
|
|
42
|
+
android:background="@android:color/transparent" />
|
|
43
|
+
|
|
44
|
+
<TextView
|
|
45
|
+
android:id="@+id/rn_hit_top_3"
|
|
46
|
+
android:layout_width="0dp"
|
|
47
|
+
android:layout_height="match_parent"
|
|
48
|
+
android:layout_weight="1"
|
|
49
|
+
android:background="@android:color/transparent" />
|
|
50
|
+
|
|
51
|
+
<TextView
|
|
52
|
+
android:id="@+id/rn_hit_top_4"
|
|
53
|
+
android:layout_width="0dp"
|
|
54
|
+
android:layout_height="match_parent"
|
|
55
|
+
android:layout_weight="1"
|
|
56
|
+
android:background="@android:color/transparent" />
|
|
57
|
+
</LinearLayout>
|
|
58
|
+
|
|
59
|
+
<!-- Vùng giữa (dành cho danh sách các nút bấm / Todo items: toggle:todo_1, toggle:todo_2, toggle:todo_3) -->
|
|
60
|
+
<LinearLayout
|
|
61
|
+
android:id="@+id/rn_widget_row_mid"
|
|
62
|
+
android:layout_width="match_parent"
|
|
63
|
+
android:layout_height="0dp"
|
|
64
|
+
android:layout_weight="58"
|
|
65
|
+
android:orientation="vertical">
|
|
66
|
+
|
|
67
|
+
<TextView
|
|
68
|
+
android:id="@+id/rn_hit_mid_1"
|
|
69
|
+
android:layout_width="match_parent"
|
|
70
|
+
android:layout_height="0dp"
|
|
71
|
+
android:layout_weight="1"
|
|
72
|
+
android:background="@android:color/transparent" />
|
|
73
|
+
|
|
74
|
+
<TextView
|
|
75
|
+
android:id="@+id/rn_hit_mid_2"
|
|
76
|
+
android:layout_width="match_parent"
|
|
77
|
+
android:layout_height="0dp"
|
|
78
|
+
android:layout_weight="1"
|
|
79
|
+
android:background="@android:color/transparent" />
|
|
80
|
+
|
|
81
|
+
<TextView
|
|
82
|
+
android:id="@+id/rn_hit_mid_3"
|
|
83
|
+
android:layout_width="match_parent"
|
|
84
|
+
android:layout_height="0dp"
|
|
85
|
+
android:layout_weight="1"
|
|
86
|
+
android:background="@android:color/transparent" />
|
|
87
|
+
</LinearLayout>
|
|
88
|
+
|
|
89
|
+
<!-- Hàng dưới cùng (dành cho nút Refresh API ngầm / Điều hướng: refresh, page:prev, page:next) -->
|
|
90
|
+
<LinearLayout
|
|
91
|
+
android:id="@+id/rn_widget_row_bottom"
|
|
92
|
+
android:layout_width="match_parent"
|
|
93
|
+
android:layout_height="0dp"
|
|
94
|
+
android:layout_weight="20"
|
|
95
|
+
android:orientation="horizontal">
|
|
96
|
+
|
|
97
|
+
<TextView
|
|
98
|
+
android:id="@+id/rn_hit_bot_1"
|
|
99
|
+
android:layout_width="0dp"
|
|
100
|
+
android:layout_height="match_parent"
|
|
101
|
+
android:layout_weight="1"
|
|
102
|
+
android:background="@android:color/transparent" />
|
|
103
|
+
|
|
104
|
+
<TextView
|
|
105
|
+
android:id="@+id/rn_hit_bot_2"
|
|
106
|
+
android:layout_width="0dp"
|
|
107
|
+
android:layout_height="match_parent"
|
|
108
|
+
android:layout_weight="1"
|
|
109
|
+
android:background="@android:color/transparent" />
|
|
110
|
+
</LinearLayout>
|
|
111
|
+
</LinearLayout>
|
|
112
|
+
</FrameLayout>
|
|
113
|
+
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:minWidth="250dp"
|
|
4
|
+
android:minHeight="180dp"
|
|
5
|
+
android:targetCellWidth="4"
|
|
6
|
+
android:targetCellHeight="3"
|
|
7
|
+
android:minResizeWidth="140dp"
|
|
8
|
+
android:minResizeHeight="110dp"
|
|
9
|
+
android:maxResizeWidth="520dp"
|
|
10
|
+
android:maxResizeHeight="520dp"
|
|
11
|
+
android:updatePeriodMillis="900000"
|
|
12
|
+
android:initialLayout="@layout/rn_live_widget_host"
|
|
13
|
+
android:resizeMode="horizontal|vertical"
|
|
14
|
+
android:widgetCategory="home_screen" />
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/cli/setup.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* CLI setup script cho React Native thuần:
|
|
5
|
+
* npx react-native-live-widgets init
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
11
|
+
const projectRoot = process.cwd();
|
|
12
|
+
const iosDir = path.join(projectRoot, 'ios');
|
|
13
|
+
const androidDir = path.join(projectRoot, 'android');
|
|
14
|
+
|
|
15
|
+
console.log('🚀 [react-native-live-widgets] Bắt đầu thiết lập dự án React Native...');
|
|
16
|
+
|
|
17
|
+
if (!fs.existsSync(iosDir)) {
|
|
18
|
+
console.error('❌ Không tìm thấy thư mục ios/. Hãy chạy lệnh này ở thư mục gốc của dự án React Native.');
|
|
19
|
+
process.exit(1);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// 1. Cấu hình Info.plist iOS: NSSupportsLiveActivities = YES
|
|
23
|
+
try {
|
|
24
|
+
const xcodeProjects = fs.readdirSync(iosDir).filter((file) => file.endsWith('.xcodeproj'));
|
|
25
|
+
if (xcodeProjects.length > 0) {
|
|
26
|
+
const appName = xcodeProjects[0].replace('.xcodeproj', '');
|
|
27
|
+
const infoPlistPath = path.join(iosDir, appName, 'Info.plist');
|
|
28
|
+
|
|
29
|
+
if (fs.existsSync(infoPlistPath)) {
|
|
30
|
+
let plistContent = fs.readFileSync(infoPlistPath, 'utf8');
|
|
31
|
+
if (!plistContent.includes('NSSupportsLiveActivities')) {
|
|
32
|
+
plistContent = plistContent.replace(
|
|
33
|
+
'<dict>',
|
|
34
|
+
'<dict>\n\t<key>NSSupportsLiveActivities</key>\n\t<true/>\n\t<key>NSSupportsLiveActivitiesFrequentUpdates</key>\n\t<true/>'
|
|
35
|
+
);
|
|
36
|
+
fs.writeFileSync(infoPlistPath, plistContent, 'utf8');
|
|
37
|
+
console.log(`✅ Đã thêm NSSupportsLiveActivities vào ${appName}/Info.plist`);
|
|
38
|
+
} else {
|
|
39
|
+
console.log(`ℹ️ NSSupportsLiveActivities đã tồn tại trong ${appName}/Info.plist`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
console.warn('⚠️ Không thể tự động chỉnh sửa Info.plist:', e.message);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 2. Tạo template Widget Extension Bundle nếu chưa có
|
|
48
|
+
const widgetTargetDir = path.join(iosDir, 'LiveWidgetsExtension');
|
|
49
|
+
if (!fs.existsSync(widgetTargetDir)) {
|
|
50
|
+
fs.mkdirSync(widgetTargetDir, { recursive: true });
|
|
51
|
+
|
|
52
|
+
const widgetBundleContent = `import WidgetKit
|
|
53
|
+
import SwiftUI
|
|
54
|
+
import react_native_live_widgets
|
|
55
|
+
|
|
56
|
+
@main
|
|
57
|
+
struct LiveWidgetsBundle: WidgetBundle {
|
|
58
|
+
var body: some Widget {
|
|
59
|
+
// 1. Live Activity & Dynamic Island (iOS 16.1+)
|
|
60
|
+
if #available(iOS 16.1, *) {
|
|
61
|
+
DynamicLiveActivityWidget()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// 2. Home Screen Widget (Màn hình chính)
|
|
65
|
+
DynamicHomeScreenWidget()
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
struct DynamicHomeScreenWidget: Widget {
|
|
70
|
+
let kind: String = "DynamicHomeScreenWidget"
|
|
71
|
+
|
|
72
|
+
var body: some WidgetConfiguration {
|
|
73
|
+
StaticConfiguration(kind: kind, provider: DynamicWidgetProvider(widgetKey: "main")) { entry in
|
|
74
|
+
DynamicHomeScreenWidgetView(entry: entry)
|
|
75
|
+
}
|
|
76
|
+
.configurationDisplayName("Tiện ích")
|
|
77
|
+
.description("Hiển thị thông tin cập nhật từ ứng dụng.")
|
|
78
|
+
.supportedFamilies([.systemSmall, .systemMedium, .systemLarge])
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
`;
|
|
82
|
+
fs.writeFileSync(path.join(widgetTargetDir, 'LiveWidgetsBundle.swift'), widgetBundleContent, 'utf8');
|
|
83
|
+
console.log('✅ Đã tạo file template: ios/LiveWidgetsExtension/LiveWidgetsBundle.swift');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
console.log('\n🎉 Thiết lập ban đầu hoàn tất!');
|
|
87
|
+
console.log('👉 Tiếp theo:');
|
|
88
|
+
console.log('1. Mở Xcode, chọn File -> New -> Target -> Widget Extension (đặt tên LiveWidgetsExtension, bỏ tích "Include Configuration App Intent").');
|
|
89
|
+
console.log('2. Trong Podfile, thêm vào bên trong target chính:');
|
|
90
|
+
console.log(` target 'LiveWidgetsExtension' do
|
|
91
|
+
inherit! :search_paths
|
|
92
|
+
pod 'react-native-live-widgets/Widget', :path => '../node_modules/react-native-live-widgets'
|
|
93
|
+
end`);
|
|
94
|
+
console.log('3. Chạy "cd ios && pod install" là sẵn sàng sử dụng!\n');
|