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): idling resource refactoring #4663

Merged
merged 18 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
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,7 +13,7 @@
import com.facebook.react.ReactApplication;
import com.wix.detox.common.UIThread;
import com.wix.detox.reactnative.ReactNativeExtension;
import com.wix.detox.reactnative.idlingresources.NetworkIdlingResource;
import com.wix.detox.reactnative.idlingresources.network.NetworkIdlingResource;

import org.hamcrest.Matcher;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.facebook.react.ReactApplication
import com.facebook.react.ReactInstanceManager
import com.facebook.react.bridge.ReactContext
import com.wix.detox.LaunchArgs
import com.wix.detox.reactnative.idlingresources.ReactNativeIdlingResources

private const val LOG_TAG = "DetoxRNExt"

Expand Down Expand Up @@ -56,15 +57,14 @@ object ReactNativeExtension {
Log.i(LOG_TAG, "Reloading React Native")

(applicationContext as ReactApplication).let {
val networkSyncEnabled = rnIdlingResources?.networkSyncEnabled ?: true
clearIdlingResources()

val previousReactContext = getCurrentReactContextSafe(it)

reloadReactNativeInBackground(it)
val reactContext = awaitNewReactNativeContext(it, previousReactContext)

enableOrDisableSynchronization(reactContext, networkSyncEnabled)
enableOrDisableSynchronization(reactContext)
}
}

Expand Down Expand Up @@ -93,11 +93,6 @@ object ReactNativeExtension {
return null
}

@JvmStatic
fun setNetworkSynchronization(enable: Boolean) {
rnIdlingResources?.setNetworkSynchronization(enable)
}

@JvmStatic
fun toggleNetworkSynchronization(enable: Boolean) {
rnIdlingResources?.let {
Expand Down Expand Up @@ -129,11 +124,11 @@ object ReactNativeExtension {
return rnLoadingMonitor.getNewContext()!!
}

private fun enableOrDisableSynchronization(reactContext: ReactContext, networkSyncEnabled: Boolean = true) {
private fun enableOrDisableSynchronization(reactContext: ReactContext) {
if (shouldDisableSynchronization()) {
clearAllSynchronization()
} else {
setupIdlingResources(reactContext, networkSyncEnabled)
setupIdlingResources(reactContext)
}
}

Expand All @@ -142,10 +137,10 @@ object ReactNativeExtension {
return launchArgs.hasEnableSynchronization() && launchArgs.enableSynchronization.equals("0")
}

private fun setupIdlingResources(reactContext: ReactContext, networkSyncEnabled: Boolean = true) {
private fun setupIdlingResources(reactContext: ReactContext) {
val launchArgs = LaunchArgs()

rnIdlingResources = ReactNativeIdlingResources(reactContext, launchArgs, networkSyncEnabled).apply {
rnIdlingResources = ReactNativeIdlingResources(reactContext, launchArgs).apply {
registerAll()
}
}
Expand Down

This file was deleted.

Loading
Loading