microsoft / react-native-macos

A framework for building native macOS apps with React.
https://microsoft.github.io/react-native-windows/
MIT License
3.49k stars 135 forks source link

fix: Allow viewRegistry to accept subclasses of NSView #2196

Closed Saadnajmi closed 2 weeks ago

Saadnajmi commented 2 weeks ago

Summary:

In React Native macOS, we have two "shim" classes to help make the iOS codebase of React Native compatible with macOS

Additionally, in React Native's old architecture, there is this line that we forked as follows in 0.73 and earlier versions:

React Native:

typedef void (^RCTViewManagerUIBlock)(RCTUIManager uiManager, NSDictionary<NSNumber , UIView > viewRegistry);

React Native macOS:

typedef void (^RCTViewManagerUIBlock)(RCTUIManager uiManager, NSDictionary<NSNumber , **RCTUIView**> viewRegistry); // [macOS]`

In React Native macOS 0.74+, I changed the definition as follows, thinking the widening of scope to a superclass would be a non breaking change:

typedef void (^RCTViewManagerUIBlock)(RCTUIManager uiManager, NSDictionary<NSNumber , **RCTPlatformView**> viewRegistry); // [macOS]`

Turns out I was wrong, and this broke libraries like Reanimated and React Native Gesture Handler. The fix is simple, add a __kindof in front of the type!

typedef void (^RCTViewManagerUIBlock)(RCTUIManager uiManager, NSDictionary<NSNumber , **__kindof RCTPlatformView**> viewRegistry); // [macOS]`

Test Plan:

Tested this in my branch where I'm adding macOS support to react-native-webgpu (https://github.com/wcandillon/react-native-webgpu/pull/123), and reanimated + gesture gesture handler compile successfully.