<lambda>null1 package host.exp.exponent.experience.splashscreen
2 
3 import android.app.Activity
4 import android.content.Intent
5 import android.net.Uri
6 import android.os.Handler
7 import android.view.View
8 import android.view.ViewGroup
9 import com.google.android.material.snackbar.Snackbar
10 import expo.modules.splashscreen.BuildConfig
11 import expo.modules.splashscreen.SplashScreenViewController
12 
13 class ManagedAppSplashScreenViewController(
14   activity: Activity,
15   rootView: Class<out ViewGroup>,
16   private val splashScreenView: View
17 ) : SplashScreenViewController(activity, rootView, splashScreenView) {
18   private val mWarningHandler = Handler()
19   private var mSnackbar: Snackbar? = null
20   private var mRunnable: Runnable? = null
21 
22   fun startSplashScreenWarningTimer() {
23     if (BuildConfig.DEBUG) {
24       mRunnable = Runnable {
25         // this runnable is being executed after the parent view has been destroyed, causing a crash
26         // an easy way to trigger this is to toggle the debug JS option in the dev menu
27         // this causes the whole app to remount, I suspect this is why the timer isn't cleaned up
28         // TODO: cancel runnable when app is unmounted / reloaded
29         if (splashScreenView?.parent != null) {
30           mSnackbar = Snackbar.make(splashScreenView, "Stuck on splash screen?", Snackbar.LENGTH_LONG)
31           mSnackbar!!.setAction(
32             "Info",
33             View.OnClickListener { v ->
34               val url = "https://expo.fyi/splash-screen-hanging"
35               val webpage = Uri.parse(url)
36               val intent = Intent(Intent.ACTION_VIEW, webpage)
37               v.context.startActivity(intent)
38               mSnackbar!!.dismiss()
39             }
40           )
41           mSnackbar!!.show()
42         }
43       }
44 
45       mWarningHandler.postDelayed(mRunnable!!, 20000)
46     }
47   }
48 
49   override fun showSplashScreen(successCallback: () -> Unit) {
50     super.showSplashScreen {
51       successCallback()
52     }
53   }
54 
55   override fun hideSplashScreen(successCallback: (hasEffect: Boolean) -> Unit, failureCallback: (reason: String) -> Unit) {
56     super.hideSplashScreen(
57       {
58         mRunnable?.let { it1 -> mWarningHandler.removeCallbacks(it1) }
59         successCallback(it)
60       },
61       failureCallback
62     )
63   }
64 }
65