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","sourcesContent":["import fs from 'fs-extra';\n\nimport { SplashScreenImageResizeMode, SplashScreenImageResizeModeType } from '../constants';\nimport StateManager from '../utils/StateManager';\nimport { insert, replace } from '../utils/string-utils';\nimport { getMainActivityAsync } from './Paths';\n\n/**\n * Injects specific code to MainActivity that would trigger SplashScreen mounting process.\n */\nexport default async function configureMainActivity(\n projectRootPath: string,\n config: {\n imageResizeMode?: SplashScreenImageResizeModeType;\n statusBar?: {\n translucent?: boolean;\n };\n } = {}\n) {\n const resizeMode = config.imageResizeMode ?? SplashScreenImageResizeMode.CONTAIN;\n const statusBarTranslucent: boolean = config.statusBar?.translucent ?? false;\n\n // eslint-disable-next-line\n const mainActivity = await getMainActivityAsync(projectRootPath);\n\n if (!mainActivity) {\n throw new Error(`Failed to configure 'MainActivity'.`);\n }\n\n const isJava = mainActivity.language === 'java';\n const isKotlin = mainActivity.language === 'kt';\n\n const LE = isJava ? ';' : '';\n\n const { state: newFileContent } = new StateManager(mainActivity.contents)\n // importing ReactRootView\n .applyAction(content => {\n const [succeeded, newContent] = replace(content, {\n replacePattern: /^import com\\.facebook\\.react\\.ReactRootView.*?$/m,\n replaceContent: `import com.facebook.react.ReactRootView${LE}`,\n });\n return [newContent, 'replacedReactRootViewImports', succeeded];\n })\n .applyAction((content, { replacedReactRootViewImports }) => {\n if (replacedReactRootViewImports) {\n return [content, 'insertedReactRootViewImports', false];\n }\n const [succeeded, newContent] = insert(content, {\n insertPattern: isJava ? /(?=public class .* extends .* {.*$)/m : /(?=class .* : .* {.*$)/m,\n insertContent: `import com.facebook.react.ReactRootView${LE}\n\n`,\n });\n\n return [newContent, 'insertedReactRootViewImports', succeeded];\n })\n // importing SplashScreen\n .applyAction(content => {\n const [succeeded, newContent] = replace(content, {\n replacePattern: /^import expo\\.modules\\.splashscreen\\..*?SplashScreen.*?\\nimport expo\\.modules\\.splashscreen\\.SplashScreenImageResizeMode.*?$/m,\n replaceContent: `import expo.modules.splashscreen.singletons.SplashScreen${LE}\nimport expo.modules.splashscreen.SplashScreenImageResizeMode${LE}`,\n });\n return [newContent, 'replacedSplashImports', succeeded];\n })\n .applyAction((content, { replacedSplashImports }) => {\n if (replacedSplashImports) {\n return [content, 'insertedSplashImports', false];\n }\n const [succeeded, newContent] = insert(content, {\n insertPattern: isJava ? /(?=public class .* extends .* {.*$)/m : /(?=class .* : .* {.*$)/m,\n insertContent: `import expo.modules.splashscreen.singletons.SplashScreen${LE}\nimport expo.modules.splashscreen.SplashScreenImageResizeMode${LE}\n\n`,\n });\n return [newContent, 'insertedSplashImports', succeeded];\n })\n // registering SplashScreen in onCreate()\n .applyAction(content => {\n const [succeeded, newContent] = replace(content, {\n replacePattern: /(?<=super\\.onCreate(.|\\n)*?)SplashScreen\\.show\\(this, SplashScreenImageResizeMode\\..*\\).*$/m,\n replaceContent: `SplashScreen.show(this, SplashScreenImageResizeMode.${resizeMode.toUpperCase()}, ReactRootView${\n isKotlin ? '::class.java' : '.class'\n }, ${statusBarTranslucent})${LE}`,\n });\n return [newContent, 'replacedInOnCreate', succeeded];\n })\n .applyAction((content, { replacedInOnCreate }) => {\n if (replacedInOnCreate) {\n return [content, 'insertedInOnCreate', false];\n }\n const [succeeded, newContent] = insert(content, {\n insertPattern: /(?<=^.*super\\.onCreate.*$)/m, // insert just below super.onCreate\n insertContent: `\n // SplashScreen.show(...) has to be called after super.onCreate(...)\n // Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually\n SplashScreen.show(this, SplashScreenImageResizeMode.${resizeMode.toUpperCase()}, ReactRootView${\n isKotlin ? '::class.java' : '.class'\n }, ${statusBarTranslucent})${LE}`,\n });\n return [newContent, 'insertedInOnCreate', succeeded];\n })\n // inserting basic onCreate()\n .applyAction((content, { replacedInOnCreate, insertedInOnCreate }) => {\n if (replacedInOnCreate || insertedInOnCreate) {\n return [content, 'insertedOnCreate', false];\n }\n const [succeeded, newContent] = insert(content, {\n insertPattern: isJava\n ? /(?<=public class .* extends .* {.*$)/m\n : /(?<=class .* : .* {.*$)/m,\n insertContent: `\n ${\n isJava\n ? `@Override\n protected void onCreate(Bundle savedInstanceState`\n : 'override fun onCreate(savedInstanceState: Bundle?'\n }) {\n super.onCreate(savedInstanceState)${LE}\n // SplashScreen.show(...) has to be called after super.onCreate(...)\n // Below line is handled by '@expo/configure-splash-screen' command and it's discouraged to modify it manually\n SplashScreen.show(this, SplashScreenImageResizeMode.${resizeMode.toUpperCase()}, ReactRootView${\n isKotlin ? '::class.java' : '.class'\n }, ${statusBarTranslucent})${LE}\n }\n`,\n });\n return [newContent, 'insertedOnCreate', succeeded];\n })\n // importing Bundle\n .applyAction((content, { replacedInOnCreate, insertedInOnCreate }) => {\n if (replacedInOnCreate || insertedInOnCreate) {\n return [content, 'replacedBundleImport', false];\n }\n const [succeeded, newContent] = replace(content, {\n replacePattern: /import android\\.os\\.Bundle/m,\n replaceContent: 'import android.os.Bundle',\n });\n return [newContent, 'replacedBundleImport', succeeded];\n })\n .applyAction((content, { replacedInOnCreate, insertedInOnCreate }) => {\n if (replacedInOnCreate || insertedInOnCreate) {\n return [content, 'insertedBundleImport', false];\n }\n const [succeeded, newContent] = insert(content, {\n insertPattern: /(?<=(^.*?package .*?$))/m,\n insertContent: `\\n\\nimport android.os.Bundle${LE}`,\n });\n return [newContent, 'insertedBundleImport', succeeded];\n });\n\n await fs.writeFile(mainActivity.path, newFileContent);\n}\n"]}