software-mansion / react-native-reanimated

React Native's Animated library reimplemented
https://docs.swmansion.com/react-native-reanimated/
MIT License
8.84k stars 1.29k forks source link

Fails to build on react-native-macos 0.74.1 #6421

Open hsjoberg opened 4 weeks ago

hsjoberg commented 4 weeks ago

Description

Hi. When trying to build react-native-reanimated with react-native-macos 0.74.1, the following syntax error is encountered in REASizzledManager.mm#L235 and in other places.

Cannot initialize return object of type 'RCTViewManagerUIBlock' (aka 'void (^)(RCTUIManager *__strong, NSDictionary<NSNumber *,NSView *> *__strong)') with an rvalue of type 'void (^)(RCTUIManager *__strong, NSDictionary<NSNumber *,REAUIView *> *__strong)'

Simply changing REAUIView to NSView everywhere where the compiler complains seems to fix the issue. But I don't know react-native-reanimated's inner workings well enough to understand if this is a sane approach. If yes, I can submit a PR.

Also, react-native-gesture-handler has a similar issue as this one. I could file a bug report there too if needed.

Steps to reproduce

Try to build the demo project to see the issue.

Due to an unrelated issue in react-native-macos 0.74.1 https://github.com/microsoft/react-native-macos/issues/2165, you may have to clear out the build phase script [CP-User] [RN]Check rncore in the React-Fabric pod before building.

Snack or a link to a repository

https://github.com/hsjoberg/rnmacos74/tree/reanimated (reanimated branch)

Reanimated version

3.15.0

React Native version

0.74.1

Platforms

macOS

JavaScript runtime

JSC

Workflow

React Native

Architecture

Paper (Old Architecture)

Build type

None

Device

Real device

Device model

No response

Acknowledgements

Yes

hsjoberg commented 1 week ago

It seems like NSView is being expected somewhere instead of REAUIView (which is a typedef of RCTUIView for macOS, not NSView), but I cannot quite figure out where.

hsjoberg commented 1 week ago

The issue is essentially that RCTViewManagerUIBlock that's being used as arg to reanimated_addUIBlock() expects UIView in react-native and NSView in react-native-macos, but reanimated's REAUIView is typedef'd as RCTUIView on macos. It's therefore incorrectly used here: https://github.com/software-mansion/react-native-reanimated/blob/c7f4b5f9b1157a31da289f9065961ac526f96bf1/packages/react-native-reanimated/apple/reanimated/LayoutReanimation/REASwizzledUIManager.mm#L374-L376

RCTViewManagerUIBlock: react-native (iOS): https://github.com/facebook/react-native/blob/ade863a48cd78039dd68e7176e339cdaca3b0f74/packages/react-native/React/Views/RCTViewManager.h#L22

react-native-macos: https://github.com/microsoft/react-native-macos/blob/042cd6c36b23c21d20de628bc9756793e01ce282/packages/react-native/React/Views/RCTViewManager.h#L22 (RCTPlatformView in turn defined as NSView: https://github.com/microsoft/react-native-macos/blob/042cd6c36b23c21d20de628bc9756793e01ce282/packages/react-native/React/Base/RCTUIKit.h#L382).

hsjoberg commented 1 week ago

Okay, I've quick & dirty fixes for react-native-reanimated and react-native-gesture-handler here:

https://github.com/hsjoberg/react-native-reanimated/tree/rn75fix https://github.com/hsjoberg/react-native-gesture-handler/tree/rn75fix

Just using #ifdef to output NSView or UIView.

I don't know the proper solution here but I'm happy to make a PR if someone would give some directions.