expo-app-icon 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/README.md +62 -0
- package/android/build.gradle +43 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/dynamicappicon/ExpoAppIconChangerModule.kt +81 -0
- package/android/src/main/java/expo/modules/dynamicappicon/ExpoAppIconChangerPackage.kt +13 -0
- package/android/src/main/java/expo/modules/dynamicappicon/ExpoAppIconChangerReactActivityLifecycleListener.kt +224 -0
- package/android/src/main/java/expo/modules/dynamicappicon/ExpoAppIconChangerView.kt +8 -0
- package/app.plugin.js +1 -0
- package/build/ExpoAppIconChangerModule.d.ts +3 -0
- package/build/ExpoAppIconChangerModule.d.ts.map +1 -0
- package/build/ExpoAppIconChangerModule.js +5 -0
- package/build/ExpoAppIconChangerModule.js.map +1 -0
- package/build/index.d.ts +21 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +21 -0
- package/build/index.js.map +1 -0
- package/build/index.web.d.ts +12 -0
- package/build/index.web.d.ts.map +1 -0
- package/build/index.web.js +16 -0
- package/build/index.web.js.map +1 -0
- package/build/types.d.ts +4 -0
- package/build/types.d.ts.map +1 -0
- package/build/types.js +2 -0
- package/build/types.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/ExpoAppIconChanger.podspec +27 -0
- package/ios/ExpoAppIconChangerModule.swift +34 -0
- package/package.json +59 -0
- package/plugin/build/android-resources.d.ts +89 -0
- package/plugin/build/android-resources.js +151 -0
- package/plugin/build/android.d.ts +18 -0
- package/plugin/build/android.js +203 -0
- package/plugin/build/apple.d.ts +14 -0
- package/plugin/build/apple.js +143 -0
- package/plugin/build/icons.d.ts +23 -0
- package/plugin/build/icons.js +62 -0
- package/plugin/build/index.d.ts +8 -0
- package/plugin/build/index.js +46 -0
- package/plugin/build/types.d.ts +62 -0
- package/plugin/build/types.js +2 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { AppleIconVariant, IconConfig, IconPluginInput, IconSet, ResolvedIconProps } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Coerce whatever the user placed in app config into a normalized icon map.
|
|
4
|
+
* A bare array of image paths is expanded to keyed entries that share the same
|
|
5
|
+
* image for both platforms.
|
|
6
|
+
*/
|
|
7
|
+
export declare function normalizeIconSet(input: IconPluginInput): IconSet;
|
|
8
|
+
/**
|
|
9
|
+
* Build the list of Apple icon variants to emit for the given tablet support.
|
|
10
|
+
*/
|
|
11
|
+
export declare function resolveAppleVariants(supportsTablet: boolean): AppleIconVariant[];
|
|
12
|
+
/**
|
|
13
|
+
* Base name used to reference an icon from the Info.plist (no scale/extension).
|
|
14
|
+
*/
|
|
15
|
+
export declare function appleIconBaseName(iconKey: string, variant: AppleIconVariant): string;
|
|
16
|
+
/**
|
|
17
|
+
* Concrete asset filename for a variant, including @Nx scale and ~target.
|
|
18
|
+
*/
|
|
19
|
+
export declare function appleIconFileName(iconKey: string, variant: AppleIconVariant): string;
|
|
20
|
+
/**
|
|
21
|
+
* Visit every (icon, variant) pair in declaration order.
|
|
22
|
+
*/
|
|
23
|
+
export declare function forEachAppleIcon({ icons, variants }: ResolvedIconProps, visit: (iconKey: string, icon: IconConfig, variant: AppleIconVariant) => Promise<void>): Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.normalizeIconSet = normalizeIconSet;
|
|
4
|
+
exports.resolveAppleVariants = resolveAppleVariants;
|
|
5
|
+
exports.appleIconBaseName = appleIconBaseName;
|
|
6
|
+
exports.appleIconFileName = appleIconFileName;
|
|
7
|
+
exports.forEachAppleIcon = forEachAppleIcon;
|
|
8
|
+
const APPLE_ICON_BLUEPRINTS = [
|
|
9
|
+
{ size: 60, scale: 2 },
|
|
10
|
+
{ size: 60, scale: 3 },
|
|
11
|
+
{ size: 60, scale: 2, width: 152, height: 152, target: "ipad" },
|
|
12
|
+
{ size: 60, scale: 3, width: 167, height: 167, target: "ipad" },
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* Coerce whatever the user placed in app config into a normalized icon map.
|
|
16
|
+
* A bare array of image paths is expanded to keyed entries that share the same
|
|
17
|
+
* image for both platforms.
|
|
18
|
+
*/
|
|
19
|
+
function normalizeIconSet(input) {
|
|
20
|
+
if (Array.isArray(input)) {
|
|
21
|
+
return input.reduce((acc, image, index) => {
|
|
22
|
+
acc[String(index)] = { ios: image, android: image };
|
|
23
|
+
return acc;
|
|
24
|
+
}, {});
|
|
25
|
+
}
|
|
26
|
+
return input ?? {};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Build the list of Apple icon variants to emit for the given tablet support.
|
|
30
|
+
*/
|
|
31
|
+
function resolveAppleVariants(supportsTablet) {
|
|
32
|
+
return APPLE_ICON_BLUEPRINTS.filter((blueprint) => blueprint.target == null || supportsTablet).map((blueprint) => ({
|
|
33
|
+
size: blueprint.size,
|
|
34
|
+
scale: blueprint.scale,
|
|
35
|
+
width: blueprint.width ?? blueprint.size * blueprint.scale,
|
|
36
|
+
height: blueprint.height ?? blueprint.size * blueprint.scale,
|
|
37
|
+
target: blueprint.target ?? null,
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Base name used to reference an icon from the Info.plist (no scale/extension).
|
|
42
|
+
*/
|
|
43
|
+
function appleIconBaseName(iconKey, variant) {
|
|
44
|
+
return `${iconKey}-Icon-${variant.size}x${variant.size}`;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Concrete asset filename for a variant, including @Nx scale and ~target.
|
|
48
|
+
*/
|
|
49
|
+
function appleIconFileName(iconKey, variant) {
|
|
50
|
+
const targetSuffix = variant.target ? `~${variant.target}` : "";
|
|
51
|
+
return `${appleIconBaseName(iconKey, variant)}@${variant.scale}x${targetSuffix}.png`;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Visit every (icon, variant) pair in declaration order.
|
|
55
|
+
*/
|
|
56
|
+
async function forEachAppleIcon({ icons, variants }, visit) {
|
|
57
|
+
for (const [iconKey, icon] of Object.entries(icons)) {
|
|
58
|
+
for (const variant of variants) {
|
|
59
|
+
await visit(iconKey, icon, variant);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ConfigPlugin } from "expo/config-plugins";
|
|
2
|
+
import type { IconPluginInput } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Config plugin entry point. Wires up the per-platform sub-plugins from a
|
|
5
|
+
* single icon declaration and keeps the shipped `IconName` type in sync.
|
|
6
|
+
*/
|
|
7
|
+
declare const withDynamicIcon: ConfigPlugin<IconPluginInput>;
|
|
8
|
+
export default withDynamicIcon;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const android_1 = require("./android");
|
|
9
|
+
const apple_1 = require("./apple");
|
|
10
|
+
const icons_1 = require("./icons");
|
|
11
|
+
const PACKAGE_ROOT = path_1.default.join(__dirname, "..", "..");
|
|
12
|
+
/**
|
|
13
|
+
* Config plugin entry point. Wires up the per-platform sub-plugins from a
|
|
14
|
+
* single icon declaration and keeps the shipped `IconName` type in sync.
|
|
15
|
+
*/
|
|
16
|
+
const withDynamicIcon = (config, input) => {
|
|
17
|
+
const icons = (0, icons_1.normalizeIconSet)(input);
|
|
18
|
+
const variants = (0, icons_1.resolveAppleVariants)(Boolean(config.ios?.supportsTablet));
|
|
19
|
+
const props = { icons, variants };
|
|
20
|
+
config = withTypedIconNames(config, icons);
|
|
21
|
+
config = (0, apple_1.withAppleIconAssets)(config, props);
|
|
22
|
+
config = (0, apple_1.withAppleAlternateIcons)(config, props);
|
|
23
|
+
config = (0, apple_1.withAppleIconImages)(config, props);
|
|
24
|
+
config = (0, android_1.withAndroidIconAliases)(config, icons);
|
|
25
|
+
config = (0, android_1.withAndroidIconResources)(config, icons);
|
|
26
|
+
return config;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Rewrite the shipped `IconName` union in `build/types.d.ts` to the configured
|
|
30
|
+
* icon keys, so `getAppIcon()` / `setAppIcon()` are typed to this project.
|
|
31
|
+
*/
|
|
32
|
+
function withTypedIconNames(config, icons) {
|
|
33
|
+
const union = Object.keys(icons)
|
|
34
|
+
.map((name) => `"${name}"`)
|
|
35
|
+
.join(" | ") || "string";
|
|
36
|
+
const typesFile = path_1.default.join(PACKAGE_ROOT, "build", "types.d.ts");
|
|
37
|
+
try {
|
|
38
|
+
const current = fs_1.default.readFileSync(typesFile, "utf8");
|
|
39
|
+
fs_1.default.writeFileSync(typesFile, current.replace(/IconName:\s.*/, `IconName: ${union}`));
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
// The types file only exists in a built package; ignore when absent.
|
|
43
|
+
}
|
|
44
|
+
return config;
|
|
45
|
+
}
|
|
46
|
+
exports.default = withDynamicIcon;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A single icon entry as declared in the plugin config.
|
|
3
|
+
*/
|
|
4
|
+
export type IconConfig = {
|
|
5
|
+
/**
|
|
6
|
+
* Path to the iOS source image.
|
|
7
|
+
*/
|
|
8
|
+
ios?: string;
|
|
9
|
+
/**
|
|
10
|
+
* Path to the Android source image.
|
|
11
|
+
*/
|
|
12
|
+
android?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Whether iOS should treat the icon as already rendered (no gloss).
|
|
15
|
+
*/
|
|
16
|
+
prerendered?: boolean;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Map of icon key → icon config, as used everywhere internally.
|
|
20
|
+
*/
|
|
21
|
+
export type IconSet = Record<string, IconConfig>;
|
|
22
|
+
/**
|
|
23
|
+
* What the plugin accepts from the app config: a keyed map, a bare list of
|
|
24
|
+
* image paths, or nothing.
|
|
25
|
+
*/
|
|
26
|
+
export type IconPluginInput = IconSet | string[] | void;
|
|
27
|
+
/**
|
|
28
|
+
* Device family an Apple icon variant targets.
|
|
29
|
+
*/
|
|
30
|
+
export type AppleIconTarget = null | "ipad";
|
|
31
|
+
/**
|
|
32
|
+
* One concrete Apple icon row written into the asset catalog / Info.plist.
|
|
33
|
+
*/
|
|
34
|
+
export type AppleIconVariant = {
|
|
35
|
+
/**
|
|
36
|
+
* Logical point size; drives the asset base name.
|
|
37
|
+
*/
|
|
38
|
+
size: number;
|
|
39
|
+
/**
|
|
40
|
+
* @Nx scale; drives the asset file suffix.
|
|
41
|
+
*/
|
|
42
|
+
scale: number;
|
|
43
|
+
/**
|
|
44
|
+
* Pixel width (defaults to `size * scale`).
|
|
45
|
+
*/
|
|
46
|
+
width: number;
|
|
47
|
+
/**
|
|
48
|
+
* Pixel height (defaults to `size * scale`).
|
|
49
|
+
*/
|
|
50
|
+
height: number;
|
|
51
|
+
/**
|
|
52
|
+
* Device family this row applies to, if any.
|
|
53
|
+
*/
|
|
54
|
+
target: AppleIconTarget;
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Props threaded between the per-platform sub-plugins.
|
|
58
|
+
*/
|
|
59
|
+
export type ResolvedIconProps = {
|
|
60
|
+
icons: IconSet;
|
|
61
|
+
variants: AppleIconVariant[];
|
|
62
|
+
};
|