@@ -9,11 +9,7 @@ import com.facebook.react.animated.NativeAnimatedNodesManager
99import com.facebook.react.bridge.ReactContext
1010import com.wix.detox.common.DetoxErrors
1111import com.wix.detox.common.DetoxLog.Companion.LOG_TAG
12- import com.wix.detox.common.KotlinReflectUtils
13- import com.wix.detox.reactnative.ReactNativeInfo
1412import com.wix.detox.reactnative.idlingresources.DetoxIdlingResource
15- import kotlin.reflect.full.memberProperties
16- import kotlin.reflect.jvm.isAccessible
1713
1814class AnimatedModuleIdlingResource (private val reactContext : ReactContext ) : DetoxIdlingResource(),
1915 Choreographer .FrameCallback {
@@ -31,8 +27,7 @@ class AnimatedModuleIdlingResource(private val reactContext: ReactContext) : Det
3127 return false
3228 }
3329
34- if (animatedModule.hasQueuedAnimations() ||
35- animatedModule.hasActiveAnimations()) {
30+ if (animatedModule.hasActiveAnimations()) {
3631 Choreographer .getInstance().postFrameCallback(this )
3732 return false
3833 }
@@ -56,7 +51,7 @@ class AnimatedModuleIdlingResource(private val reactContext: ReactContext) : Det
5651 }
5752
5853 private fun getAnimatedModule (): AnimatedModuleFacade ? =
59- if (animatedModule != null ) {
54+ if (animatedModule != null ) {
6055 animatedModule
6156 } else {
6257 reactContext.getNativeModule(NativeAnimatedModule ::class .java)?.let {
@@ -68,50 +63,11 @@ class AnimatedModuleIdlingResource(private val reactContext: ReactContext) : Det
6863}
6964
7065private class AnimatedModuleFacade (private val animatedModule : NativeAnimatedModule ) {
71- private val operationsQueue: OperationsQueueReflected
72- private val preOperationsQueue: OperationsQueueReflected
73- private val nodesManager: NativeAnimatedNodesManager
74-
75- init {
76- val operationsQueueName = if (ReactNativeInfo .rnVersion().minor > 79 ) " operations" else " mOperations"
77- val preOperationsQueueName = if (ReactNativeInfo .rnVersion().minor > 79 ) " preOperations" else " mPreOperations"
78-
79-
80- operationsQueue = (NativeAnimatedModule ::class .memberProperties.find { it.name == operationsQueueName } ? :
81- throw DetoxErrors .DetoxIllegalStateException (" $operationsQueueName property cannot be accessed" )).let {
82-
83- it.isAccessible = true
84- OperationsQueueReflected (it.get(animatedModule) as Any )
85- }
86-
87- preOperationsQueue = (NativeAnimatedModule ::class .memberProperties.find { it.name == preOperationsQueueName } ? :
88- throw DetoxErrors .DetoxIllegalStateException (" $preOperationsQueueName property cannot be accessed" )).let {
89-
90- it.isAccessible = true
91- OperationsQueueReflected (it.get(animatedModule) as Any )
92- }
93-
94- nodesManager = animatedModule.nodesManager ? :
95- throw DetoxErrors .DetoxIllegalStateException (" AnimatedModule exists but nodesManager is null" )
96- }
97-
98- @UiThread
99- fun hasQueuedAnimations (): Boolean =
100- ! preOperationsQueue.isEmpty() ||
101- ! operationsQueue.isEmpty()
66+ private val nodesManager: NativeAnimatedNodesManager = animatedModule.nodesManager
67+ ? : throw DetoxErrors .DetoxIllegalStateException (" AnimatedModule exists but nodesManager is null" )
10268
10369 @UiThread
10470 fun hasActiveAnimations (): Boolean {
10571 return nodesManager.hasActiveAnimations()
10672 }
10773}
108-
109- class OperationsQueueReflected (private val operationsQueue : Any ) {
110- fun isEmpty (): Boolean {
111- KotlinReflectUtils .getPropertyValueWithCustomGetter<Boolean >(operationsQueue, " isEmpty" )?.let {
112- return it
113- }
114-
115- throw DetoxErrors .DetoxIllegalStateException (" isEmpty method/property cannot be reached" )
116- }
117- }
0 commit comments