diff --git a/.github/workflows/check-archs-consistency.yml b/.github/workflows/check-archs-consistency.yml deleted file mode 100644 index 0d200aca34..0000000000 --- a/.github/workflows/check-archs-consistency.yml +++ /dev/null @@ -1,40 +0,0 @@ -name: Test consistency between Paper & Fabric - -on: - pull_request: - branches: - - main - paths: - - .github/workflows/check-archs-consistency.yml - - packages/react-native-gesture-handler/src/specs/** - - packages/react-native-gesture-handler/package.json - - apps/basic-example/package.json - push: - branches: - - main - workflow_dispatch: - -jobs: - if: github.repository == 'software-mansion/react-native-gesture-handler' - - check: - runs-on: ubuntu-latest - concurrency: - group: check-archs-consistency-${{ github.ref }} - cancel-in-progress: true - - steps: - - name: checkout - uses: actions/checkout@v4 - - - name: Use Node.js 18 - uses: actions/setup-node@v4 - with: - node-version: 18 - cache: yarn - - - name: Install node dependencies - run: yarn - - - name: Check Android Paper & Fabric generated interfaces consistency - run: yarn workspace react-native-gesture-handler architectures-consistency-check diff --git a/apps/macos-example/macos/Podfile.lock b/apps/macos-example/macos/Podfile.lock index 45752e9cf6..5db4e5bafe 100644 --- a/apps/macos-example/macos/Podfile.lock +++ b/apps/macos-example/macos/Podfile.lock @@ -1504,31 +1504,6 @@ PODS: - ReactCodegen - ReactCommon/turbomodule/bridging - ReactCommon/turbomodule/core - - RNGestureHandler/shared (= 2.25.0) - - Yoga - - RNGestureHandler/shared (2.25.0): - - DoubleConversion - - glog - - hermes-engine - - RCT-Folly (= 2024.11.18.00) - - RCTRequired - - RCTTypeSafety - - React-Core - - React-debug - - React-Fabric - - React-featureflags - - React-graphics - - React-hermes - - React-ImageManager - - React-jsi - - React-NativeModulesApple - - React-RCTFabric - - React-renderercss - - React-rendererdebug - - React-utils - - ReactCodegen - - ReactCommon/turbomodule/bridging - - ReactCommon/turbomodule/core - Yoga - RNReanimated (3.18.0): - DoubleConversion @@ -1879,8 +1854,8 @@ SPEC CHECKSUMS: React-debug: 9ef45d64b88281e7e629158410ceb61b3bb51ea0 React-defaultsnativemodule: 4e5646f85edca54998efb35efac242045d1123dc React-domnativemodule: aa0750129c97675305ad52da5e0525985a7bc1c9 - React-Fabric: 20a409df4dc64d8139324f707837bfa72d5663ce - React-FabricComponents: a8ad8665dacbf82a4669f5a4e55531594c65601b + React-Fabric: e5670d9e6c90650fc3d8b86eedfb3a75b80152cb + React-FabricComponents: d1e9208aa6b2134bb1c18d8a42cf4c975ffc755d React-FabricImage: 309d4ebb53631461fc8108b7b3ce6dc84f135a20 React-featureflags: 46790800dbdeb1305b3b12427b4d18413dadd13e React-featureflagsnativemodule: eb77d500c3770978e9c1c8e6f3f36a923ca7eecf @@ -1926,7 +1901,7 @@ SPEC CHECKSUMS: ReactCodegen: 3d30536e47f328f0a297d897cb789e46a092c2a6 ReactCommon: 0f22e3dd34a8215b8482778898f6e1e95572c498 RNCAsyncStorage: b9f5f78da5d16a853fe3dc22e8268d932fc45a83 - RNGestureHandler: 9ea0b24ab06251465e366792c8d1a8f96d7a41ad + RNGestureHandler: cae3c899259949424d97bbe309c68be7c673cff6 RNReanimated: 6ccc6e6826ada6643d2e6474d95f37a1fbf7771d RNSVG: 4c63b12b7b5761063bca4f20dd228f6a8370f614 SocketRocket: 03f7111df1a343b162bf5b06ead333be808e1e0a @@ -1934,4 +1909,4 @@ SPEC CHECKSUMS: PODFILE CHECKSUM: ba6f2105d3e43bf0ae77356a9afcc8b532e3c306 -COCOAPODS: 1.15.2 +COCOAPODS: 1.16.2 diff --git a/packages/react-native-gesture-handler/RNGestureHandler.podspec b/packages/react-native-gesture-handler/RNGestureHandler.podspec index 1b1979d847..57151c9566 100644 --- a/packages/react-native-gesture-handler/RNGestureHandler.podspec +++ b/packages/react-native-gesture-handler/RNGestureHandler.podspec @@ -24,13 +24,9 @@ Pod::Spec.new do |s| "OTHER_CFLAGS" => "$(inherited) " + compilation_metadata_generation_flag } - if defined?(install_modules_dependencies()) != nil - install_modules_dependencies(s); - else - s.dependency "React-Core" - end + install_modules_dependencies(s); - if ENV['USE_FRAMEWORKS'] != nil && ENV['RCT_NEW_ARCH_ENABLED'] == '1' + if ENV['USE_FRAMEWORKS'] != nil add_dependency(s, "React-FabricComponents", :additional_framework_paths => [ "react/renderer/textlayoutmanager/platform/ios", "react/renderer/components/textinput/platform/ios", diff --git a/packages/react-native-gesture-handler/android/build.gradle b/packages/react-native-gesture-handler/android/build.gradle index ac149a0e7d..5614c7a29e 100644 --- a/packages/react-native-gesture-handler/android/build.gradle +++ b/packages/react-native-gesture-handler/android/build.gradle @@ -16,14 +16,6 @@ buildscript { } } -def isNewArchitectureEnabled() { - // To opt-in for the New Architecture, you can either: - // - Set `newArchEnabled` to true inside the `gradle.properties` file - // - Invoke gradle with `-newArchEnabled=true` - // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true` - return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" -} - def safeExtGet(prop, fallback) { rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback } @@ -57,6 +49,11 @@ def resolveReactNativeDirectory() { ) } +def isNewArchitectureEnabled() { + // This is a workaround for linter crashing when applying the `com.facebook.react` plugin. + return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" +} + if (isNewArchitectureEnabled()) { apply plugin: 'com.facebook.react' } @@ -147,20 +144,16 @@ android { defaultConfig { minSdkVersion safeExtGet('minSdkVersion', 24) targetSdkVersion safeExtGet('targetSdkVersion', 33) - buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() buildConfigField "int", "REACT_NATIVE_MINOR_VERSION", REACT_NATIVE_MINOR_VERSION.toString() - if (isNewArchitectureEnabled()) { - var appProject = rootProject.allprojects.find { it.plugins.hasPlugin('com.android.application') } - externalNativeBuild { - cmake { - cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++20", "-DANDROID" - arguments "-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}", - "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}", - "-DANDROID_STL=c++_shared", - "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON" - abiFilters(*reactNativeArchitectures()) - } + externalNativeBuild { + cmake { + cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++20", "-DANDROID" + arguments "-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}", + "-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}", + "-DANDROID_STL=c++_shared", + "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON" + abiFilters(*reactNativeArchitectures()) } } } @@ -170,11 +163,9 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } - if (isNewArchitectureEnabled()) { - externalNativeBuild { - cmake { - path "src/main/jni/CMakeLists.txt" - } + externalNativeBuild { + cmake { + path "src/main/jni/CMakeLists.txt" } } @@ -202,14 +193,6 @@ android { } else { srcDirs += 'nosvg/src/main/java' } - - if (isNewArchitectureEnabled()) { - srcDirs += 'fabric/src/main/java' - } else { - // 'paper/src/main/java' includes files from codegen so the library can compile with - // codegen turned off - srcDirs += 'paper/src/main/java' - } } } @@ -233,7 +216,6 @@ def kotlin_version = safeExtGet('kotlinVersion', project.properties['RNGH_kotlin dependencies { implementation 'com.facebook.react:react-native:+' // from node_modules - if (shouldUseCommonInterfaceFromReanimated()) { // Include Reanimated as dependency to load the common interface implementation(rootProject.subprojects.find { it.name == 'react-native-reanimated' }) { diff --git a/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java b/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java deleted file mode 100644 index 755f026e14..0000000000 --- a/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +++ /dev/null @@ -1,60 +0,0 @@ -/** -* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). -* -* Do not edit this file as changes may cause incorrect behavior and will be lost -* once the code is regenerated. -* -* @generated by codegen project: GeneratePropsJavaDelegate.js -*/ - -package com.facebook.react.viewmanagers; - -import android.view.View; -import androidx.annotation.Nullable; -import com.facebook.react.bridge.ColorPropConverter; -import com.facebook.react.uimanager.BaseViewManager; -import com.facebook.react.uimanager.BaseViewManagerDelegate; -import com.facebook.react.uimanager.LayoutShadowNode; - -public class RNGestureHandlerButtonManagerDelegate & RNGestureHandlerButtonManagerInterface> extends BaseViewManagerDelegate { - public RNGestureHandlerButtonManagerDelegate(U viewManager) { - super(viewManager); - } - @Override - public void setProperty(T view, String propName, @Nullable Object value) { - switch (propName) { - case "exclusive": - mViewManager.setExclusive(view, value == null ? true : (boolean) value); - break; - case "foreground": - mViewManager.setForeground(view, value == null ? false : (boolean) value); - break; - case "borderless": - mViewManager.setBorderless(view, value == null ? false : (boolean) value); - break; - case "enabled": - mViewManager.setEnabled(view, value == null ? true : (boolean) value); - break; - case "rippleColor": - mViewManager.setRippleColor(view, ColorPropConverter.getColor(value, view.getContext())); - break; - case "rippleRadius": - mViewManager.setRippleRadius(view, value == null ? 0 : ((Double) value).intValue()); - break; - case "touchSoundDisabled": - mViewManager.setTouchSoundDisabled(view, value == null ? false : (boolean) value); - break; - case "borderWidth": - mViewManager.setBorderWidth(view, value == null ? 0f : ((Double) value).floatValue()); - break; - case "borderColor": - mViewManager.setBorderColor(view, ColorPropConverter.getColor(value, view.getContext())); - break; - case "borderStyle": - mViewManager.setBorderStyle(view, value == null ? "solid" : (String) value); - break; - default: - super.setProperty(view, propName, value); - } - } -} diff --git a/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerInterface.java b/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerInterface.java deleted file mode 100644 index 975704f08b..0000000000 --- a/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerInterface.java +++ /dev/null @@ -1,27 +0,0 @@ -/** -* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). -* -* Do not edit this file as changes may cause incorrect behavior and will be lost -* once the code is regenerated. -* -* @generated by codegen project: GeneratePropsJavaInterface.js -*/ - -package com.facebook.react.viewmanagers; - -import android.view.View; -import androidx.annotation.Nullable; -import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; - -public interface RNGestureHandlerButtonManagerInterface extends ViewManagerWithGeneratedInterface { - void setExclusive(T view, boolean value); - void setForeground(T view, boolean value); - void setBorderless(T view, boolean value); - void setEnabled(T view, boolean value); - void setRippleColor(T view, @Nullable Integer value); - void setRippleRadius(T view, int value); - void setTouchSoundDisabled(T view, boolean value); - void setBorderWidth(T view, float value); - void setBorderColor(T view, @Nullable Integer value); - void setBorderStyle(T view, @Nullable String value); -} diff --git a/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerDelegate.java b/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerDelegate.java deleted file mode 100644 index 03524008f0..0000000000 --- a/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerDelegate.java +++ /dev/null @@ -1,32 +0,0 @@ -/** -* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). -* -* Do not edit this file as changes may cause incorrect behavior and will be lost -* once the code is regenerated. -* -* @generated by codegen project: GeneratePropsJavaDelegate.js -*/ - -package com.facebook.react.viewmanagers; - -import android.view.View; -import androidx.annotation.Nullable; -import com.facebook.react.uimanager.BaseViewManager; -import com.facebook.react.uimanager.BaseViewManagerDelegate; -import com.facebook.react.uimanager.LayoutShadowNode; - -public class RNGestureHandlerRootViewManagerDelegate & RNGestureHandlerRootViewManagerInterface> extends BaseViewManagerDelegate { - public RNGestureHandlerRootViewManagerDelegate(U viewManager) { - super(viewManager); - } - @Override - public void setProperty(T view, String propName, @Nullable Object value) { - switch (propName) { - case "moduleId": - mViewManager.setModuleId(view, value == null ? 0 : ((Double) value).intValue()); - break; - default: - super.setProperty(view, propName, value); - } - } -} diff --git a/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerInterface.java b/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerInterface.java deleted file mode 100644 index 8dc0586aec..0000000000 --- a/packages/react-native-gesture-handler/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerRootViewManagerInterface.java +++ /dev/null @@ -1,17 +0,0 @@ -/** -* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). -* -* Do not edit this file as changes may cause incorrect behavior and will be lost -* once the code is regenerated. -* -* @generated by codegen project: GeneratePropsJavaInterface.js -*/ - -package com.facebook.react.viewmanagers; - -import android.view.View; -import com.facebook.react.uimanager.ViewManagerWithGeneratedInterface; - -public interface RNGestureHandlerRootViewManagerInterface extends ViewManagerWithGeneratedInterface { - void setModuleId(T view, int value); -} diff --git a/packages/react-native-gesture-handler/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java b/packages/react-native-gesture-handler/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java deleted file mode 100644 index 3fedeea9a9..0000000000 --- a/packages/react-native-gesture-handler/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java +++ /dev/null @@ -1,63 +0,0 @@ - -/** - * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen). - * - * Do not edit this file as changes may cause incorrect behavior and will be lost - * once the code is regenerated. - * - * @generated by codegen project: GenerateModuleJavaSpec.js - * - * @nolint - */ - -package com.swmansion.gesturehandler; - -import com.facebook.proguard.annotations.DoNotStrip; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; -import com.facebook.react.bridge.ReactMethod; -import com.facebook.react.bridge.ReactModuleWithSpec; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.turbomodule.core.interfaces.TurboModule; -import javax.annotation.Nonnull; - -public abstract class NativeRNGestureHandlerModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule { - public static final String NAME = "RNGestureHandlerModule"; - - public NativeRNGestureHandlerModuleSpec(ReactApplicationContext reactContext) { - super(reactContext); - } - - @Override - public @Nonnull String getName() { - return NAME; - } - - @ReactMethod - @DoNotStrip - public abstract void handleSetJSResponder(double tag, boolean blockNativeResponder); - - @ReactMethod - @DoNotStrip - public abstract void handleClearJSResponder(); - - @ReactMethod(isBlockingSynchronousMethod = true) - @DoNotStrip - public abstract boolean createGestureHandler(String handlerName, double handlerTag, ReadableMap config); - - @ReactMethod - @DoNotStrip - public abstract void attachGestureHandler(double handlerTag, double newView, double actionType); - - @ReactMethod - @DoNotStrip - public abstract void updateGestureHandler(double handlerTag, ReadableMap newConfig); - - @ReactMethod - @DoNotStrip - public abstract void dropGestureHandler(double handlerTag); - - @ReactMethod - @DoNotStrip - public abstract void flushOperations(); -} diff --git a/packages/react-native-gesture-handler/android/paper/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt b/packages/react-native-gesture-handler/android/paper/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt deleted file mode 100644 index 6a21138d84..0000000000 --- a/packages/react-native-gesture-handler/android/paper/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt +++ /dev/null @@ -1,16 +0,0 @@ -package com.swmansion.gesturehandler - -import com.facebook.react.bridge.ReactContext -import com.facebook.react.uimanager.UIManagerModule -import com.facebook.react.uimanager.events.Event - -fun ReactContext.dispatchEvent(event: Event<*>) { - try { - this.getNativeModule(UIManagerModule::class.java)!!.eventDispatcher.dispatchEvent(event) - } catch (e: NullPointerException) { - throw Exception( - "Couldn't get an instance of UIManagerModule. Gesture Handler is unable to send an event.", - e, - ) - } -} diff --git a/packages/react-native-gesture-handler/android/fabric/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerComponentsRegistry.java b/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerComponentsRegistry.java similarity index 100% rename from packages/react-native-gesture-handler/android/fabric/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerComponentsRegistry.java rename to packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerComponentsRegistry.java diff --git a/packages/react-native-gesture-handler/android/fabric/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt b/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt similarity index 100% rename from packages/react-native-gesture-handler/android/fabric/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt rename to packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/ReactContextExtensions.kt diff --git a/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEventDispatcher.kt b/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEventDispatcher.kt index 126f0f61ea..4725dcb5ad 100644 --- a/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEventDispatcher.kt +++ b/packages/react-native-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEventDispatcher.kt @@ -4,7 +4,6 @@ import android.view.MotionEvent import com.facebook.react.bridge.ReactApplicationContext import com.facebook.react.bridge.WritableMap import com.facebook.react.uimanager.events.Event -import com.swmansion.gesturehandler.BuildConfig import com.swmansion.gesturehandler.ReanimatedProxy import com.swmansion.gesturehandler.core.GestureHandler import com.swmansion.gesturehandler.core.OnTouchEventListener @@ -57,19 +56,10 @@ class RNGestureHandlerEventDispatcher(private val reactApplicationContext: React } GestureHandler.ACTION_TYPE_JS_FUNCTION_OLD_API -> { // JS function, Animated.event with useNativeDriver: false using old API - if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - val data = RNGestureHandlerEvent.createEventData( - handlerFactory.createEventBuilder(handler), - ) - sendEventForDeviceEvent(RNGestureHandlerEvent.EVENT_NAME, data) - } else { - val event = RNGestureHandlerEvent.obtain( - handler, - handler.actionType, - handlerFactory.createEventBuilder(handler), - ) - sendEventForDirectEvent(event) - } + val data = RNGestureHandlerEvent.createEventData( + handlerFactory.createEventBuilder(handler), + ) + sendEventForDeviceEvent(RNGestureHandlerEvent.EVENT_NAME, data) } GestureHandler.ACTION_TYPE_JS_FUNCTION_NEW_API -> { // JS function, Animated.event with useNativeDriver: false using new API @@ -123,23 +113,12 @@ class RNGestureHandlerEventDispatcher(private val reactApplicationContext: React GestureHandler.ACTION_TYPE_NATIVE_ANIMATED_EVENT, GestureHandler.ACTION_TYPE_JS_FUNCTION_OLD_API -> { // JS function or Animated.event with useNativeDriver: false with old API - if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - val data = RNGestureHandlerStateChangeEvent.createEventData( - handlerFactory.createEventBuilder(handler), - newState, - oldState, - ) - sendEventForDeviceEvent(RNGestureHandlerStateChangeEvent.EVENT_NAME, data) - } else { - val event = RNGestureHandlerStateChangeEvent.obtain( - handler, - newState, - oldState, - handler.actionType, - handlerFactory.createEventBuilder(handler), - ) - sendEventForDirectEvent(event) - } + val data = RNGestureHandlerStateChangeEvent.createEventData( + handlerFactory.createEventBuilder(handler), + newState, + oldState, + ) + sendEventForDeviceEvent(RNGestureHandlerStateChangeEvent.EVENT_NAME, data) } GestureHandler.ACTION_TYPE_JS_FUNCTION_NEW_API -> { @@ -203,13 +182,7 @@ class RNGestureHandlerEventDispatcher(private val reactApplicationContext: React private fun > sendEventForReanimated(event: T) { // Delivers the event to Reanimated. - if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { - // Send event directly to Reanimated - reanimatedProxy.sendEvent(event, reactApplicationContext) - } else { - // In the old architecture, Reanimated subscribes for specific direct events. - sendEventForDirectEvent(event) - } + reanimatedProxy.sendEvent(event, reactApplicationContext) } private fun sendEventForNativeAnimatedEvent(event: RNGestureHandlerEvent) { @@ -220,11 +193,6 @@ class RNGestureHandlerEventDispatcher(private val reactApplicationContext: React reactApplicationContext.dispatchEvent(event) } - private fun > sendEventForDirectEvent(event: T) { - // Delivers the event to JS as a direct event. This method is called only on Paper. - reactApplicationContext.dispatchEvent(event) - } - private fun sendEventForDeviceEvent(eventName: String, data: WritableMap) { // Delivers the event to JS as a device event. reactApplicationContext.deviceEventEmitter.emit(eventName, data) diff --git a/packages/react-native-gesture-handler/apple/Handlers/RNNativeViewHandler.mm b/packages/react-native-gesture-handler/apple/Handlers/RNNativeViewHandler.mm index e36f9463f0..e1e0c27a48 100644 --- a/packages/react-native-gesture-handler/apple/Handlers/RNNativeViewHandler.mm +++ b/packages/react-native-gesture-handler/apple/Handlers/RNNativeViewHandler.mm @@ -14,12 +14,7 @@ #import #import - -#ifdef RCT_NEW_ARCH_ENABLED #import -#else -#import -#endif // RCT_NEW_ARCH_ENABLED #pragma mark RNDummyGestureRecognizer diff --git a/packages/react-native-gesture-handler/apple/RNGHUIKit.h b/packages/react-native-gesture-handler/apple/RNGHUIKit.h index dc0b742ca2..c5f8b4859f 100644 --- a/packages/react-native-gesture-handler/apple/RNGHUIKit.h +++ b/packages/react-native-gesture-handler/apple/RNGHUIKit.h @@ -3,6 +3,8 @@ #import typedef UIView RNGHUIView; +typedef UIWindow RNGHWindow; +typedef UIScrollView RNGHScrollView; typedef UITouch RNGHUITouch; typedef UIScrollView RNGHUIScrollView; @@ -17,6 +19,8 @@ typedef UIScrollView RNGHUIScrollView; #import typedef RCTUIView RNGHUIView; +typedef NSWindow RNGHWindow; +typedef NSScrollView RNGHScrollView; typedef RCTUITouch RNGHUITouch; typedef NSScrollView RNGHUIScrollView; diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandler.h b/packages/react-native-gesture-handler/apple/RNGestureHandler.h index 3d4b731a64..eaa2ec941a 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandler.h +++ b/packages/react-native-gesture-handler/apple/RNGestureHandler.h @@ -79,9 +79,7 @@ @property (nonatomic) BOOL manualActivation; @property (nonatomic) BOOL dispatchesAnimatedEvents; -#if RCT_NEW_ARCH_ENABLED - (BOOL)isViewParagraphComponent:(nullable RNGHUIView *)view; -#endif - (nonnull RNGHUIView *)chooseViewForInteraction:(nonnull UIGestureRecognizer *)recognizer; - (void)bindToView:(nonnull RNGHUIView *)view; - (void)unbindFromView; diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandler.mm b/packages/react-native-gesture-handler/apple/RNGestureHandler.mm index bec86fe5bd..418d3eb7f6 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandler.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandler.mm @@ -10,12 +10,8 @@ #import -#ifdef RCT_NEW_ARCH_ENABLED #import #import -#else -#import -#endif @interface UIGestureRecognizer (GestureHandler) @property (nonatomic, readonly) RNGestureHandler *gestureHandler; @@ -221,25 +217,19 @@ - (UITouchType)getPointerType return (UITouchType)_pointerType; } -#if RCT_NEW_ARCH_ENABLED - (BOOL)isViewParagraphComponent:(RNGHUIView *)view { return [view isKindOfClass:[RCTParagraphComponentView class]]; } -#endif - (void)bindToView:(RNGHUIView *)view { self.recognizer.delegate = self; -#if RCT_NEW_ARCH_ENABLED - // Starting from react-native 0.79 `RCTParagraphTextView` overrides `hitTest` method to return `nil`. This results in - // native `UIGestureRecognizer` not responding to gestures. To fix this issue, we attach recognizer to its parent, - // i.e. `RCTParagraphComponentView`. + // Starting from react-native 0.79 `RCTParagraphTextView` overrides `hitTest` method to return `nil`. + // This results in native `UIGestureRecognizer` not responding to gestures. + // To fix this issue, we attach recognizer to its parent, i.e. `RCTParagraphComponentView`. RNGHUIView *recognizerView = [self isViewParagraphComponent:view.superview] ? view.superview : view; -#else - RNGHUIView *recognizerView = view; -#endif #if !TARGET_OS_OSX recognizerView.userInteractionEnabled = YES; @@ -278,11 +268,7 @@ - (RNGestureHandlerEventExtraData *)eventExtraData:(UIGestureRecognizer *)recogn */ - (RNGHUIView *)chooseViewForInteraction:(UIGestureRecognizer *)recognizer { -#if RCT_NEW_ARCH_ENABLED return [self isViewParagraphComponent:recognizer.view] ? recognizer.view.subviews[0] : recognizer.view; -#else - return recognizer.view; -#endif } - (void)handleGesture:(UIGestureRecognizer *)recognizer @@ -612,20 +598,10 @@ - (BOOL)isUIScrollViewPanGestureRecognizer:(NSGestureRecognizer *)gestureRecogni - (RNGHUIScrollView *)retrieveScrollView:(RNGHUIView *)view { -#ifdef RCT_NEW_ARCH_ENABLED if ([view isKindOfClass:[RCTScrollViewComponentView class]]) { RNGHUIScrollView *scrollView = ((RCTScrollViewComponentView *)view).scrollView; return scrollView; } -#else - if ([view isKindOfClass:[RCTScrollView class]]) { - // This part of the code is coupled with RN implementation of ScrollView native wrapper and - // we expect for RCTScrollView component to contain a subclass of UIScrollview as the only - // subview - RNGHUIScrollView *scrollView = [view.subviews objectAtIndex:0]; - return scrollView; - } -#endif return nil; } diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerButton.h b/packages/react-native-gesture-handler/apple/RNGestureHandlerButton.h index 6e789aacb2..59d9304eab 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerButton.h +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerButton.h @@ -10,18 +10,16 @@ #if TARGET_OS_OSX -#if RCT_NEW_ARCH_ENABLED - #include @protocol RCTComponentViewProtocol; -#endif // RCT_NEW_ARCH_ENABLED - @interface RNGestureHandlerButton : NSControl + #else @interface RNGestureHandlerButton : UIControl #endif // TARGET_OS_OSX + /** * Insets used when hit testing inside this view. */ @@ -29,7 +27,7 @@ @property (nonatomic, assign) CGFloat borderRadius; @property (nonatomic) BOOL userEnabled; -#if TARGET_OS_OSX && RCT_NEW_ARCH_ENABLED +#if TARGET_OS_OSX - (void)mountChildComponentView:(RNGHUIView *)childComponentView index:(NSInteger)index; - (void)unmountChildComponentView:(RNGHUIView *)childComponentView index:(NSInteger)index; - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerButton.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerButton.mm index c9f8067bd6..9ecec68cc4 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerButton.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerButton.mm @@ -14,13 +14,9 @@ #import #endif -#if RCT_NEW_ARCH_ENABLED - #import #import -#endif - /** * Gesture Handler Button components overrides standard mechanism used by RN * to determine touch target, which normally would reurn the UIView that is placed @@ -154,9 +150,9 @@ - (NSString *)accessibilityLabel return str; } -#endif -#if TARGET_OS_OSX && RCT_NEW_ARCH_ENABLED +#else + - (void)mountChildComponentView:(RNGHUIView *)childComponentView index:(NSInteger)index { if (childComponentView.superview != nil) { @@ -209,6 +205,7 @@ - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetric self.hidden = layoutMetrics.displayType == facebook::react::DisplayType::None; } } + #endif @end diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.h b/packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.h index aa03db683c..0aa0c19a6d 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.h +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.h @@ -1,5 +1,3 @@ -#ifdef RCT_NEW_ARCH_ENABLED - #if !TARGET_OS_OSX #import #else @@ -18,5 +16,3 @@ NS_ASSUME_NONNULL_BEGIN @end NS_ASSUME_NONNULL_END - -#endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.mm index e19c8d531b..e90fcc5e84 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerButtonComponentView.mm @@ -1,5 +1,3 @@ -#ifdef RCT_NEW_ARCH_ENABLED - #import "RNGestureHandlerButtonComponentView.h" #import @@ -215,5 +213,3 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared & { return RNGestureHandlerButtonComponentView.class; } - -#endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm index 4c7cfadb62..1f164445d6 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm @@ -50,7 +50,7 @@ - (instancetype)initWithFrame:(CGRect)frame // TODO: I'm not sure whether this is the correct place for cleanup // Possibly allowing recycling and doing this in prepareForRecycle would be better -- (void)willMoveToWindow:(UIWindow *)newWindow +- (void)willMoveToWindow:(RNGHWindow *)newWindow { if (newWindow == nil) { RNGestureHandlerManager *handlerManager = [RNGestureHandlerModule handlerManagerForModuleId:_moduleId]; @@ -94,14 +94,14 @@ - (BOOL)shouldAttachGestureToSubview:(NSNumber *)handlerTag return [[[handlerManager registry] handlerWithTag:handlerTag] wantsToAttachDirectlyToView]; } -- (void)addSubview:(UIView *)view +- (void)addSubview:(RNGHUIView *)view { [super addSubview:view]; [self tryAttachHandlerToChildView]; } -- (void)willRemoveSubview:(UIView *)subview +- (void)willRemoveSubview:(RNGHUIView *)subview { [self detachNativeGestureHandlers]; diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerManager.h b/packages/react-native-gesture-handler/apple/RNGestureHandlerManager.h index 7f3d9ceaef..a4ab245bae 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerManager.h +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerManager.h @@ -11,15 +11,10 @@ @interface RNGestureHandlerManager : NSObject -#ifdef RCT_NEW_ARCH_ENABLED @property (nonatomic, strong, readonly, nonnull) RNGestureHandlerRegistry *registry; - (nonnull instancetype)initWithModuleRegistry:(nonnull RCTModuleRegistry *)moduleRegistry viewRegistry:(nonnull RCTViewRegistry *)viewRegistry; -#else -- (nonnull instancetype)initWithUIManager:(nonnull RCTUIManager *)uiManager - eventDispatcher:(nonnull id)eventDispatcher; -#endif // RCT_NEW_ARCH_ENABLED - (void)createGestureHandler:(nonnull NSString *)handlerName tag:(nonnull NSNumber *)handlerTag diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerManager.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerManager.mm index 7ee9de8e49..7d86f7d072 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerManager.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerManager.mm @@ -15,14 +15,10 @@ #import "RNGestureHandlerState.h" #import "RNRootViewGestureRecognizer.h" -#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import -#else -#import -#endif // RCT_NEW_ARCH_ENABLED #import "Handlers/RNFlingHandler.h" #import "Handlers/RNForceTouchHandler.h" @@ -52,17 +48,12 @@ @implementation RNGestureHandlerManager { NSHashTable *_rootViewGestureRecognizers; NSMutableDictionary *_attachRetryCounter; NSMutableSet *_droppedHandlers; -#ifdef RCT_NEW_ARCH_ENABLED RCTModuleRegistry *_moduleRegistry; RCTViewRegistry *_viewRegistry; -#else - RCTUIManager *_uiManager; -#endif // RCT_NEW_ARCH_ENABLED id _eventDispatcher; id _reanimatedModule; } -#ifdef RCT_NEW_ARCH_ENABLED - (RNGestureHandlerRegistry *)registry { return _registry; @@ -78,18 +69,6 @@ - (instancetype)initWithModuleRegistry:(RCTModuleRegistry *)moduleRegistry viewR } return self; } -#else -- (instancetype)initWithUIManager:(RCTUIManager *)uiManager - eventDispatcher:(id)eventDispatcher -{ - if ((self = [super init])) { - _uiManager = uiManager; - _eventDispatcher = eventDispatcher; - [self initCommonProps]; - } - return self; -} -#endif // RCT_NEW_ARCH_ENABLED - (void)initCommonProps { @@ -144,13 +123,8 @@ - (void)attachGestureHandler:(nonnull NSNumber *)handlerTag toViewWithTag:(nonnull NSNumber *)viewTag withActionType:(RNGestureHandlerActionType)actionType { -#ifdef RCT_NEW_ARCH_ENABLED RNGHUIView *view = [_viewRegistry viewForReactTag:viewTag]; -#else - RNGHUIView *view = [_uiManager viewForReactTag:viewTag]; -#endif // RCT_NEW_ARCH_ENABLED -#ifdef RCT_NEW_ARCH_ENABLED if (view == nil || view.superview == nil) { // There are a few reasons we could end up here: // - the native view corresponding to the viewtag hasn't yet been created @@ -197,7 +171,6 @@ - (void)attachGestureHandler:(nonnull NSNumber *)handlerTag view.reactTag = viewTag; // necessary for RNReanimated eventHash (e.g. "42onGestureHandlerEvent"), also will be // returned as event.target -#endif // RCT_NEW_ARCH_ENABLED [_registry attachHandlerWithTag:handlerTag toView:view withActionType:actionType]; @@ -245,7 +218,6 @@ - (id)handlerWithTag:(NSNumber *)handlerTag - (void)registerViewWithGestureRecognizerAttachedIfNeeded:(RNGHUIView *)childView { -#ifdef RCT_NEW_ARCH_ENABLED RNGHUIView *touchHandlerView = childView; #if !TARGET_OS_OSX @@ -262,31 +234,6 @@ - (void)registerViewWithGestureRecognizerAttachedIfNeeded:(RNGHUIView *)childVie } #endif // !TARGET_OS_OSX -#else - RNGHUIView *touchHandlerView = nil; - -#if !TARGET_OS_OSX - if ([[childView reactViewController] isKindOfClass:[RCTModalHostViewController class]]) { - touchHandlerView = [childView reactViewController].view.subviews[0]; - } else { - UIView *parent = childView; - while (parent != nil && ![parent respondsToSelector:@selector(touchHandler)]) { - parent = parent.superview; - } - - touchHandlerView = [[parent performSelector:@selector(touchHandler)] view]; - } -#else - NSView *parent = childView; - while (parent != nil && ![parent respondsToSelector:@selector(touchHandler)]) { - parent = parent.superview; - } - - touchHandlerView = [[parent performSelector:@selector(touchHandler)] view]; -#endif // !TARGET_OS_OSX - -#endif // RCT_NEW_ARCH_ENABLED - if (touchHandlerView == nil) { return; } @@ -323,25 +270,15 @@ - (void)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer // particular if we have one PanHandler and ScrollView that can work simultaniously then when // the Pan handler activates it would still tigger cancel events. // Once the upstream fix lands the line below along with this comment can be removed -#if TARGET_OS_OSX - if ([gestureRecognizer.view isKindOfClass:[NSScrollView class]]) { - return; - } -#else - if ([gestureRecognizer.view isKindOfClass:[UIScrollView class]]) { + if ([gestureRecognizer.view isKindOfClass:[RNGHScrollView class]]) { return; } -#endif UIGestureRecognizer *touchHandler = nil; // this way we can extract the touch handler on both architectures relatively easily for (UIGestureRecognizer *recognizer in [viewWithTouchHandler gestureRecognizers]) { -#ifdef RCT_NEW_ARCH_ENABLED if ([recognizer isKindOfClass:[RCTSurfaceTouchHandler class]]) { -#else - if ([recognizer isKindOfClass:[RCTTouchHandler class]]) { -#endif // RCT_NEW_ARCH_ENABLED touchHandler = recognizer; break; } @@ -440,18 +377,11 @@ - (void)sendNativeTouchEventForGestureHandler:(RNGestureHandler *)handler withPo - (void)sendEventForReanimated:(RNGestureHandlerStateChange *)event { // Delivers the event to Reanimated. -#ifdef RCT_NEW_ARCH_ENABLED - // Send event directly to Reanimated if (_reanimatedModule == nil) { _reanimatedModule = [_moduleRegistry moduleForName:"ReanimatedModule"]; } [_reanimatedModule eventDispatcherWillDispatchEvent:event]; -#else - // In the old architecture, Reanimated overwrites RCTEventDispatcher - // with REAEventDispatcher and intercepts all direct events. - [self sendEventForDirectEvent:event]; -#endif // RCT_NEW_ARCH_ENABLED } - (void)sendEventForNativeAnimatedEvent:(RNGestureHandlerStateChange *)event @@ -466,11 +396,7 @@ - (void)sendEventForNativeAnimatedEvent:(RNGestureHandlerStateChange *)event - (void)sendEventForJSFunctionOldAPI:(RNGestureHandlerStateChange *)event { // Delivers the event to JS (old RNGH API). -#ifdef RCT_NEW_ARCH_ENABLED [self sendEventForDeviceEvent:event]; -#else - [self sendEventForDirectEvent:event]; -#endif // RCT_NEW_ARCH_ENABLED } - (void)sendEventForJSFunctionNewAPI:(RNGestureHandlerStateChange *)event diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerModule.h b/packages/react-native-gesture-handler/apple/RNGestureHandlerModule.h index 684e4df6e5..fa8a7bec6d 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerModule.h +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerModule.h @@ -1,23 +1,13 @@ -#import -#import - -#ifdef RCT_NEW_ARCH_ENABLED #import +#import #import +#import #import -#else -#import -#endif #import "RNGestureHandlerManager.h" -@interface RNGestureHandlerModule : RCTEventEmitter -#ifdef RCT_NEW_ARCH_ENABLED - +@interface RNGestureHandlerModule : RCTEventEmitter + (RNGestureHandlerManager *)handlerManagerForModuleId:(int)moduleId; -#else - -#endif @end diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm index 16e227dd98..01a0740f4b 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerModule.mm @@ -7,14 +7,12 @@ #import #import -#ifdef RCT_NEW_ARCH_ENABLED #import #import #import #import #import #import -#endif // RCT_NEW_ARCH_ENABLED #import "RNGHRuntimeDecorator.h" @@ -31,15 +29,9 @@ using namespace facebook; using namespace react; -#ifdef RCT_NEW_ARCH_ENABLED @interface RNGestureHandlerModule () @end -#else -@interface RNGestureHandlerModule () - -@end -#endif // RCT_NEW_ARCH_ENABLED typedef void (^GestureHandlerOperation)(RNGestureHandlerManager *manager); @@ -55,7 +47,6 @@ @implementation RNGestureHandlerModule { bool _uiRuntimeDecorated; } -#ifdef RCT_NEW_ARCH_ENABLED @synthesize viewRegistry_DEPRECATED = _viewRegistry_DEPRECATED; static std::unordered_map _managers; @@ -65,8 +56,6 @@ + (RNGestureHandlerManager *)handlerManagerForModuleId:(int)moduleId return _managers[moduleId]; } -#endif // RCT_NEW_ARCH_ENABLED - RCT_EXPORT_MODULE() + (BOOL)requiresMainQueueSetup @@ -83,9 +72,6 @@ - (void)invalidate _managers[_moduleId] = nullptr; -#ifndef RCT_NEW_ARCH_ENABLED - [self.bridge.uiManager.observerCoordinator removeObserver:self]; -#endif // RCT_NEW_ARCH_ENABLED } - (dispatch_queue_t)methodQueue @@ -99,7 +85,6 @@ - (dispatch_queue_t)methodQueue return RCTGetUIManagerQueue(); } -#ifdef RCT_NEW_ARCH_ENABLED - (void)installJSIBindingsWithRuntime:(jsi::Runtime &)rnRuntime callInvoker:(const std::shared_ptr &)callinvoker { @@ -113,9 +98,7 @@ - (void)installJSIBindingsWithRuntime:(jsi::Runtime &)rnRuntime } }); } -#endif // RCT_NEW_ARCH_ENABLED -#ifdef RCT_NEW_ARCH_ENABLED - (void)initialize { static int nextModuleId = 0; @@ -124,18 +107,6 @@ - (void)initialize viewRegistry:_viewRegistry_DEPRECATED]; _operations = [NSMutableArray new]; } -#else -- (void)setBridge:(RCTBridge *)bridge -{ - [super setBridge:bridge]; - - _manager = [[RNGestureHandlerManager alloc] initWithUIManager:bridge.uiManager - eventDispatcher:bridge.eventDispatcher]; - _operations = [NSMutableArray new]; - - [bridge.uiManager.observerCoordinator addObserver:self]; -} -#endif // RCT_NEW_ARCH_ENABLED - (bool)installUIRuntimeBindings { @@ -207,7 +178,6 @@ - (void)flushOperations { // On the new arch we rely on `flushOperations` for scheduling the operations on the UI thread. // On the old arch we rely on `uiManagerWillPerformMounting` -#ifdef RCT_NEW_ARCH_ENABLED if (_operations.count == 0) { return; } @@ -221,7 +191,6 @@ - (void)flushOperations operation(manager); } }]; -#endif // RCT_NEW_ARCH_ENABLED } - (void)setGestureState:(int)state forHandler:(int)handlerTag @@ -275,34 +244,6 @@ - (void)addOperationBlock:(GestureHandlerOperation)operation [_operations addObject:operation]; } -#ifndef RCT_NEW_ARCH_ENABLED - -#pragma mark - RCTUIManagerObserver - -- (void)uiManagerWillFlushUIBlocks:(RCTUIManager *)uiManager -{ - [self uiManagerWillPerformMounting:uiManager]; -} - -- (void)uiManagerWillPerformMounting:(RCTUIManager *)uiManager -{ - if (_operations.count == 0) { - return; - } - - NSArray *operations = _operations; - _operations = [NSMutableArray new]; - - [uiManager - addUIBlock:^(__unused RCTUIManager *manager, __unused NSDictionary *viewRegistry) { - for (GestureHandlerOperation operation in operations) { - operation(self->_manager); - } - }]; -} - -#endif // RCT_NEW_ARCH_ENABLED - #pragma mark Events - (NSArray *)supportedEvents @@ -332,12 +273,10 @@ - (NSDictionary *)constantsToExport }; } -#if RCT_NEW_ARCH_ENABLED - (std::shared_ptr)getTurboModule: (const facebook::react::ObjCTurboModule::InitParams &)params { return std::make_shared(params); } -#endif @end diff --git a/packages/react-native-gesture-handler/apple/RNGestureHandlerRootViewComponentView.mm b/packages/react-native-gesture-handler/apple/RNGestureHandlerRootViewComponentView.mm index ef102a529f..7823e3643e 100644 --- a/packages/react-native-gesture-handler/apple/RNGestureHandlerRootViewComponentView.mm +++ b/packages/react-native-gesture-handler/apple/RNGestureHandlerRootViewComponentView.mm @@ -1,5 +1,3 @@ -#ifdef RCT_NEW_ARCH_ENABLED - #import Class RNGestureHandlerRootViewCls(void) @@ -17,5 +15,3 @@ // TODO: remove this file once `excludedPlatforms` option properly disables generating ShadowNode return nil; } - -#endif // RCT_NEW_ARCH_ENABLED diff --git a/packages/react-native-gesture-handler/apple/RNRootViewGestureRecognizer.m b/packages/react-native-gesture-handler/apple/RNRootViewGestureRecognizer.m index a2a2f182cf..474592d146 100644 --- a/packages/react-native-gesture-handler/apple/RNRootViewGestureRecognizer.m +++ b/packages/react-native-gesture-handler/apple/RNRootViewGestureRecognizer.m @@ -12,11 +12,7 @@ #import #endif -#ifdef RCT_NEW_ARCH_ENABLED #import -#else -#import -#endif // RCT_NEW_ARCH_ENABLED @implementation RNRootViewGestureRecognizer { BOOL _active; @@ -51,13 +47,7 @@ - (BOOL)shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGe - (BOOL)canPreventGestureRecognizer:(UIGestureRecognizer *)preventedGestureRecognizer { - return ![preventedGestureRecognizer isKindOfClass:[ -#ifdef RCT_NEW_ARCH_ENABLED - RCTSurfaceTouchHandler -#else - RCTTouchHandler -#endif - class]]; + return ![preventedGestureRecognizer isKindOfClass:[RCTSurfaceTouchHandler class]]; } - (BOOL)canBePreventedByGestureRecognizer:(UIGestureRecognizer *)preventingGestureRecognizer diff --git a/packages/react-native-gesture-handler/package.json b/packages/react-native-gesture-handler/package.json index 3dcc46b08f..62ef580437 100644 --- a/packages/react-native-gesture-handler/package.json +++ b/packages/react-native-gesture-handler/package.json @@ -15,8 +15,6 @@ "lint:js": "yarn lint-js", "lint:android": "./android/gradlew -p android spotlessCheck -q", "circular-dependency-check": "yarn madge --extensions js,ts,tsx --circular src", - "architectures-consistency-check": "node ../../scripts/codegen-check-consistency.js", - "sync-architectures": "node ../../scripts/codegen-sync-archs.js", "clean": "rm -rf node_modules android/build android/.cxx", "prepack": "cp ../../README.md ./README.md", "postpack": "rm ./README.md" @@ -36,14 +34,9 @@ "android/src/main/AndroidManifest.xml", "android/src/main/java/", "android/src/main/jni/", - "android/fabric/src/main/java", - "android/paper/src/main/java", - "android/paper77/src/main/java", "android/common/src/main/java/", "android/reanimated/src/main/java/", "android/noreanimated/src/main/java/", - "android/package77/", - "android/packageDeprecated/", "android/svg", "android/nosvg", "apple/", diff --git a/scripts/codegen-check-consistency.js b/scripts/codegen-check-consistency.js deleted file mode 100644 index 83ddabb4af..0000000000 --- a/scripts/codegen-check-consistency.js +++ /dev/null @@ -1,3 +0,0 @@ -const { checkCodegenIntegrity } = require('./codegen-utils'); - -checkCodegenIntegrity(); diff --git a/scripts/codegen-sync-archs.js b/scripts/codegen-sync-archs.js deleted file mode 100644 index 2829a58a28..0000000000 --- a/scripts/codegen-sync-archs.js +++ /dev/null @@ -1,3 +0,0 @@ -const { generateCodegenJavaOldArch } = require('./codegen-utils'); - -generateCodegenJavaOldArch(); diff --git a/scripts/codegen-utils.js b/scripts/codegen-utils.js deleted file mode 100644 index a952287110..0000000000 --- a/scripts/codegen-utils.js +++ /dev/null @@ -1,150 +0,0 @@ -const fs = require('fs'); -const path = require('path'); -const { execSync } = require('child_process'); -const packageJSON = require('../packages/react-native-gesture-handler/package.json'); - -const ERROR_PREFIX = 'react-native-gesture-handler'; -const ROOT_DIR = path.resolve( - __dirname, - '../packages/react-native-gesture-handler' -); -const ANDROID_DIR = path.resolve(ROOT_DIR, 'android'); -const GENERATED_DIR = path.resolve(ANDROID_DIR, 'build/generated'); -const OLD_ARCH_DIR = path.resolve(ANDROID_DIR, 'paper/src/main'); -const SPECS_DIR = path.resolve(ROOT_DIR, packageJSON.codegenConfig.jsSrcsDir); -const PACKAGE_NAME = packageJSON.codegenConfig.android.javaPackageName; -const RN_DIR = path.resolve(__dirname, '../node_modules/react-native'); -const RN_CODEGEN_DIR = path.resolve( - __dirname, - '../node_modules/@react-native/codegen' -); - -const SOURCE_FOLDER = 'java/com/facebook/react/viewmanagers'; -const GH_SOURCE_FOLDER = 'java/com/swmansion/gesturehandler'; - -const SOURCE_FOLDERS = [ - { - codegenPath: `${GENERATED_DIR}/source/codegen/${SOURCE_FOLDER}`, - oldArchPath: `${OLD_ARCH_DIR}/${SOURCE_FOLDER}`, - }, - { - codegenPath: `${GENERATED_DIR}/source/codegen/${GH_SOURCE_FOLDER}`, - oldArchPath: `${OLD_ARCH_DIR}/${GH_SOURCE_FOLDER}`, - }, -]; - -const BLACKLISTED_FILES = new Set(['ReactContextExtensions.kt']); - -function exec(command) { - console.log(`[${ERROR_PREFIX}]> ` + command); - execSync(command); -} - -function readdirSync(dir) { - return fs.readdirSync(dir).filter((file) => !BLACKLISTED_FILES.has(file)); -} - -function fixOldArchJavaForRN72Compat(dir) { - // see https://github.com/rnmapbox/maps/issues/3193 - const files = readdirSync(dir); - files.forEach((file) => { - const filePath = path.join(dir, file); - const fileExtension = path.extname(file); - if (fileExtension === '.java') { - let fileContent = fs.readFileSync(filePath, 'utf-8'); - let newFileContent = fileContent.replace( - /extends ReactContextBaseJavaModule implements TurboModule/g, - 'extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule' - ); - if (fileContent !== newFileContent) { - // also insert an import line with `import com.facebook.react.bridge.ReactModuleWithSpec;` - newFileContent = newFileContent.replace( - /import com.facebook.react.bridge.ReactMethod;/, - 'import com.facebook.react.bridge.ReactMethod;\nimport com.facebook.react.bridge.ReactModuleWithSpec;' - ); - - console.log(' => fixOldArchJava applied to:', filePath); - fs.writeFileSync(filePath, newFileContent, 'utf-8'); - } - } else if (fs.lstatSync(filePath).isDirectory()) { - fixOldArchJavaForRN72Compat(filePath); - } - }); -} - -async function generateCodegen() { - exec(`rm -rf ${GENERATED_DIR}`); - exec(`mkdir -p ${GENERATED_DIR}/source/codegen/`); - - exec( - `node ${RN_CODEGEN_DIR}/lib/cli/combine/combine-js-to-schema-cli.js --platform android ${GENERATED_DIR}/source/codegen/schema.json ${SPECS_DIR}` - ); - exec( - `node ${RN_DIR}/scripts/generate-specs-cli.js --platform android --schemaPath ${GENERATED_DIR}/source/codegen/schema.json --outputDir ${GENERATED_DIR}/source/codegen --javaPackageName ${PACKAGE_NAME}` - ); - - fixOldArchJavaForRN72Compat(`${GENERATED_DIR}/source/codegen/java/`); -} - -async function generateCodegenJavaOldArch() { - await generateCodegen(); - - SOURCE_FOLDERS.forEach(({ codegenPath, oldArchPath }) => { - const generatedFiles = readdirSync(codegenPath); - const oldArchFiles = readdirSync(oldArchPath); - const existingFilesSet = new Set(oldArchFiles.map((fileName) => fileName)); - - generatedFiles.forEach((generatedFile) => { - if (!existingFilesSet.has(generatedFile)) { - console.warn( - `[${ERROR_PREFIX}] ${generatedFile} not found in paper dir, if it's used on Android you need to copy it manually and implement yourself before using auto-copy feature.` - ); - } - }); - - if (oldArchFiles.length === 0) { - console.warn( - `[${ERROR_PREFIX}] Paper destination with codegen interfaces is empty. This might be okay if you don't have any interfaces/delegates used on Android, otherwise please check if OLD_ARCH_DIR and SOURCE_FOLDERS are set properly.` - ); - } - - oldArchFiles.forEach((file) => { - if (!fs.existsSync(`${codegenPath}/${file}`)) { - console.warn( - `[${ERROR_PREFIX}] ${file} file does not exist in codegen artifacts source destination. Please check if you still need this interface/delagete.` - ); - } else { - const filesTheSame = compareFileAtTwoPaths(file, codegenPath, oldArchPath); - exec(`cp -rf ${codegenPath}/${file} ${oldArchPath}/${file}`); - - if (!filesTheSame) { - exec(`git add ${oldArchPath}/${file}`); - } - } - }); - }); -} - -function compareFileAtTwoPaths(filename, firstPath, secondPath) { - const fileA = fs.readFileSync(`${firstPath}/${filename}`, 'utf-8'); - const fileB = fs.readFileSync(`${secondPath}/${filename}`, 'utf-8'); - - return fileA === fileB -} - -async function checkCodegenIntegrity() { - await generateCodegen(); - - SOURCE_FOLDERS.forEach(({ codegenPath, oldArchPath }) => { - const oldArchFiles = readdirSync(oldArchPath); - oldArchFiles.forEach((file) => { - if (!compareFileAtTwoPaths(file, codegenPath, oldArchPath)) { - throw new Error( - `[${ERROR_PREFIX}] File ${file} is different at ${codegenPath} and ${oldArchPath}. Make sure you committed codegen autogenerated files.` - ); - } - }); - }); -} - -module.exports = { generateCodegenJavaOldArch, checkCodegenIntegrity };