nn-widgets 0.1.17 → 0.1.18
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/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withAndroidWidget.d.ts","sourceRoot":"","sources":["../src/withAndroidWidget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,sBAAsB,CAAC;AAGzE,OAAO,KAAK,EACV,oBAAoB,EAGrB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"withAndroidWidget.d.ts","sourceRoot":"","sources":["../src/withAndroidWidget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAuB,MAAM,sBAAsB,CAAC;AAGzE,OAAO,KAAK,EACV,oBAAoB,EAGrB,MAAM,SAAS,CAAC;AAmgCjB,eAAO,MAAM,iBAAiB,EAAE,YAAY,CAAC,oBAAoB,CAyQhE,CAAC;AAEF,eAAe,iBAAiB,CAAC"}
|
|
@@ -39,6 +39,38 @@ const fs = __importStar(require("fs"));
|
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
40
|
const withIosWidget_1 = require("./withIosWidget");
|
|
41
41
|
// ──────────────────────────────────────────────
|
|
42
|
+
// Constants and helpers
|
|
43
|
+
// ──────────────────────────────────────────────
|
|
44
|
+
// Material background names that should use blur effect on Android 12+
|
|
45
|
+
const BLUR_BACKGROUNDS = [
|
|
46
|
+
"blur",
|
|
47
|
+
"ultraThinMaterial",
|
|
48
|
+
"thinMaterial",
|
|
49
|
+
"regularMaterial",
|
|
50
|
+
"thickMaterial",
|
|
51
|
+
"ultraThickMaterial",
|
|
52
|
+
];
|
|
53
|
+
/**
|
|
54
|
+
* Check if backgroundColor should use blur effect
|
|
55
|
+
*/
|
|
56
|
+
function isBlurBackground(bgColor) {
|
|
57
|
+
return bgColor ? BLUR_BACKGROUNDS.includes(bgColor) : false;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Resolve Android background attribute for XML.
|
|
61
|
+
* - If blur/material: use system widget background (API 31+) or transparent
|
|
62
|
+
* - Otherwise: use the color directly
|
|
63
|
+
*/
|
|
64
|
+
function resolveAndroidBackground(bgColor) {
|
|
65
|
+
if (!bgColor)
|
|
66
|
+
return "#FFFFFF";
|
|
67
|
+
if (isBlurBackground(bgColor)) {
|
|
68
|
+
// Will be handled by drawable resource
|
|
69
|
+
return "@drawable/widget_blur_background";
|
|
70
|
+
}
|
|
71
|
+
return bgColor;
|
|
72
|
+
}
|
|
73
|
+
// ──────────────────────────────────────────────
|
|
42
74
|
// Code generation helpers (per widget)
|
|
43
75
|
// ──────────────────────────────────────────────
|
|
44
76
|
function generateWidgetProviderCode(w, packageName, deepLinkUrl) {
|
|
@@ -646,7 +678,7 @@ function generateWidgetLayoutXml(w) {
|
|
|
646
678
|
}
|
|
647
679
|
// ── List layout ──
|
|
648
680
|
if (w.type === "list") {
|
|
649
|
-
const bgColor = w.style?.backgroundColor
|
|
681
|
+
const bgColor = resolveAndroidBackground(w.style?.backgroundColor);
|
|
650
682
|
const titleColor = w.style?.titleColor || "#000000";
|
|
651
683
|
const subtitleColor = w.style?.subtitleColor || "#888888";
|
|
652
684
|
return `<?xml version="1.0" encoding="utf-8"?>
|
|
@@ -699,7 +731,7 @@ function generateWidgetLayoutXml(w) {
|
|
|
699
731
|
}
|
|
700
732
|
// ── Flex-grid layout ──
|
|
701
733
|
if (w.type === "flex-grid") {
|
|
702
|
-
const bgColor = w.style?.backgroundColor
|
|
734
|
+
const bgColor = resolveAndroidBackground(w.style?.backgroundColor);
|
|
703
735
|
const titleColor = w.style?.titleColor || "#000000";
|
|
704
736
|
const subtitleColor = w.style?.subtitleColor || "#888888";
|
|
705
737
|
return `<?xml version="1.0" encoding="utf-8"?>
|
|
@@ -751,7 +783,7 @@ function generateWidgetLayoutXml(w) {
|
|
|
751
783
|
`;
|
|
752
784
|
}
|
|
753
785
|
// ── Single (default) styled text layout ──
|
|
754
|
-
const bgColor = w.style?.backgroundColor
|
|
786
|
+
const bgColor = resolveAndroidBackground(w.style?.backgroundColor);
|
|
755
787
|
const titleColor = w.style?.titleColor || "#000000";
|
|
756
788
|
const subtitleColor = w.style?.subtitleColor || "#888888";
|
|
757
789
|
const accentColor = w.style?.accentColor || "#6200EE";
|
|
@@ -948,6 +980,32 @@ function generateFlexGridCellCardLayoutXml(w) {
|
|
|
948
980
|
</LinearLayout>
|
|
949
981
|
`;
|
|
950
982
|
}
|
|
983
|
+
/**
|
|
984
|
+
* Generate blur background drawable for API 31+ (Android 12+)
|
|
985
|
+
* Uses the system widget background with rounded corners
|
|
986
|
+
*/
|
|
987
|
+
function generateBlurBackgroundDrawableV31() {
|
|
988
|
+
return `<?xml version="1.0" encoding="utf-8"?>
|
|
989
|
+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
|
990
|
+
android:shape="rectangle">
|
|
991
|
+
<corners android:radius="16dp" />
|
|
992
|
+
<solid android:color="@android:color/system_accent1_50" />
|
|
993
|
+
</shape>
|
|
994
|
+
`;
|
|
995
|
+
}
|
|
996
|
+
/**
|
|
997
|
+
* Generate blur background drawable for pre-API 31 (fallback)
|
|
998
|
+
* Uses semi-transparent white with rounded corners
|
|
999
|
+
*/
|
|
1000
|
+
function generateBlurBackgroundDrawableFallback() {
|
|
1001
|
+
return `<?xml version="1.0" encoding="utf-8"?>
|
|
1002
|
+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
|
1003
|
+
android:shape="rectangle">
|
|
1004
|
+
<corners android:radius="16dp" />
|
|
1005
|
+
<solid android:color="#E6FFFFFF" />
|
|
1006
|
+
</shape>
|
|
1007
|
+
`;
|
|
1008
|
+
}
|
|
951
1009
|
function generateWidgetInfoXml(w, updatePeriodMillis) {
|
|
952
1010
|
return `<?xml version="1.0" encoding="utf-8"?>
|
|
953
1011
|
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
|
@@ -979,17 +1037,29 @@ const withAndroidWidget = (config, props = {}) => {
|
|
|
979
1037
|
const resXmlPath = path.join(androidPath, "res", "xml");
|
|
980
1038
|
const resValuesPath = path.join(androidPath, "res", "values");
|
|
981
1039
|
const resDrawablePath = path.join(androidPath, "res", "drawable");
|
|
1040
|
+
const resDrawableV31Path = path.join(androidPath, "res", "drawable-v31");
|
|
982
1041
|
[
|
|
983
1042
|
widgetPackagePath,
|
|
984
1043
|
resLayoutPath,
|
|
985
1044
|
resXmlPath,
|
|
986
1045
|
resValuesPath,
|
|
987
1046
|
resDrawablePath,
|
|
1047
|
+
resDrawableV31Path,
|
|
988
1048
|
].forEach((dir) => {
|
|
989
1049
|
if (!fs.existsSync(dir)) {
|
|
990
1050
|
fs.mkdirSync(dir, { recursive: true });
|
|
991
1051
|
}
|
|
992
1052
|
});
|
|
1053
|
+
// Check if any widget uses blur background
|
|
1054
|
+
const hasBlurWidget = resolvedProps.widgets.some((w) => isBlurBackground(w.style?.backgroundColor));
|
|
1055
|
+
// Generate blur background drawables if needed
|
|
1056
|
+
if (hasBlurWidget) {
|
|
1057
|
+
// Fallback drawable (pre-API 31)
|
|
1058
|
+
fs.writeFileSync(path.join(resDrawablePath, "widget_blur_background.xml"), generateBlurBackgroundDrawableFallback());
|
|
1059
|
+
// API 31+ drawable
|
|
1060
|
+
fs.writeFileSync(path.join(resDrawableV31Path, "widget_blur_background.xml"), generateBlurBackgroundDrawableV31());
|
|
1061
|
+
console.log("[nn-widgets] Generated Android blur background drawables");
|
|
1062
|
+
}
|
|
993
1063
|
// Generate files for each widget
|
|
994
1064
|
for (const w of resolvedProps.widgets) {
|
|
995
1065
|
// Widget provider Kotlin
|