Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 1 addition & 66 deletions src/project/assets/android/generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { mkdirp, pathExists, writeFile } from '@ionic/utils-fs';
import { dirname, join, relative } from 'path';
import { dirname, join } from 'path';
import type { OutputInfo, Sharp } from 'sharp';
import sharp from 'sharp';

Expand All @@ -14,7 +14,6 @@ import { AssetKind, Platform } from '../asset-types';
import type { InputAsset } from '../input-asset';
import { OutputAsset } from '../output-asset';
import type { MobileProject } from '../../project';
import { Logger } from '../../logger';

import * as AndroidAssetTemplates from './assets';

Expand Down Expand Up @@ -120,70 +119,6 @@ export class AndroidAssetGenerator extends AssetGenerator {
return [...foregroundImages, ...backgroundImages];
}

private async _generateSplashesFromLogo(
project: MobileProject,
asset: InputAsset,
splash: AndroidOutputAssetTemplate,
pipe: Sharp,
backgroundColor: string,
): Promise<OutputAsset> {
// Generate light splash
const resPath = this.getResPath(project);

let drawableDir = `drawable`;
if (splash.density) {
drawableDir = `drawable-${splash.density}`;
}

const parentDir = join(resPath, drawableDir);
if (!(await pathExists(parentDir))) {
await mkdirp(parentDir);
}
const dest = join(resPath, drawableDir, 'splash.png');

const targetLogoWidthPercent = this.options.logoSplashScale ?? 0.2;
let targetWidth = this.options.logoSplashTargetWidth ?? Math.floor((splash.width ?? 0) * targetLogoWidthPercent);

if (targetWidth > splash.width || targetWidth > splash.height) {
targetWidth = Math.floor((splash.width ?? 0) * targetLogoWidthPercent);
}

if (targetWidth > splash.width || targetWidth > splash.height) {
Logger.warn(`Logo dimensions exceed dimensions of splash ${splash.width}x${splash.height}, using default logo size`);
targetWidth = Math.floor((splash.width ?? 0) * 0.2);
}

const canvas = sharp({
create: {
width: splash.width ?? 0,
height: splash.height ?? 0,
channels: 4,
background: backgroundColor,
},
});

const resized = await sharp(asset.path).resize(targetWidth).toBuffer();

const outputInfo = await canvas
.composite([{ input: resized, gravity: sharp.gravity.center }])
.png()
.toFile(dest);

const splashOutput = new OutputAsset(
splash,
asset,
project,
{
[dest]: dest,
},
{
[dest]: outputInfo,
},
);

return splashOutput;
}

private async generateLegacyIcon(asset: InputAsset, project: MobileProject): Promise<OutputAsset[]> {
const icons = Object.values(AndroidAssetTemplates).filter(
(a) => a.kind === AssetKind.Icon,
Expand Down
12 changes: 0 additions & 12 deletions src/project/assets/asset-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,6 @@ export interface AssetGeneratorOptions {
iconBackgroundColor?: string;
// Background color for icon generation for use in dark mode scenarios
iconBackgroundColorDark?: string;
// Background color for light mode splash generation
splashBackgroundColor?: string;
// Background color for dark mode splash generation
splashBackgroundColorDark?: string;
// Path to the web app manifest
pwaManifestPath?: string;
// Whether to fetch latest device sizes from official apple site
pwaNoAppleFetch?: boolean;
// Scale amount for logo when generating splashes. Default: 0.2 (20%)
logoSplashScale?: number;
// Specific width for logo when generating splashes. (not used by default)
logoSplashTargetWidth?: number;
// Android product flavor name where generated assets will be created. Default: main
androidFlavor?: string;
}
70 changes: 0 additions & 70 deletions src/project/assets/asset-types.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
import type { InputAsset } from './input-asset';

export interface Assets {
logo: InputAsset | null;
logoDark: InputAsset | null;
icon: InputAsset | null;
iconForeground: InputAsset | null;
iconBackground: InputAsset | null;
splash: InputAsset | null;
splashDark: InputAsset | null;

iosIcon?: InputAsset | null;
iosSplash?: InputAsset | null;
iosSplashDark?: InputAsset | null;

androidIcon?: InputAsset | null;
androidIconForeground?: InputAsset | null;
androidIconBackground?: InputAsset | null;

androidSplash?: InputAsset | null;
androidSplashDark?: InputAsset | null;
androidNotificationIcon?: InputAsset | null;

pwaIcon?: InputAsset | null;
pwaSplash?: InputAsset | null;
pwaSplashDark?: InputAsset | null;
}

export enum AssetKind {
Logo = 'logo',
LogoDark = 'logo-dark',
AdaptiveIcon = 'adaptive-icon',
Icon = 'icon',
IconForeground = 'icon-foreground',
IconBackground = 'icon-background',
NotificationIcon = 'notification-icon'
}

export enum Platform {
Expand All @@ -50,18 +21,6 @@ export enum Format {
Unknown = 'unknown',
}

export enum Orientation {
Default = '',
Portrait = 'portrait',
Landscape = 'landscape',
}

export enum Theme {
Any = 'any',
Light = 'light',
Dark = 'dark',
}

export enum AndroidDensity {
Default = '',
Ldpi = 'ldpi',
Expand Down Expand Up @@ -126,38 +85,9 @@ export enum IosIdiom {
TV = 'tv',
}

export type IosOutputAssetTemplateIcon = IosOutputAssetTemplate;
export interface IosOutputAssetTemplateSplash extends IosOutputAssetTemplate {
orientation: Orientation;
theme: Theme;
}
export interface PwaOutputAssetTemplate extends OutputAssetTemplate {
name: string;
orientation?: Orientation;
density?: string;
}

export interface AndroidOutputAssetTemplate extends OutputAssetTemplate {
density: AndroidDensity;
}
export interface AndroidOutputAssetTemplateSplash extends OutputAssetTemplate {
density: AndroidDensity;
orientation: Orientation;
}
export interface AndroidOutputAssetTemplateAdaptiveIcon extends OutputAssetTemplate {
density: AndroidDensity;
}

// Shape of the Contents.json file inside of ios app appiconset and imageset folders
export interface IosContents {
images: {
filename: string;
size: string;
scale: string;
idiom: string;
}[];
info?: {
version: number;
author: string;
};
}
4 changes: 0 additions & 4 deletions src/project/assets/ios/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import type { MobileProject } from '../../project';

export const IOS_APP_ICON_SET_NAME = 'AppIcon';
export const IOS_APP_ICON_SET_PATH = `App/Assets.xcassets/${IOS_APP_ICON_SET_NAME}.appiconset`;
// export const IOS_SPLASH_IMAGE_SET_NAME = 'Splash';
// export const IOS_SPLASH_IMAGE_SET_PATH = `App/Assets.xcassets/${IOS_SPLASH_IMAGE_SET_NAME}.imageset`;

export const IOS_1024_ICON: IosOutputAssetTemplate = {
platform: Platform.Ios,
Expand Down Expand Up @@ -59,8 +57,6 @@ export class IosAssetGenerator extends AssetGenerator {
throw new Error('Sharp instance not created');
}

const iosDir = project.config.ios!.path!;

// Generate logos
let logos: OutputAsset[] = [];
if (asset.kind === AssetKind.Logo) {
Expand Down
2 changes: 0 additions & 2 deletions src/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ import { NativeIosFramework } from './frameworks/native-ios';
import { NativeAndroidFramework } from './frameworks/native-android';
import { NativeScriptFramework } from './frameworks/nativescript';
import { Logger } from './logger';
import { Assets } from './assets/asset-types'

export class MobileProject {
public framework: Framework | null = null;
public ios: IosProject | null = null;
public android: AndroidProject | null = null;
vfs: VFS;

assets: Assets | null = null;
directory: string | null = null;
assetDir: string | null = null;

Expand Down
Loading