Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

Is it possible to use React's RCTViewManager without Objective C?

$
0
0

I'm currently trying to bridge my React Native application to an Objective C library that uses alarge dynamic framework that has Objective C headers. There is also an Objective C demo application that I'm referencing.

I know that I can do this in Objective C, but I would like to write all new code in Swift since this is a rather large project that I'd like to be maintainable. Is it possible to use Swift (only) as a bridge to React Native's RCTViewManager so that I can display native iOS views?

Currently, I've had to create an implementation class (.m) for RCTViewManager, a corresponding header (.h), a bridging header (.h), and the swift code for the UIView (.swift) I want to customize - all to create an RCTView via an RCTViewManager in Swift that can be accessed by requireNativeComponent. Since I actually need dozens of specialized native RCTViews, this is quite cumbersome.

Here is some Swift code I tried:

class CustomViewZeroManager: RCTViewManager{  override func view() -> UIView!  {    let player = LCOpenSDK_PlayWindow.init(playWindow: CGRect(x: 0, y: 0, width: 375, height: 211), index: 0)    player!.playRtspReal("", devID: "", psk: "", channel: 0, definition: 1)    return player!.getView()  }}

As I try this, I am coming across the error "Invariant Violation: requireNativeComponent: "CustomViewZero" was not found in the UIManager.

I assume this is because the macro used to export the module (RCT_EXPORT_MODULE) and do the automatic name resolution is not present in the Swift file. I believe macros are not a feature in Swift, so is there any way or example I could use to bridge an RCTView (via RCTViewManager), or write an RCTBridgeModule without Objective C, and Swift only?


Viewing all articles
Browse latest Browse all 16750

Trending Articles