1 // Copyright 2015-present 650 Industries. All rights reserved.
2 package host.exp.exponent.experience
3 
4 import android.content.Intent
5 import android.os.Bundle
6 import com.facebook.react.ReactPackage
7 import com.facebook.react.ReactRootView
8 import expo.modules.adapters.react.ReactModuleRegistryProvider
9 import expo.modules.core.interfaces.Package
10 import expo.modules.core.interfaces.SingletonModule
11 import expo.modules.splashscreen.singletons.SplashScreen
12 import host.exp.exponent.Constants
13 import host.exp.expoview.ExpoViewBuildConfig
14 import versioned.host.exp.exponent.ExponentPackageDelegate
15 import versioned.host.exp.exponent.modules.universal.ExpoModuleRegistryAdapter
16 
17 abstract class DetachActivity : ExperienceActivity(), ExponentPackageDelegate {
18   // Override me!
publishedUrlnull19   abstract fun publishedUrl(): String?
20   abstract fun developmentUrl(): String?
21   abstract override fun reactPackages(): List<ReactPackage>?
22   abstract override fun expoPackages(): List<Package>?
23   abstract val isDebug: Boolean
24 
25   override fun onCreate(savedInstanceState: Bundle?) {
26     ExpoViewBuildConfig.DEBUG = isDebug
27     Constants.INITIAL_URL = if (isDebug) developmentUrl() else publishedUrl()
28     manifestUrl = Constants.INITIAL_URL
29 
30     if (intent.data != null) {
31       intentUri = intent.data.toString()
32     }
33 
34     super.onCreate(savedInstanceState)
35 
36     SplashScreen.show(this, Constants.SPLASH_SCREEN_IMAGE_RESIZE_MODE, ReactRootView::class.java, true)
37 
38     kernel.handleIntent(this, intent)
39   }
40 
onNewIntentnull41   override fun onNewIntent(intent: Intent) {
42     super.onNewIntent(intent)
43     kernel.handleIntent(this, intent)
44   }
45 
46   // TODO: eric: make Constants.INITIAL_URI reliable so we can get rid of this
shouldCheckOptionsnull47   override fun shouldCheckOptions() {
48     if (manifestUrl != null && kernel.hasOptionsForManifestUrl(manifestUrl)) {
49       handleOptions(kernel.popOptionsForManifestUrl(manifestUrl)!!)
50     } else if (isDebug && kernel.hasOptionsForManifestUrl(publishedUrl())) {
51       // also check publishedUrl since this can get set before Constants.INITIAL_URL is set to developmentUrl
52       handleOptions(kernel.popOptionsForManifestUrl(publishedUrl())!!)
53     }
54   }
55 
56   override val exponentPackageDelegate: ExponentPackageDelegate
57     get() = this
58 
getScopedModuleRegistryAdapterForPackagesnull59   override fun getScopedModuleRegistryAdapterForPackages(
60     packages: List<Package>,
61     singletonModules: List<SingletonModule>
62   ): ExpoModuleRegistryAdapter {
63     return DetachedModuleRegistryAdapter(ReactModuleRegistryProvider(packages, singletonModules))
64   }
65 }
66