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

Address compilation warnings #2597

Merged
merged 16 commits into from
Mar 12, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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")
// These parameters may be useful in the future
m-bert marked this conversation as resolved.
Show resolved Hide resolved
fun <T : Event<T>>sendEvent(event: T, reactApplicationContext: ReactContext) {
// no-op
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)!!
Expand All @@ -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.
j-piasecki marked this conversation as resolved.
Show resolved Hide resolved
reactModule.isCxxModule,
true
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -835,15 +835,15 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
private lateinit var pointerProps: Array<PointerProperties?>
private lateinit var pointerCoords: Array<PointerCoords?>
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--
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.facebook.react.ReactRootView

@Deprecated(message = "Use <GestureHandlerRootView /> 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 <GestureHandlerRootView /> here: https://docs.swmansion.com/react-native-gesture-handler/docs/guides/migrating-off-rnghenabledroot")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -47,9 +46,7 @@ class RNGestureHandlerEvent private constructor() : Event<RNGestureHandlerEvent>

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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
action = MotionEvent.ACTION_CANCEL
}
if (rootView is RootView) {
rootView.onChildStartedNativeGesture(event)
rootView.onChildStartedNativeGesture(rootView, event)
}
event.recycle()
}
}

@Suppress("UNUSED_PARAMETER", "COMMENT_IN_SUPPRESSION")
// This parameter may be useful in the future
m-bert marked this conversation as resolved.
Show resolved Hide resolved
fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
// 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
Expand Down Expand Up @@ -116,6 +118,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() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -46,9 +45,7 @@ class RNGestureHandlerStateChangeEvent private constructor() : Event<RNGestureHa
// TODO: coalescing
override fun getCoalescingKey(): Short = 0

override fun dispatch(rctEventEmitter: RCTEventEmitter) {
rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, createEventData(dataBuilder!!, newState, oldState))
}
override fun getEventData(): WritableMap = createEventData(dataBuilder!!, newState, oldState)

companion object {
const val EVENT_NAME = "onGestureHandlerStateChange"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.swmansion.gesturehandler.react
import androidx.core.util.Pools
import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.WritableMap
import com.facebook.react.uimanager.UIManagerHelper
import com.facebook.react.uimanager.events.Event
import com.facebook.react.uimanager.events.RCTEventEmitter
import com.swmansion.gesturehandler.core.GestureHandler

class RNGestureHandlerTouchEvent private constructor() : Event<RNGestureHandlerTouchEvent>() {
private var extraData: WritableMap? = null
private var coalescingKey: Short = 0
private fun <T : GestureHandler<T>> init(handler: T) {
super.init(handler.view!!.id)
super.init(UIManagerHelper.getSurfaceId(handler.view), handler.view!!.id)
extraData = createEventData(handler)
coalescingKey = handler.eventCoalescingKey
}
Expand All @@ -26,10 +26,7 @@ class RNGestureHandlerTouchEvent private constructor() : Event<RNGestureHandlerT
override fun canCoalesce() = true

override fun getCoalescingKey() = coalescingKey

override fun dispatch(rctEventEmitter: RCTEventEmitter) {
rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, extraData)
}
override fun getEventData(): WritableMap? = extraData

companion object {
const val EVENT_UNDETERMINED = 0
Expand All @@ -47,7 +44,7 @@ class RNGestureHandlerTouchEvent private constructor() : Event<RNGestureHandlerT
init(handler)
}

fun <T : GestureHandler<T>> createEventData(handler: T,): WritableMap = Arguments.createMap().apply {
fun <T : GestureHandler<T>> createEventData(handler: T): WritableMap = Arguments.createMap().apply {
putInt("handlerTag", handler.tag)
putInt("state", handler.state)
putInt("numberOfTouches", handler.trackedPointersCount)
Expand Down
Loading