-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[android][splash-screen] Migrate to new modules API (expo#22827)
- Loading branch information
1 parent
cd1a5cd
commit 2d8d8b6
Showing
14 changed files
with
57 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 26 additions & 45 deletions
71
.../expo-splash-screen/android/src/main/java/expo/modules/splashscreen/SplashScreenModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,42 @@ | ||
package expo.modules.splashscreen | ||
|
||
import android.content.Context | ||
|
||
import expo.modules.core.ExportedModule | ||
import expo.modules.core.ModuleRegistry | ||
import expo.modules.core.Promise | ||
import expo.modules.core.errors.CurrentActivityNotFoundException | ||
import expo.modules.core.interfaces.ActivityProvider | ||
import expo.modules.core.interfaces.ExpoMethod | ||
import expo.modules.kotlin.Promise | ||
import expo.modules.kotlin.exception.Exceptions | ||
import expo.modules.kotlin.modules.Module | ||
import expo.modules.kotlin.modules.ModuleDefinition | ||
import expo.modules.splashscreen.exceptions.HideAsyncException | ||
import expo.modules.splashscreen.exceptions.PreventAutoHideException | ||
|
||
// Below import must be kept unversioned even in versioned code to provide a redirection from | ||
// versioned code realm to unversioned code realm. | ||
// Without this import any `SplashScreen.anyMethodName(...)` invocation on JS side ends up | ||
// in versioned SplashScreen kotlin object that stores no information about the ExperienceActivity. | ||
import expo.modules.splashscreen.singletons.SplashScreen | ||
|
||
class SplashScreenModule(context: Context) : ExportedModule(context) { | ||
companion object { | ||
private const val NAME = "ExpoSplashScreen" | ||
private const val ERROR_TAG = "ERR_SPLASH_SCREEN" | ||
} | ||
|
||
private lateinit var activityProvider: ActivityProvider | ||
|
||
override fun getName(): String { | ||
return NAME | ||
} | ||
class SplashScreenModule : Module() { | ||
override fun definition() = ModuleDefinition { | ||
Name("ExpoSplashScreen") | ||
|
||
override fun onCreate(moduleRegistry: ModuleRegistry) { | ||
activityProvider = moduleRegistry.getModule(ActivityProvider::class.java) | ||
} | ||
AsyncFunction("preventAutoHideAsync") { promise: Promise -> | ||
val currentActivity = | ||
appContext.currentActivity ?: throw Exceptions.MissingActivity() | ||
|
||
@ExpoMethod | ||
fun preventAutoHideAsync(promise: Promise) { | ||
val activity = activityProvider.currentActivity | ||
if (activity == null) { | ||
promise.reject(CurrentActivityNotFoundException()) | ||
return | ||
SplashScreen.preventAutoHide( | ||
currentActivity, | ||
{ hasEffect -> promise.resolve(hasEffect) }, | ||
{ m -> promise.reject(PreventAutoHideException(m)) } | ||
) | ||
} | ||
SplashScreen.preventAutoHide( | ||
activity, | ||
{ hasEffect -> promise.resolve(hasEffect) }, | ||
{ m -> promise.reject(ERROR_TAG, m) } | ||
) | ||
} | ||
|
||
@ExpoMethod | ||
fun hideAsync(promise: Promise) { | ||
val activity = activityProvider.currentActivity | ||
if (activity == null) { | ||
promise.reject(CurrentActivityNotFoundException()) | ||
return | ||
AsyncFunction("hideAsync") { promise: Promise -> | ||
val currentActivity = | ||
appContext.currentActivity ?: throw Exceptions.MissingActivity() | ||
|
||
SplashScreen.hide( | ||
currentActivity, | ||
{ hasEffect -> promise.resolve(hasEffect) }, | ||
{ m -> promise.reject(HideAsyncException(m)) } | ||
) | ||
} | ||
SplashScreen.hide( | ||
activity, | ||
{ hasEffect -> promise.resolve(hasEffect) }, | ||
{ m -> promise.reject(ERROR_TAG, m) } | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
...reen/android/src/main/java/expo/modules/splashscreen/exceptions/NoContentViewException.kt
This file was deleted.
Oops, something went wrong.
12 changes: 12 additions & 0 deletions
12
...reen/android/src/main/java/expo/modules/splashscreen/exceptions/SplashScreenExceptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package expo.modules.splashscreen.exceptions | ||
|
||
import expo.modules.kotlin.exception.CodedException | ||
|
||
class NoContentViewException : | ||
CodedException("ContentView is not yet available. Call 'SplashScreen.show(...)' once 'setContentView()' is called.") | ||
|
||
class PreventAutoHideException(message: String) : | ||
CodedException(message) | ||
|
||
class HideAsyncException(message: String) : | ||
CodedException(message) |
7 changes: 0 additions & 7 deletions
7
...creen/android/src/main/java/expo/modules/splashscreen/singletons/SplashScreenStatusBar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "expo-splash-screen", | ||
"platforms": ["ios", "android"], | ||
"android": { | ||
"modules": ["expo.modules.splashscreen.SplashScreenModule"] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
import { NativeModulesProxy } from 'expo-modules-core'; | ||
|
||
export default NativeModulesProxy.ExpoSplashScreen || {}; | ||
import { requireNativeModule } from 'expo-modules-core'; | ||
export default requireNativeModule('ExpoSplashScreen') || {}; |
This file was deleted.
Oops, something went wrong.