Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

[configure-splash-screen] Refactor and integrate with @expo/config #2297

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
86fddc0
[configure-splash-screen] feat: move utils from ./helpers to ./utils
bbarthec Jun 22, 2020
0172fa0
[configure-splash-screen] fix: make one pbxproj propoerty opional
bbarthec Jun 22, 2020
7ba4a37
[configure-splash-screen] feat: clean-up js constants
bbarthec Jun 22, 2020
987a354
[configure-splash-screen] feat: create types.ts with SplashScreenConf…
bbarthec Jun 22, 2020
75f35f1
[configure-splash-screen] feat: create Validator for ConfigJson
bbarthec Jun 22, 2020
ba09414
[configure-splash-screen] feat: create external API
bbarthec Jun 22, 2020
aa090b5
[configure-splash-screen] feat: update CLI command and package.json w…
bbarthec Jun 22, 2020
bd8474e
[configure-splash-screen] feat: update and write missing tests
bbarthec Jun 22, 2020
3e15875
[config] feat: add configure-splash-screen and remove warning
bbarthec Jun 22, 2020
4ba291f
[config] fix: rebase with master
bbarthec Jun 22, 2020
755420d
[configure-splash-screen] Simplify config validator & adjust PR sugge…
bbarthec Sep 4, 2020
8481c9c
[configure-splash-screen] Rename imagePath into image in internally &…
bbarthec Sep 4, 2020
cc77d1c
[configure-splash-screen] Remove TODO comment, because it's already done
bbarthec Sep 4, 2020
560d054
Merge branch 'master' into @bbarthec/configure-splash-screen-integrat…
EvanBacon Sep 10, 2020
8abf170
Merge branch 'master' into @bbarthec/configure-splash-screen-integrat…
EvanBacon Sep 10, 2020
d8f539a
Merge branch 'master' into @bbarthec/configure-splash-screen-integrat…
EvanBacon Sep 16, 2020
2b63608
[splash-screen] Fix config not being applied
bbarthec Sep 17, 2020
c94dcb5
Merge branch 'master' into @bbarthec/configure-splash-screen-integrat…
brentvatne Sep 18, 2020
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
1 change: 1 addition & 0 deletions packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"@expo/config-types": "^39.0.0",
"@expo/image-utils": "0.3.6",
"@expo/json-file": "8.2.23",
"@expo/configure-splash-screen": "~0.1.11",
"@expo/plist": "0.0.10",
"fs-extra": "9.0.0",
"glob": "7.1.6",
Expand Down
46 changes: 34 additions & 12 deletions packages/config/src/android/SplashScreen.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
import {
AndroidSplashScreenConfig,
SplashScreenImageResizeMode,
configureAndroidSplashScreen,
} from '@expo/configure-splash-screen';

import { ExpoConfig } from '../Config.types';
import { addWarningAndroid } from '../WarningAggregator';

export function getSplashScreen(config: ExpoConfig) {
if (config.splash?.image || config.android?.splash?.mdpi) {
return true;
} else {
return false;
export function getSplashScreenConfig(config: ExpoConfig): AndroidSplashScreenConfig | undefined {
if (!config.splash && !config.android?.splash) {
return;
}

const result: AndroidSplashScreenConfig = {
imageResizeMode:
config.android?.splash?.resizeMode ??
config.splash?.resizeMode ??
SplashScreenImageResizeMode.CONTAIN,
backgroundColor:
config.android?.splash?.backgroundColor ?? config.splash?.backgroundColor ?? '#FFFFFF', // white
image:
config.android?.splash?.xxxhdpi ??
config.android?.splash?.xxhdpi ??
config.android?.splash?.xhdpi ??
config.android?.splash?.hdpi ??
config.android?.splash?.mdpi ??
config.splash?.image,
};

return result;
}

export async function setSplashScreenAsync(config: ExpoConfig, projectRoot: string) {
const splash = getSplashScreen(config);
if (!splash) {
const splashConfig = getSplashScreenConfig(config);
if (!splashConfig) {
return;
}

addWarningAndroid(
'splash',
'This is the image that your app uses on the loading screen, we recommend installing and using expo-splash-screen.',
'https://github.com/expo/expo/blob/master/packages/expo-splash-screen/README.md'
);
try {
await configureAndroidSplashScreen(projectRoot, splashConfig);
} catch (e) {
addWarningAndroid('splash', e);
}
}
44 changes: 30 additions & 14 deletions packages/config/src/ios/SplashScreen.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,39 @@
import {
configureIosSplashScreen,
IosSplashScreenConfig,
SplashScreenImageResizeMode,
} from '@expo/configure-splash-screen';

import { ExpoConfig } from '../Config.types';
import { addWarningIOS } from '../WarningAggregator';

export function getSplashScreen(config: ExpoConfig) {
if (config.splash || config.ios?.splash) {
return true;
} else {
return false;
export function getSplashScreen(config: ExpoConfig): IosSplashScreenConfig | undefined {
if (!config.splash && !config.ios?.splash) {
return;
}

const result: IosSplashScreenConfig = {
imageResizeMode:
config.ios?.splash?.resizeMode ??
config.splash?.resizeMode ??
SplashScreenImageResizeMode.CONTAIN,
backgroundColor:
config.ios?.splash?.backgroundColor ?? config.splash?.backgroundColor ?? '#FFFFFF', // white
image: config.ios?.splash?.image ?? config.splash?.image,
};

return result;
}

export function setSplashScreenAsync(config: ExpoConfig, projectRoot: string) {
const splash = getSplashScreen(config);
if (!splash) {
export async function setSplashScreenAsync(config: ExpoConfig, projectRoot: string) {
const splashConfig = getSplashScreen(config);

if (!splashConfig) {
return;
}

addWarningIOS(
'splash',
'This is the image that your app uses on the loading screen, we recommend installing and using expo-splash-screen.',
'https://github.com/expo/expo/blob/master/packages/expo-splash-screen/README.md'
);
try {
await configureIosSplashScreen(projectRoot, splashConfig);
} catch (e) {
addWarningIOS('splash', e);
}
}
10 changes: 7 additions & 3 deletions packages/configure-splash-screen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
"version": "0.1.16",
"description": "Supplementary module for 'expo-splash-screen' providing cli configuration command",
"bin": {
"configure-splash-screen": "./build/configure.js",
"expo-splash-screen": "./build/configure.js"
"configure-splash-screen": "./build/index-cli.js",
"expo-splash-screen": "./build/index-cli.js"
},
"main": "./build/index.js",
"scripts": {
"start": "yarn run prepare",
"build": "tsc",
Expand Down Expand Up @@ -44,6 +45,7 @@
"core-js": "^3.6.5",
"deep-equal": "^2.0.3",
"fs-extra": "^9.0.0",
"lodash": "^4.17.15",
"pngjs": "^5.0.0",
"xcode": "^3.0.0",
"xml-js": "^1.6.11"
Expand All @@ -57,8 +59,10 @@
"@types/color-string": "^1.5.0",
"@types/deep-equal": "^1.0.1",
"@types/fs-extra": "^9.0.1",
"@types/jest": "^26.0.8",
"@types/jest": "^25.2.2",
"@types/lodash": "^4.14.155",
"babel-jest": "^26.2.2",
"conditional-type-checks": "^1.0.5",
"eslint": "^6.8.0",
"jest": "^26.2.2",
"memfs": "^3.1.2",
Expand Down
95 changes: 95 additions & 0 deletions packages/configure-splash-screen/src/SplashScreenConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { Color } from 'color-string';

import { SplashScreenImageResizeModeType, SplashScreenStatusBarStyleType } from './constants';

/**
* iOS SplashScreen config.
*/
export type IosSplashScreenConfig = {
backgroundColor: Color;

image?: string;
imageResizeMode?: SplashScreenImageResizeModeType;

statusBar?: {
hidden?: boolean;
style?: SplashScreenStatusBarStyleType;
};

darkMode?: {
backgroundColor?: Color;
image?: string;
};
};

/**
* Android SplashScreen config.
*/
export type AndroidSplashScreenConfig = {
backgroundColor: Color;

image?: string;
imageResizeMode?: SplashScreenImageResizeModeType;

statusBar?: {
hidden?: boolean;
style?: SplashScreenStatusBarStyleType;
translucent?: boolean;
backgroundColor?: Color;
};

darkMode?: {
backgroundColor?: Color;
image?: string;
statusBar?: {
style?: SplashScreenStatusBarStyleType;
backgroundColor?: Color;
};
};
};

/**
* The very same as `IosSplashScreenConfig`, but JSON-friendly (values for each property are JavaScript built-in types).
*/
export type IosSplashScreenConfigJSON = {
backgroundColor: string;

image?: string;
imageResizeMode?: string;

statusBar?: {
hidden?: boolean;
style?: string;
};

darkMode?: {
backgroundColor?: string;
image?: string;
};
};

/**
* The very same as `IosSplashScreenConfig`, but JSON-friendly (values for each property are JavaScript built-in types).
*/
export type AndroidSplashScreenConfigJSON = {
backgroundColor: string;

image?: string;
imageResizeMode?: string;

statusBar?: {
hidden?: boolean;
style?: string;
translucent?: boolean;
backgroundColor?: string;
};

darkMode?: {
backgroundColor?: string;
image?: string;
statusBar?: {
style?: string;
backgroundColor?: string;
};
};
};
138 changes: 138 additions & 0 deletions packages/configure-splash-screen/src/__tests__/cli-command.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import configureAndroid from '../android';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rename all of these tests to -test after this PR is merged. #2591

import createCommand from '../cli-command';
import configureIos from '../ios';

jest.mock('../ios', () => ({
__esModule: true,
default: jest.fn(),
}));
jest.mock('../android', () => ({
__esModule: true,
default: jest.fn(),
}));

describe('cli-command', () => {
describe('successful scenarios', () => {
it('basic scenario', async () => {
await createCommand().parseAsync(['--background-color', 'rgba(10, 20, 30, 0.2)'], {
from: 'user',
});
expect(configureIos).toHaveBeenLastCalledWith(expect.anything(), {
backgroundColor: 'rgba(10, 20, 30, 0.2)',
darkMode: {
backgroundColor: undefined,
image: undefined,
},
image: undefined,
imageResizeMode: undefined,
statusBar: {
hidden: undefined,
style: undefined,
},
});
expect(configureAndroid).toHaveBeenLastCalledWith(expect.anything(), {
backgroundColor: 'rgba(10, 20, 30, 0.2)',
darkMode: {
backgroundColor: undefined,
image: undefined,
statusBar: {
backgroundColor: undefined,
style: undefined,
},
},
image: undefined,
imageResizeMode: undefined,
statusBar: {
hidden: undefined,
style: undefined,
},
});
});

it('all available parameters', async () => {
/* eslint-disable prettier/prettier */
await createCommand().parseAsync(
[
'--background-color',
'rgba(10, 20, 30, 0.2)',
'--image-path',
'./assets/background.png',
'--image-resize-mode',
'contain',
'--dark-mode-background-color',
'yellow',
'--dark-mode-image-path',
'./assets/background-dark.png',
'--status-bar-style',
'dark-content',
'--status-bar-hidden',
'--status-bar-translucent',
'--status-bar-background-color',
'#FFEECCDD',
'--dark-mode-status-bar-background-color',
'red',
'--dark-mode-status-bar-style',
'light-content',
],
{
from: 'user',
}
);
/* eslint-enable */
expect(configureIos).toHaveBeenLastCalledWith(expect.anything(), {
backgroundColor: 'rgba(10, 20, 30, 0.2)',
image: './assets/background.png',
imageResizeMode: 'contain',
darkMode: {
backgroundColor: 'yellow',
image: './assets/background-dark.png',
},
statusBar: {
hidden: true,
style: 'dark-content',
},
});
expect(configureAndroid).toHaveBeenLastCalledWith(expect.anything(), {
backgroundColor: 'rgba(10, 20, 30, 0.2)',
image: './assets/background.png',
imageResizeMode: 'contain',
darkMode: {
backgroundColor: 'yellow',
image: './assets/background-dark.png',
statusBar: {
backgroundColor: 'red',
style: 'light-content',
},
},
statusBar: {
backgroundColor: '#FFEECCDD',
hidden: true,
style: 'dark-content',
translucent: true,
},
});
});
});

describe('rejecting scenarios', () => {
it('reject upon wrong platform', async () => {
await expect(async () => {
await createCommand().parseAsync(['--platform', 'what?'], { from: 'user' });
}).rejects.toThrowError(
new Error(
`'platform': Invalid value 'what?'. Available values are "android" | "ios" | "all".`
)
);
});

it('reject upon missing backgroundColor', async () => {
await expect(async () => {
await createCommand().parseAsync(['--platform', 'all'], { from: 'user' });
}).rejects.toThrowError(
new Error(
`'backgroundColor': Required option is not provided. Provide a valid color string.`
)
);
});
});
});
Loading