software-mansion / react-native-gesture-handler

Declarative API exposing platform native touch and gesture system to React Native.
https://docs.swmansion.com/react-native-gesture-handler/
MIT License
6.12k stars 981 forks source link

react-native-gesture-handler fails to build on react-native-macos with new architecture #3144

Closed hsjoberg closed 1 month ago

hsjoberg commented 1 month ago

Description

Hi, react-native-gesture-handler cannot be built on react-native-macos with new architecture enabled.

image

This is due to iOS environment being expected in RNGestureHandlerButtonComponentView.h.

Furthermore, even when importing AppKit instead for macOS, there are more issues in RNGestureHandlerButtonComponentView.mm, where UIView is used instead of the platform-independent RNGHUIView.

However, I don't know how to fix [_buttonView mountChildComponentView:childComponentView index:index]; simply not working (existing?) on macOS. No visible @interface for 'RNGestureHandlerButton' declares the selector 'mountChildComponentView:index:'

https://github.com/software-mansion/react-native-gesture-handler/blob/a6741a920718f35d04cccf621737a146eeff370d/apple/RNGestureHandlerButtonComponentView.mm#L43-L46

This line does work either with error No visible @interface for 'RNGestureHandlerButton' declares the selector 'updateLayoutMetrics:oldLayoutMetrics:':

https://github.com/software-mansion/react-native-gesture-handler/blob/a6741a920718f35d04cccf621737a146eeff370d/apple/RNGestureHandlerButtonComponentView.mm#L85

See repro here: https://github.com/hsjoberg/gesturehandlernewarchbug

Steps to reproduce

Please see my repro. But to do manually; start a new react-native community CLI project, initialize react-native-macos and add react-native-gesture handler to observe the error.

npx @react-native-community/cli init gesturehandlernewarchbug

cd gesturehandlernewarchbug/

yarn add react-native-macos@^0.75.0

npx react-native-macos-init

yarn add react-native-gesture-handler

cd macos

RCT_NEW_ARCH_ENABLED=1 pod install

# then start macos app via xcode or metro

Note: you may have to add bundleUrl fix too: https://github.com/microsoft/react-native-macos/issues/2164#issuecomment-2294816367

Snack or a link to a repository

https://github.com/hsjoberg/gesturehandlernewarchbug

Gesture Handler version

2.20.0

React Native version

0.75

Platforms

MacOS

JavaScript runtime

JSC

Workflow

React Native (without Expo)

Architecture

Fabric (New Architecture)

Build type

Debug mode

Device

None

Device model

macOS

Acknowledgements

Yes

m-bert commented 1 month ago

Hi @hsjoberg! Could you please check if #3154 resolves this issue?

hsjoberg commented 1 month ago

Hi @m-bert, thank you for taking the time to fix this one. I will test the PR.