fix(mobile): fit the Android splash icon to its circular mask (#10620)

Co-authored-by: Claude Fable 5 <[email protected]>
This commit is contained in:
Julius MarmingeandClaude Fable 5 authored and GitHub committed 2026-09-07 18:20:46 -07:00
1 parent d081ab7abc
commit 892de47f06
6 files changed
+94 -27

No files matched your search

+12
View File
@@ -39,6 +39,7 @@ const DEVELOPMENT_ASSETS = {
androidAdaptiveForeground,
androidAdaptiveBackgroundColor: "#347FF8",
androidAdaptiveBackgroundImage: "./assets/android-icon-background-dev.png",
androidSplashIcon: "./assets/android-splash-icon-dev.png",
androidMonochromeIcon: "./assets/android-icon-mark.png",
androidNotificationIcon: "./assets/android-notification-icon.png",
androidNotificationColor: "#00639B",
@@ -51,6 +52,7 @@ const PREVIEW_ASSETS = {
androidAdaptiveForeground,
androidAdaptiveBackgroundColor: "#111533",
androidAdaptiveBackgroundImage: "./assets/android-icon-background-nightly.png",
androidSplashIcon: "./assets/android-splash-icon-nightly.png",
androidMonochromeIcon: "./assets/android-icon-mark.png",
androidNotificationIcon: "./assets/android-notification-icon.png",
androidNotificationColor: "#7565C7",
@@ -63,6 +65,7 @@ const RELEASE_ASSETS = {
androidAdaptiveForeground,
androidAdaptiveBackgroundColor: "#000000",
androidAdaptiveBackgroundImage: undefined,
androidSplashIcon: "./assets/android-splash-icon-prod.png",
androidMonochromeIcon: "./assets/android-icon-mark.png",
androidNotificationIcon: "./assets/android-notification-icon.png",
androidNotificationColor: "#FFFFFF",
@@ -339,6 +342,15 @@ const config: ExpoConfig = {
image: variant.assets.splashIcon,
backgroundColor: "#0a0a0a",
},
android: {
// Android 12+ masks the splash icon to a circle over the central two thirds of
// its 288dp canvas, so the iOS export's corners get cut. A full-canvas image of
// the composed adaptive layers puts the wordmark in the same frame the launcher
// icon uses.
image: variant.assets.androidSplashIcon,
imageWidth: 288,
dark: { image: variant.assets.androidSplashIcon },
},
},
],
[
Binary file not shown.

After

Width:  |  Height:  |  Size: 949 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 341 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

+7 -5
View File
@@ -49,17 +49,19 @@ Verify every result is 1024×1024 and has the classic macOS safe area: an 824×8
Do not edit the generated PNG or ICO files directly.
## Android adaptive icon layers
## Android launcher and splash artwork
Android masks the central 72dp of a 108dp adaptive canvas, so the Icon Composer exports cannot be
used directly: their rounded-square silhouette gets framed again and the wordmark is cropped. The
Android layers are instead rendered from the same Icon Composer SVG sources by
`vp run icons:export:android`:
Android masks the central 72dp of a 108dp adaptive canvas, and the Android 12+ splash screen masks
the central two thirds of a 288dp canvas, so the Icon Composer exports cannot be used directly:
their rounded-square silhouette gets framed again and the wordmark is cropped. The Android artwork
is instead rendered from the same Icon Composer SVG sources by `vp run icons:export:android`:
- `apps/mobile/assets/android-icon-foreground.png`: the shared transparent wordmark, sized to stay
inside the safe zone
- `apps/mobile/assets/android-icon-background-dev.png` and `-nightly.png`: full-bleed variant
artwork (blueprint grid and annotations; night sky and clouds). Production uses a solid color.
- `apps/mobile/assets/android-splash-icon-*.png`: the two layers composed into one 288dp image, so
the splash mask reproduces the launcher icon's framing.
Rerun the export after changing a layer SVG. `android-icon-mark.png` remains a flat silhouette for
Android's monochrome themed icon.
+75 -22
View File
@@ -1,12 +1,17 @@
#!/usr/bin/env node
// Renders the Android adaptive-icon layers from the Icon Composer SVG sources.
// Renders the Android launcher and splash artwork from the Icon Composer SVG sources.
//
// Icon Composer exports already contain a rounded-square silhouette, and Android masks
// the central 72dp of a 108dp adaptive canvas, so exporting them as a foreground produces
// a double-framed icon with the letters cropped by the mask. Instead, each variant gets a
// full-bleed background layer (the artwork behind the wordmark) and a shared transparent
// foreground that keeps the wordmark inside the safe zone.
//
// The Android 12+ splash screen masks its icon to a circle covering the central two thirds
// of a 288dp canvas, which is the same proportion the launcher crops. Composing the two
// adaptive layers into one 288dp image therefore makes the splash frame the wordmark
// exactly like the launcher icon does.
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
import * as NodeServices from "@effect/platform-node/NodeServices";
@@ -19,8 +24,10 @@ import sharp from "sharp";
type IconVariant = "dev" | "nightly" | "prod";
// 108dp at xxxhdpi. Expo's prebuild derives every density bucket from this.
const CANVAS = 432;
// 108dp at xxxhdpi. Expo's prebuild derives every launcher density bucket from this.
const ADAPTIVE_CANVAS = 432;
// 288dp at xxxhdpi: the full Android 12+ splash canvas, so the icon needs no upscaling.
const SPLASH_CANVAS = 1152;
// Icon Composer's layer sources use a 128pt viewBox; the wordmark path spans this box.
const TEXT = { x: 15.53, y: 37, width: 94.5, height: 57 };
// Wordmark width as a fraction of the 108dp canvas. The visible area is 72dp (66dp
@@ -31,21 +38,23 @@ const WORDMARK_FRACTION = 0.48;
const COMPOSER_CANVAS_PT = 1024;
const SVG_DENSITY = 300;
const OUTPUT_DIRECTORY = "apps/mobile/assets";
// Production has no background artwork, so its splash composes onto the adaptive color.
const PRODUCTION_BACKGROUND_COLOR = "#000000";
export class AndroidIconRenderError extends Schema.TaggedErrorClass<AndroidIconRenderError>()(
"AndroidIconRenderError",
{ layer: Schema.String, cause: Schema.Defect() },
) {}
const wordmarkTransform = () => {
const scale = (CANVAS * WORDMARK_FRACTION) / TEXT.width;
const tx = (CANVAS - TEXT.width * scale) / 2 - TEXT.x * scale;
const ty = (CANVAS - TEXT.height * scale) / 2 - TEXT.y * scale;
const wordmarkTransform = (size: number) => {
const scale = (size * WORDMARK_FRACTION) / TEXT.width;
const tx = (size - TEXT.width * scale) / 2 - TEXT.x * scale;
const ty = (size - TEXT.height * scale) / 2 - TEXT.y * scale;
return `translate(${tx.toFixed(3)} ${ty.toFixed(3)}) scale(${scale.toFixed(4)})`;
};
const canvasSvg = (inner: string) =>
`<svg xmlns="http://www.w3.org/2000/svg" width="${CANVAS}" height="${CANVAS}" viewBox="0 0 ${CANVAS} ${CANVAS}" fill="none">${inner}</svg>`;
const canvasSvg = (size: number, inner: string) =>
`<svg xmlns="http://www.w3.org/2000/svg" width="${size}" height="${size}" viewBox="0 0 ${size} ${size}" fill="none">${inner}</svg>`;
// The layer sources clip to a 10pt rounded rectangle for the iOS silhouette. Android
// applies its own mask, so the layer must bleed to the canvas edge.
@@ -73,6 +82,15 @@ const composite = (
catch: (cause) => new AndroidIconRenderError({ layer, cause }),
});
const solidCanvas = (layer: string, size: number, background: string) =>
Effect.tryPromise({
try: () =>
sharp({ create: { width: size, height: size, channels: 4, background } })
.png()
.toBuffer(),
catch: (cause) => new AndroidIconRenderError({ layer, cause }),
});
const readLayerSource = Effect.fn("androidIcons.readLayerSource")(function* (
repositoryRoot: string,
variant: IconVariant,
@@ -87,29 +105,30 @@ const readLayerSource = Effect.fn("androidIcons.readLayerSource")(function* (
const renderForeground = Effect.fn("androidIcons.renderForeground")(function* (
repositoryRoot: string,
size: number,
) {
const text = yield* readLayerSource(repositoryRoot, "prod", "text.svg");
const paths = text.match(/<path[^>]*\/>/g) ?? [];
return yield* rasterize(
"foreground",
canvasSvg(`<g transform="${wordmarkTransform()}">${paths.join("")}</g>`),
CANVAS,
canvasSvg(size, `<g transform="${wordmarkTransform(size)}">${paths.join("")}</g>`),
size,
);
});
const renderDevelopmentBackground = Effect.fn("androidIcons.renderDevelopmentBackground")(
function* (repositoryRoot: string) {
function* (repositoryRoot: string, size: number) {
// The annotation layer shares the wordmark's coordinate space, so it is scaled and
// centered the same way to keep the dimension lines around the letters.
const annotations = yield* readLayerSource(repositoryRoot, "dev", "annotations.svg");
const defs = annotations.match(/<defs>[\s\S]*?<\/defs>/)?.[0] ?? "";
const body = annotations.replace(/^[\s\S]*?<\/defs>/, "").replace(/<\/svg>\s*$/, "");
const paper = yield* readLayerSource(repositoryRoot, "dev", "background.svg");
const background = yield* rasterize("dev-background", fullBleed(paper), CANVAS);
const background = yield* rasterize("dev-background", fullBleed(paper), size);
const overlay = yield* rasterize(
"dev-annotations",
canvasSvg(`${defs}<g transform="${wordmarkTransform()}">${body}</g>`),
CANVAS,
canvasSvg(size, `${defs}<g transform="${wordmarkTransform(size)}">${body}</g>`),
size,
);
return yield* composite("dev-background", background, [{ input: overlay }]);
},
@@ -117,6 +136,7 @@ const renderDevelopmentBackground = Effect.fn("androidIcons.renderDevelopmentBac
const renderNightlyBackground = Effect.fn("androidIcons.renderNightlyBackground")(function* (
repositoryRoot: string,
size: number,
) {
// Positions mirror assets/nightly/app-icon.icon/icon.json. The SVG blur filter is
// dropped because Icon Composer ignores it and it smears at this raster size.
@@ -128,7 +148,7 @@ const renderNightlyBackground = Effect.fn("androidIcons.renderNightlyBackground"
translation: [387.9605131881942, -134.30064713259117],
},
] as const;
const k = CANVAS / COMPOSER_CANVAS_PT;
const k = size / COMPOSER_CANVAS_PT;
const overlays = yield* Effect.forEach(clouds, (cloud) =>
Effect.gen(function* () {
const width = Math.round(64 * cloud.scale * k);
@@ -144,8 +164,8 @@ const renderNightlyBackground = Effect.fn("androidIcons.renderNightlyBackground"
);
const x0 = Math.max(0, left);
const y0 = Math.max(0, top);
const x1 = Math.min(CANVAS, left + width);
const y1 = Math.min(CANVAS, top + height);
const x1 = Math.min(size, left + width);
const y1 = Math.min(size, top + height);
const clipped = yield* Effect.tryPromise({
try: () =>
sharp(png)
@@ -158,18 +178,51 @@ const renderNightlyBackground = Effect.fn("androidIcons.renderNightlyBackground"
}),
);
const sky = yield* readLayerSource(repositoryRoot, "nightly", "background.svg");
const background = yield* rasterize("nightly-background", fullBleed(sky), CANVAS);
const background = yield* rasterize("nightly-background", fullBleed(sky), size);
return yield* composite("nightly-background", background, overlays);
});
const renderBackground = Effect.fn("androidIcons.renderBackground")(function* (
repositoryRoot: string,
variant: IconVariant,
size: number,
) {
switch (variant) {
case "dev":
return yield* renderDevelopmentBackground(repositoryRoot, size);
case "nightly":
return yield* renderNightlyBackground(repositoryRoot, size);
case "prod":
return yield* solidCanvas("prod-background", size, PRODUCTION_BACKGROUND_COLOR);
}
});
const renderSplashIcon = Effect.fn("androidIcons.renderSplashIcon")(function* (
repositoryRoot: string,
variant: IconVariant,
) {
const background = yield* renderBackground(repositoryRoot, variant, SPLASH_CANVAS);
const foreground = yield* renderForeground(repositoryRoot, SPLASH_CANVAS);
return yield* composite(`${variant}-splash`, background, [{ input: foreground }]);
});
const exportAndroidIcons = Effect.gen(function* () {
const fs = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const repositoryRoot = path.resolve(import.meta.dirname, "..");
const outputs = [
["android-icon-foreground.png", yield* renderForeground(repositoryRoot)],
["android-icon-background-dev.png", yield* renderDevelopmentBackground(repositoryRoot)],
["android-icon-background-nightly.png", yield* renderNightlyBackground(repositoryRoot)],
["android-icon-foreground.png", yield* renderForeground(repositoryRoot, ADAPTIVE_CANVAS)],
[
"android-icon-background-dev.png",
yield* renderDevelopmentBackground(repositoryRoot, ADAPTIVE_CANVAS),
],
[
"android-icon-background-nightly.png",
yield* renderNightlyBackground(repositoryRoot, ADAPTIVE_CANVAS),
],
["android-splash-icon-dev.png", yield* renderSplashIcon(repositoryRoot, "dev")],
["android-splash-icon-nightly.png", yield* renderSplashIcon(repositoryRoot, "nightly")],
["android-splash-icon-prod.png", yield* renderSplashIcon(repositoryRoot, "prod")],
] as const;
for (const [name, contents] of outputs) {
yield* fs.writeFile(path.join(repositoryRoot, OUTPUT_DIRECTORY, name), contents);