1import { ExpoConfig } from '@expo/config-types';
2
3export type SplashScreenConfig = {
4  xxxhdpi: string | null;
5  xxhdpi: string | null;
6  xhdpi: string | null;
7  hdpi: string | null;
8  mdpi: string | null;
9  backgroundColor: string | null;
10  resizeMode: 'contain' | 'cover' | 'native';
11};
12
13const defaultResizeMode = 'contain';
14
15export function getAndroidSplashConfig(
16  config: Pick<ExpoConfig, 'splash' | 'android'>
17): SplashScreenConfig | null {
18  // Respect the splash screen object, don't mix and match across different splash screen objects
19  // in case the user wants the top level splash to apply to every platform except android.
20  if (config.android?.splash) {
21    const splash = config.android?.splash;
22    return {
23      xxxhdpi: splash.xxxhdpi ?? splash.image ?? null,
24      xxhdpi: splash.xxhdpi ?? splash.image ?? null,
25      xhdpi: splash.xhdpi ?? splash.image ?? null,
26      hdpi: splash.hdpi ?? splash.image ?? null,
27      mdpi: splash.mdpi ?? splash.image ?? null,
28      backgroundColor: splash.backgroundColor ?? null,
29      resizeMode: splash.resizeMode ?? defaultResizeMode,
30    };
31  }
32
33  if (config.splash) {
34    const splash = config.splash;
35    return {
36      xxxhdpi: splash.image ?? null,
37      xxhdpi: splash.image ?? null,
38      xhdpi: splash.image ?? null,
39      hdpi: splash.image ?? null,
40      mdpi: splash.image ?? null,
41      backgroundColor: splash.backgroundColor ?? null,
42      resizeMode: splash.resizeMode ?? defaultResizeMode,
43    };
44  }
45
46  return null;
47}
48
49export function getAndroidDarkSplashConfig(
50  config: Pick<ExpoConfig, 'splash' | 'android'>
51): SplashScreenConfig | null {
52  // Respect the splash screen object, don't mix and match across different splash screen objects
53  // in case the user wants the top level splash to apply to every platform except android.
54  if (config.android?.splash?.dark) {
55    const splash = config.android?.splash?.dark;
56    const lightTheme = getAndroidSplashConfig(config);
57    return {
58      xxxhdpi: splash.xxxhdpi ?? splash.image ?? null,
59      xxhdpi: splash.xxhdpi ?? splash.image ?? null,
60      xhdpi: splash.xhdpi ?? splash.image ?? null,
61      hdpi: splash.hdpi ?? splash.image ?? null,
62      mdpi: splash.mdpi ?? splash.image ?? null,
63      backgroundColor: splash.backgroundColor ?? null,
64      // Can't support dark resizeMode because the resize mode is hardcoded into the MainActivity.java
65      resizeMode: lightTheme?.resizeMode ?? defaultResizeMode,
66    };
67  }
68
69  return null;
70}
71