Skip to content

Commit

Permalink
Merge pull request #4663 from wix/feat/4175-idling-resource-refactoring
Browse files Browse the repository at this point in the history
feat(android): idling resource refactoring
  • Loading branch information
gosha212 authored Dec 24, 2024
2 parents d04cfef + c0e1723 commit 9272553
Show file tree
Hide file tree
Showing 34 changed files with 1,074 additions and 1,390 deletions.
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

0 comments on commit 9272553

Please sign in to comment.