Skip to content

Commit

Permalink
[iOS][Android] Upgrade react-native-gesture-handler to 2.8.0 (#19654
Browse files Browse the repository at this point in the history
)

# Why

Upgrade `react-native-gesture-handler` to `2.8.0`.
Connected with https://exponent-internal.slack.com/archives/CNHBN8LNS/p1666255180108099.

# How

```
et update-vendored-module -m react-native-gesture-handler -c main
```

# Test Plan

- NCL in expo go ✅
  • Loading branch information
lukmccall committed Oct 21, 2022
1 parent 6239b2d commit e5f0011
Show file tree
Hide file tree
Showing 57 changed files with 463 additions and 431 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -13,7 +13,7 @@ Package-specific changes not released in any SDK will be added here just before
- Updated `@shopify/flash-list` from `1.1.0` to `1.3.0`. ([#19317](https://github.com/expo/expo/pull/19317) by [@kudo](https://github.com/kudo))
- Updated `react-native-view-shot` from `3.3.0` to `3.4.0`. ([#19405](https://github.com/expo/expo/pull/19405) by [@douglowder](https://github.com/douglowder))
- Updated `react-native-webview` from `11.23.0` to `11.23.1`. ([#19375](https://github.com/expo/expo/pull/19375) by [@aleqsio](https://github.com/aleqsio))
- Updated `react-native-gesture-handler` from `2.5.0` to `2.7.0`. ([#19362](https://github.com/expo/expo/pull/19362) by [@tsapeta](https://github.com/tsapeta))
- Updated `react-native-gesture-handler` from `2.5.0` to `2.8.0`. ([#19362](https://github.com/expo/expo/pull/19362) & [#19654](https://github.com/expo/expo/pull/19654) by [@tsapeta](https://github.com/tsapeta) & [@lukmccall](https://github.com/lukmccall))
- Updated `@react-native-community/netinfo` from `9.3.0` to `9.3.3`. ([#19421](https://github.com/expo/expo/pull/19421) by [@douglowder](https://github.com/douglowder))
- Updated `@react-native-picker/picker` from `2.4.2` to `2.4.6`. ([#19390](https://github.com/expo/expo/pull/19390) by [@aleqsio](https://github.com/aleqsio))
- Updated `react-native-screens` from `3.15.0` to `3.18.0`. ([#19383](https://github.com/expo/expo/pull/19383) by [@tsapeta](https://github.com/tsapeta))
Expand Down
Expand Up @@ -5,11 +5,17 @@ buildscript {
def kotlin_version = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : project.properties['RNGH_kotlinVersion']

repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
mavenCentral()
google()
}

dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version")
classpath("com.android.tools.build:gradle:7.2.1")
classpath("com.diffplug.spotless:spotless-plugin-gradle:6.7.2")
}
}

Expand Down Expand Up @@ -48,6 +54,10 @@ if (isNewArchitectureEnabled()) {
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'

if (project == rootProject) {
apply from: "spotless.gradle"
}

def safeExtGet(prop, fallback) {
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}
Expand Down Expand Up @@ -164,13 +174,8 @@ android {
exclude "**/libreact_render*.so"
}

// Include "lib/" as sources, unfortunately react-native link can't handle
// setting up alternative gradle modules. We still have "lib" defined as a
// standalone gradle module just to be used in AndroidNativeExample
sourceSets.main {
java {
srcDirs += 'lib/src/main/java'

// Include "common/" only when it's not provided by Reanimated to mitigate
// multiple definitions of the same class preventing build
if (shouldUseCommonInterfaceFromReanimated()) {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Expand Up @@ -4,7 +4,7 @@ import com.facebook.react.bridge.ReactContext
import com.facebook.react.uimanager.events.Event

class ReanimatedEventDispatcher {
fun <T : Event<T>>sendEvent(event: T, reactApplicationContext: ReactContext) {
// no-op
}
fun <T : Event<T>>sendEvent(event: T, reactApplicationContext: ReactContext) {
// no-op
}
}
Expand Up @@ -5,13 +5,13 @@ import com.facebook.react.uimanager.events.Event
import com.swmansion.reanimated.ReanimatedModule

class ReanimatedEventDispatcher {
private var reanimatedModule: ReanimatedModule? = null
private var reanimatedModule: ReanimatedModule? = null

fun <T : Event<T>>sendEvent(event: T, reactApplicationContext: ReactContext) {
if (reanimatedModule == null) {
reanimatedModule = reactApplicationContext.getNativeModule(ReanimatedModule::class.java)
}

reanimatedModule?.nodesManager?.onEventDispatch(event)
fun <T : Event<T>>sendEvent(event: T, reactApplicationContext: ReactContext) {
if (reanimatedModule == null) {
reanimatedModule = reactApplicationContext.getNativeModule(ReanimatedModule::class.java)
}

reanimatedModule?.nodesManager?.onEventDispatch(event)
}
}

This file was deleted.

Expand Up @@ -7,6 +7,6 @@ import com.facebook.react.uimanager.common.UIManagerType
import com.facebook.react.uimanager.events.Event

fun ReactContext.dispatchEvent(event: Event<*>) {
val fabricUIManager = UIManagerHelper.getUIManager(this, UIManagerType.FABRIC) as FabricUIManager
fabricUIManager.eventDispatcher.dispatchEvent(event)
val fabricUIManager = UIManagerHelper.getUIManager(this, UIManagerType.FABRIC) as FabricUIManager
fabricUIManager.eventDispatcher.dispatchEvent(event)
}
Expand Up @@ -4,10 +4,9 @@ import com.facebook.react.ReactPackage
import com.facebook.react.bridge.NativeModule
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.uimanager.ViewManager
import com.swmansion.gesturehandler.BuildConfig
import com.swmansion.gesturehandler.react.RNGestureHandlerButtonViewManager
import com.swmansion.gesturehandler.react.RNGestureHandlerModule
import com.swmansion.gesturehandler.react.RNGestureHandlerRootViewManager
import com.swmansion.gesturehandler.react.RNGestureHandlerButtonViewManager

class RNGestureHandlerPackage : ReactPackage {
override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
Expand All @@ -17,5 +16,6 @@ class RNGestureHandlerPackage : ReactPackage {
override fun createViewManagers(reactContext: ReactApplicationContext) =
listOf<ViewManager<*, *>>(
RNGestureHandlerRootViewManager(),
RNGestureHandlerButtonViewManager())
RNGestureHandlerButtonViewManager()
)
}
@@ -1,4 +1,4 @@
package com.swmansion.gesturehandler
package com.swmansion.gesturehandler.core

import android.os.Handler
import android.os.Looper
Expand Down Expand Up @@ -37,14 +37,17 @@ class FlingGestureHandler : GestureHandler<FlingGestureHandler>() {

private fun tryEndFling(event: MotionEvent) = if (
maxNumberOfPointersSimultaneously == numberOfPointersRequired &&
(direction and DIRECTION_RIGHT != 0 &&
event.rawX - startX > minAcceptableDelta ||
direction and DIRECTION_LEFT != 0 &&
startX - event.rawX > minAcceptableDelta ||
direction and DIRECTION_UP != 0 &&
startY - event.rawY > minAcceptableDelta ||
direction and DIRECTION_DOWN != 0 &&
event.rawY - startY > minAcceptableDelta)) {
(
direction and DIRECTION_RIGHT != 0 &&
event.rawX - startX > minAcceptableDelta ||
direction and DIRECTION_LEFT != 0 &&
startX - event.rawX > minAcceptableDelta ||
direction and DIRECTION_UP != 0 &&
startY - event.rawY > minAcceptableDelta ||
direction and DIRECTION_DOWN != 0 &&
event.rawY - startY > minAcceptableDelta
)
) {
handler!!.removeCallbacksAndMessages(null)
activate()
true
Expand Down
@@ -1,4 +1,4 @@
package com.swmansion.gesturehandler
package com.swmansion.gesturehandler.core

import android.app.Activity
import android.content.Context
Expand All @@ -14,6 +14,7 @@ import com.facebook.react.bridge.Arguments
import com.facebook.react.bridge.UiThreadUtil
import com.facebook.react.bridge.WritableArray
import com.facebook.react.uimanager.PixelUtil
import com.swmansion.gesturehandler.BuildConfig
import com.swmansion.gesturehandler.react.RNGestureHandlerTouchEvent
import java.lang.IllegalStateException
import java.util.*
Expand Down Expand Up @@ -48,7 +49,6 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
private val trackedPointers: Array<PointerData?> = Array(MAX_POINTERS_COUNT) { null }
var needsPointerData = false


private var hitSlop: FloatArray? = null
var eventCoalescingKey: Short = 0
private set
Expand Down Expand Up @@ -127,11 +127,15 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
}

fun setManualActivation(manualActivation: Boolean): ConcreteGestureHandlerT =
applySelf { this.manualActivation = manualActivation }
applySelf { this.manualActivation = manualActivation }

fun setHitSlop(
leftPad: Float, topPad: Float, rightPad: Float, bottomPad: Float,
width: Float, height: Float,
leftPad: Float,
topPad: Float,
rightPad: Float,
bottomPad: Float,
width: Float,
height: Float,
): ConcreteGestureHandlerT = applySelf {
if (hitSlop == null) {
hitSlop = FloatArray(6)
Expand Down Expand Up @@ -278,7 +282,7 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
}

// introduced in 1.11.0, remove if crashes are not reported
if(pointerProps.isEmpty()|| pointerCoords.isEmpty()){
if (pointerProps.isEmpty() || pointerCoords.isEmpty()) {
throw IllegalStateException("pointerCoords.size=${pointerCoords.size}, pointerProps.size=${pointerProps.size}")
}

Expand All @@ -289,8 +293,8 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
event.eventTime,
action,
count,
pointerProps, /* props are copied and hence it is safe to use static array here */
pointerCoords, /* same applies to coords */
pointerProps, /* props are copied and hence it is safe to use static array here */
pointerCoords, /* same applies to coords */
event.metaState,
event.buttonState,
event.xPrecision,
Expand All @@ -313,7 +317,8 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
handler: GestureHandler<*>,
event: MotionEvent,
e: IllegalArgumentException
) : Exception("""
) : Exception(
"""
handler: ${handler::class.simpleName}
state: ${handler.state}
view: ${handler.view}
Expand All @@ -324,14 +329,17 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
trackedPointersCount: ${handler.trackedPointersIDsCount}
trackedPointers: ${handler.trackedPointerIDs.joinToString(separator = ", ")}
while handling event: $event
""".trimIndent(), e) {}
""".trimIndent(),
e
)

fun handle(transformedEvent: MotionEvent, sourceEvent: MotionEvent) {
if (!isEnabled
|| state == STATE_CANCELLED
|| state == STATE_FAILED
|| state == STATE_END
|| trackedPointersIDsCount < 1) {
if (!isEnabled ||
state == STATE_CANCELLED ||
state == STATE_FAILED ||
state == STATE_END ||
trackedPointersIDsCount < 1
) {
return
}

Expand Down Expand Up @@ -380,11 +388,11 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
val offsetY = event.rawY - event.y

trackedPointers[pointerId] = PointerData(
pointerId,
event.getX(event.actionIndex),
event.getY(event.actionIndex),
event.getX(event.actionIndex) + offsetX - windowOffset[0],
event.getY(event.actionIndex) + offsetY - windowOffset[1],
pointerId,
event.getX(event.actionIndex),
event.getY(event.actionIndex),
event.getX(event.actionIndex) + offsetX - windowOffset[0],
event.getY(event.actionIndex) + offsetY - windowOffset[1],
)
trackedPointersCount++
addChangedPointer(trackedPointers[pointerId]!!)
Expand All @@ -402,11 +410,11 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
val offsetY = event.rawY - event.y

trackedPointers[pointerId] = PointerData(
pointerId,
event.getX(event.actionIndex),
event.getY(event.actionIndex),
event.getX(event.actionIndex) + offsetX - windowOffset[0],
event.getY(event.actionIndex) + offsetY - windowOffset[1],
pointerId,
event.getX(event.actionIndex),
event.getY(event.actionIndex),
event.getX(event.actionIndex) + offsetX - windowOffset[0],
event.getY(event.actionIndex) + offsetY - windowOffset[1],
)
addChangedPointer(trackedPointers[pointerId]!!)
trackedPointers[pointerId] = null
Expand Down Expand Up @@ -545,11 +553,11 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
}

fun wantEvents(): Boolean {
return isEnabled
&& state != STATE_FAILED
&& state != STATE_CANCELLED
&& state != STATE_END
&& trackedPointersIDsCount > 0
return isEnabled &&
state != STATE_FAILED &&
state != STATE_CANCELLED &&
state != STATE_END &&
trackedPointersIDsCount > 0
}

open fun shouldRequireToWaitForFailure(handler: GestureHandler<*>): Boolean {
Expand Down Expand Up @@ -745,7 +753,7 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
private lateinit var pointerCoords: Array<PointerCoords?>
private fun initPointerProps(size: Int) {
var size = size
if (!::pointerProps.isInitialized) {
if (!Companion::pointerProps.isInitialized) {
pointerProps = arrayOfNulls(MAX_POINTERS_COUNT)
pointerCoords = arrayOfNulls(MAX_POINTERS_COUNT)
}
Expand Down
@@ -1,4 +1,4 @@
package com.swmansion.gesturehandler
package com.swmansion.gesturehandler.core

interface GestureHandlerInteractionController {
fun shouldWaitForHandlerFailure(handler: GestureHandler<*>, otherHandler: GestureHandler<*>): Boolean
Expand Down

0 comments on commit e5f0011

Please sign in to comment.