diff --git a/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt b/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt index 9e81005ddf..3fce8ec8cf 100644 --- a/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt +++ b/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt @@ -4,6 +4,8 @@ import com.facebook.react.bridge.ReactContext import com.facebook.react.uimanager.events.Event class ReanimatedEventDispatcher { + @Suppress("UNUSED_PARAMETER", "COMMENT_IN_SUPPRESSION") + // This is necessary on new architecture fun >sendEvent(event: T, reactApplicationContext: ReactContext) { // no-op } diff --git a/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt b/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt index bf97d183a9..e3ad6a6117 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt @@ -60,7 +60,7 @@ class RNGestureHandlerPackage : TurboReactPackage(), ViewManagerOnDemandReactPac try { val reactModuleInfoProviderClass = Class.forName("com.swmansion.gesturehandler.RNGestureHandlerPackage$\$ReactModuleInfoProvider") - return reactModuleInfoProviderClass.newInstance() as ReactModuleInfoProvider + return reactModuleInfoProviderClass.getDeclaredConstructor().newInstance() as ReactModuleInfoProvider } catch (e: ClassNotFoundException) { return ReactModuleInfoProvider { val reactModule: ReactModule = RNGestureHandlerModule::class.java.getAnnotation(ReactModule::class.java)!! @@ -71,7 +71,7 @@ class RNGestureHandlerPackage : TurboReactPackage(), ViewManagerOnDemandReactPac RNGestureHandlerModule::class.java.name, reactModule.canOverrideExistingModule, reactModule.needsEagerInit, - reactModule.hasConstants, + true, // Has constants is hardcoded to return true, so replacing it with `true` changes nothing. reactModule.isCxxModule, true ) diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt b/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt index 6004870fa3..4e4e2232d9 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt @@ -835,15 +835,15 @@ open class GestureHandler private lateinit var pointerCoords: Array private fun initPointerProps(size: Int) { - var size = size + var pointerPropsSize = size if (!Companion::pointerProps.isInitialized) { pointerProps = arrayOfNulls(MAX_POINTERS_COUNT) pointerCoords = arrayOfNulls(MAX_POINTERS_COUNT) } - while (size > 0 && pointerProps[size - 1] == null) { - pointerProps[size - 1] = PointerProperties() - pointerCoords[size - 1] = PointerCoords() - size-- + while (pointerPropsSize > 0 && pointerProps[pointerPropsSize - 1] == null) { + pointerProps[pointerPropsSize - 1] = PointerProperties() + pointerCoords[pointerPropsSize - 1] = PointerCoords() + pointerPropsSize-- } } diff --git a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt index beefe28a99..b08ce9b584 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt @@ -6,8 +6,8 @@ import com.facebook.react.ReactRootView @Deprecated(message = "Use component instead. Check gesture handler installation instructions in documentation for more information.") class RNGestureHandlerEnabledRootView : ReactRootView { - constructor(context: Context?) : super(context) {} - constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {} + constructor(context: Context?) : super(context) + constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) init { throw UnsupportedOperationException("Your application is configured to use RNGestureHandlerEnabledRootView which is no longer supported. You can see how to migrate to here: https://docs.swmansion.com/react-native-gesture-handler/docs/guides/migrating-off-rnghenabledroot") diff --git a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.kt b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.kt index 523de4bbdb..f392c47f15 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.kt @@ -10,7 +10,6 @@ import androidx.core.util.Pools import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -import com.facebook.react.uimanager.events.RCTEventEmitter import com.swmansion.gesturehandler.core.GestureHandler import com.swmansion.gesturehandler.react.eventbuilders.GestureHandlerEventDataBuilder @@ -47,9 +46,7 @@ class RNGestureHandlerEvent private constructor() : Event override fun getCoalescingKey() = coalescingKey - override fun dispatch(rctEventEmitter: RCTEventEmitter) { - rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, createEventData(dataBuilder!!)) - } + override fun getEventData(): WritableMap = createEventData(dataBuilder!!) companion object { const val EVENT_NAME = "onGestureHandlerEvent" diff --git a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt index 7e66e66c62..b0f311950b 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt @@ -78,13 +78,13 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView: action = MotionEvent.ACTION_CANCEL } if (rootView is RootView) { - rootView.onChildStartedNativeGesture(event) + rootView.onChildStartedNativeGesture(rootView, event) } event.recycle() } } - fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) { + fun requestDisallowInterceptTouchEvent() { // If this method gets called it means that some native view is attempting to grab lock for // touch event delivery. In that case we cancel all gesture recognizers if (orchestrator != null && !passingTouch) { @@ -116,6 +116,8 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView: } /*package*/ + @Suppress("UNUSED_PARAMETER", "COMMENT_IN_SUPPRESSION") + // We want to keep order of parameters, so instead of removing viewTag we suppress the warning fun handleSetJSResponder(viewTag: Int, blockNativeResponder: Boolean) { if (blockNativeResponder) { UiThreadUtil.runOnUiThread { tryCancelAllHandlers() } diff --git a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt index 36fb7836bb..61c1b4c9a7 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt @@ -44,7 +44,7 @@ class RNGestureHandlerRootView(context: Context?) : ReactViewGroup(context) { override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) { if (_enabled) { - rootHelper!!.requestDisallowInterceptTouchEvent(disallowIntercept) + rootHelper!!.requestDisallowInterceptTouchEvent() } super.requestDisallowInterceptTouchEvent(disallowIntercept) } diff --git a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt index af519eb07a..c51ac4514f 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt @@ -10,7 +10,6 @@ import androidx.core.util.Pools import com.facebook.react.bridge.Arguments import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -import com.facebook.react.uimanager.events.RCTEventEmitter import com.swmansion.gesturehandler.core.GestureHandler import com.swmansion.gesturehandler.react.eventbuilders.GestureHandlerEventDataBuilder @@ -46,9 +45,7 @@ class RNGestureHandlerStateChangeEvent private constructor() : Event() { private var extraData: WritableMap? = null private var coalescingKey: Short = 0 private fun > init(handler: T) { - super.init(handler.view!!.id) + super.init(UIManagerHelper.getSurfaceId(handler.view), handler.view!!.id) extraData = createEventData(handler) coalescingKey = handler.eventCoalescingKey } @@ -26,10 +26,7 @@ class RNGestureHandlerTouchEvent private constructor() : Event> createEventData(handler: T,): WritableMap = Arguments.createMap().apply { + fun > createEventData(handler: T): WritableMap = Arguments.createMap().apply { putInt("handlerTag", handler.tag) putInt("state", handler.state) putInt("numberOfTouches", handler.trackedPointersCount)