How to create a React Native component using ARKit / a swift ViewController?

Viewed 338

We have a project based on the swift based ARKit example Capturing Body Motion in 3D from the WWDC 2019. And we have a React Native app using native swift components, following the great instructions from Swift in React Native - The Ultimate Guide. Now we want to implement the view from the ARKit example as a react-native component, but I just don't find out how to do this.

The ARKit example uses a UIViewController with ARSessionDelegate, which means we have to wrap more than a simple view in the component.

I found some answers on how to present a native UIViewController in React Native, but could not translate this solution into swift code and could not get it to work with the ARKit example. Does anybody of you have an idea how to wire this up?

1 Answers

Ok, I understand it by now ;-)

In the example Capturing Body Motion in 3D all functionality is implemented in the UIViewController. We do not have separate UIViewController for each component in react native, we have RCTViewManager instead.

We can create our own View class, based on ARView and move the ARSessionDelegate from the UIViewController directly to this new view, including the session method and all corresponding parts. An instance of this new View van be returned from the RCTViewManager and voila, it works!

Related