Skip to content

Commit

Permalink
feat(android): add packager connection check (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof Borowy authored and michalchudziak committed Nov 19, 2019
1 parent 2aecb60 commit b39e8a0
Showing 1 changed file with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import com.facebook.react.devsupport.DoubleTapReloadRecognizer
import com.facebook.react.modules.core.PermissionListener
import com.facebook.react.bridge.Callback
import com.facebook.react.bridge.ReadableMap
import com.facebook.react.common.DebugServerException
import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler
import com.facebook.react.modules.core.PermissionAwareActivity

Expand All @@ -39,10 +40,9 @@ class ReactNativeActivity : ReactActivity(), DefaultHardwareBackBtnHandler, Perm
)

supportActionBar?.hide()

setContentView(reactRootView)

doubleTapReloadRecognizer = DoubleTapReloadRecognizer()
checkPackagerConnection()
}

override fun onDestroy() {
Expand Down Expand Up @@ -145,6 +145,21 @@ class ReactNativeActivity : ReactActivity(), DefaultHardwareBackBtnHandler, Perm
}
}

private fun checkPackagerConnection() {
if (ReactNativeBrownfield.shared.reactNativeHost.hasInstance() && ReactNativeBrownfield.shared.reactNativeHost.useDeveloperSupport) {
val devSupportManager =
ReactNativeBrownfield.shared.reactNativeHost.reactInstanceManager.devSupportManager
val url = devSupportManager.sourceUrl
devSupportManager?.isPackagerRunning { isRunning ->
if (!isRunning) {
val error = Error()
val message = DebugServerException.makeGeneric(url, "Could not connect to development server.", "URL: $url", error).message
devSupportManager.showNewJavaError(message, error)
}
}
}
}

companion object {
@JvmStatic
@JvmOverloads
Expand Down

0 comments on commit b39e8a0

Please sign in to comment.