Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(android): Add packager connection check #26

Merged
merged 1 commit into from
Nov 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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