-
Notifications
You must be signed in to change notification settings - Fork 24.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bridgeless][IOS] bridge
is nil
on Swift when NewArch is enabled
#45232
Comments
nil
on Swift when NewArch is enabledbridge
is nil
on Swift when NewArch is enabled
Hi @lodev09, thanks for maintaining a library for React Native and thank you for the issue. There are two questions that I need to ask you:
My guess is that nobody is setting the bridge in the I'll have a look at it later today or tomorrow. |
Hmmm, interesting. I'm wondering how the RN Modal works on bridgeless then? It uses exactly the same code to set the TouchHandler -- the only difference is that my library is written in swift.
I'm trying to run it through Interop layer first and then ultimately fabric. As I mentioned, everything works fine aside from the bridge being I just need the TouchHandler to work on New Arch :/ |
RN Modals are actually already migrated to Fabric. When you run the new architecture, the component that is loaded is this one. |
Ok, I got the issue. I'll work on a fix as there could be other libraries that rely on the bridge property to be set and it is currently not set in the interop layer. I hope I'll be able to send the fix out before EOW. |
Okay.. thank you so much @cipolleschi 🙏 |
Quick question: If I understand correctly, swift is not yet supported for Fabric components right? |
Summary: Thanks to [facebook#45232](facebook#45232) we found a bug in the interop layer, where we were not passing the BridgeProxy in bridgeless mode to the view managers. This Change should fix that issue. ## Changelog: [iOS][Fixed] - Make sure to pass the RCTBridgeProxy to ViewManagers Differential Revision: D59468292
Tricky question! However, you can create a thin wrapper in objective-c++ and then forward the various calls to Swift. We haven't experimented with that setup a lot, and we are aware that there are some things that are not compatible and that will require some wrapping to make them work in Swift. |
So.. #45329 should fix the crash. But, from what I am seeing, the buttons are not tappable... :/ |
Yeah.. I use the bridge to mainly |
I need to ask around and investigate... I'll keep you posted! |
That was quick... xD
I made a quick experiment in // ...
class TrueSheetView: UIView, RCTInvalidating, TrueSheetViewControllerDelegate {
//...
private var touchHandler: RCTTouchHandler
+ private var surfaceTouchHandler: RCTSurfaceTouchHandler
// ..
init(with bridge: RCTBridge) {
// ...
touchHandler = RCTTouchHandler(bridge: bridge)
+ surfaceTouchHandler = RCTSurfaceTouchHandler()
//...
override func insertReactSubview(_ subview: UIView!, at index: Int) {
// ...
containerView = subview
- touchHandler.attach(to: containerView)
+ touchHandler.attach(to: subview)
+ surfaceTouchHandler.attach(to: subview)
}
//..
override func removeReactSubview(_ subview: UIView!) {
//...
touchHandler.detach(from: subview)
+ surfaceTouchHandler.detach(from: subview)
//... And, of course, adding the following in the bridging header #import <React/RCTTouchHandler.h>
+ #import <React/RCTSurfaceTouchHandler.h>
#import <React/RCTScrollView.h> Simulator.Screen.Recording.-.iPhone.15.Pro.-.2024-07-08.at.18.25.59.mp4sizings looks a bit off, though... :( |
Wow thank you! :D
Yeah, looks like |
It turns out, that method was not implemented in the interop layer for Bridgeless. I'll try to work on that tomorrow! |
You're awesome @cipolleschi. Thank you so much! |
Thank you for reporting the issue and for providing a way for me to work on that! (Anyway... start thinking about migrating it to Fabric! 😅 It will be needed, at some point! Happy to help there as well) |
@cipolleschi yes, I'm really eager to migrate it to fabric -- it's just a bummer that swift isn't supported out of the box. But we'll get there 💪 |
This is my first native ios/android project so I'm not 100% familiar with all this yet 😅 |
…er (#45329) Summary: Pull Request resolved: #45329 Thanks to [#45232](#45232) we found a bug in the interop layer, where we were not passing the BridgeProxy in bridgeless mode to the view managers. This Change should fix that issue. ## Changelog: [iOS][Fixed] - Make sure to pass the RCTBridgeProxy to ViewManagers Reviewed By: dmytrorykun Differential Revision: D59468292 fbshipit-source-id: 00666be21385a735878eb567c4b8a0986c609c5f
@lodev09 I looked into this issue a little bit more. The reason why it hasn't been implemented in the Interop Layer is architectural. In the New Architecture, we have a shadow tree implementation in C++. In the New Architecture, the Shadow Tree drives everything and it creates the Native tree. The Native views don't have a handle to get the shadow views anymore and they can't really change the layout from the Native layer. Due to this, we cannot really port the My suggestion would be to migrate your library to Fabric properly and support both architectures. We have some guides on how to do it: And you can use the New Architecture implementation of the React Native Modal component as base implementation for the Fabric version of it. I would also love to help with review and suggestions on how to bridge ObjC++ with Swift. I made some experiments with modules in the past, here and here, but I never had the time to try with Componentes. I hope these pointers can help you move forward with this. |
@cipolleschi I see. I'm going to implement an alternative approach to updating the size as a short term solution for now, maybe in the JS side. I agree with migrating to Fabric for the long term. I might just convert it all to ObjC 😅 Anyways, thanks again for your help! |
…er (#45329) Summary: Pull Request resolved: #45329 Thanks to [#45232](#45232) we found a bug in the interop layer, where we were not passing the BridgeProxy in bridgeless mode to the view managers. This Change should fix that issue. ## Changelog: [iOS][Fixed] - Make sure to pass the RCTBridgeProxy to ViewManagers Reviewed By: dmytrorykun Differential Revision: D59468292 fbshipit-source-id: 00666be21385a735878eb567c4b8a0986c609c5f
Description
I maintain a native component library and trying to make it work with New Architecture interop. It builds without problem. However, the
bridge
in the view manager instance isnil
and causing the component to crash.To give context, the library is similar to RN Modal where it uses the view component as a host view of a view controller. It needs the
bridge
to attachRCTTouchHandler
to the container view. The library is written inswift
. https://github.com/lodev09/react-native-true-sheetAny ideas or I'm missing something?
Steps to reproduce
example/app.json
and setnewArchEnabled: true
at line38
React Native Version
0.74.2
Affected Platforms
Runtime - iOS
Areas
Bridgeless - The New Initialization Flow
Output of
npx react-native info
Stacktrace or Logs
Reproducer
https://github.com/lodev09/react-native-true-sheet/tree/main/example
Screenshots and Videos
The text was updated successfully, but these errors were encountered: