@@ -13,6 +13,7 @@ import com.facebook.react.devsupport.DoubleTapReloadRecognizer
1313import com.facebook.react.modules.core.PermissionListener
1414import com.facebook.react.bridge.Callback
1515import com.facebook.react.bridge.ReadableMap
16+ import com.facebook.react.common.DebugServerException
1617import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
1718import com.facebook.react.modules.core.PermissionAwareActivity
1819
@@ -39,10 +40,9 @@ class ReactNativeActivity : ReactActivity(), DefaultHardwareBackBtnHandler, Perm
3940 )
4041
4142 supportActionBar?.hide()
42-
4343 setContentView(reactRootView)
44-
4544 doubleTapReloadRecognizer = DoubleTapReloadRecognizer ()
45+ checkPackagerConnection()
4646 }
4747
4848 override fun onDestroy () {
@@ -145,6 +145,21 @@ class ReactNativeActivity : ReactActivity(), DefaultHardwareBackBtnHandler, Perm
145145 }
146146 }
147147
148+ private fun checkPackagerConnection () {
149+ if (ReactNativeBrownfield .shared.reactNativeHost.hasInstance() && ReactNativeBrownfield .shared.reactNativeHost.useDeveloperSupport) {
150+ val devSupportManager =
151+ ReactNativeBrownfield .shared.reactNativeHost.reactInstanceManager.devSupportManager
152+ val url = devSupportManager.sourceUrl
153+ devSupportManager?.isPackagerRunning { isRunning ->
154+ if (! isRunning) {
155+ val error = Error ()
156+ val message = DebugServerException .makeGeneric(url, " Could not connect to development server." , " URL: $url " , error).message
157+ devSupportManager.showNewJavaError(message, error)
158+ }
159+ }
160+ }
161+ }
162+
148163 companion object {
149164 @JvmStatic
150165 @JvmOverloads
0 commit comments