react-native: Unable to create new ReactRootView/RCTRootView when bridgeless is enabled
Description
Where I work we develop an SDK that allows customers to place AR Overlays on top of recognized barcodes. We have a JS component that the user needs to extend and create a component on JS side as they want. We serialize this to JS and on native side we create a view using the ReactRootView on Android and RCTRootView on iOS.
This is the code we use on Android to create a native view from the JS component:
fun nativeViewFromJson(currentActivity: Activity, viewJson: String?): View? {
UiThreadUtil.assertOnUiThread()
val viewJson = viewJson ?: return null
val viewJsonObject = JSONObject(viewJson)
val reactInstanceManager = (currentActivity.application as ReactApplication)
.reactNativeHost
.reactInstanceManager
return ReactRootView(currentActivity).apply {
startReactApplication(
reactInstanceManager,
viewJsonObject.moduleName,
viewJsonObject.initialProperties
)
layoutParams = ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT)
}
}
and this on iOS:
func rootViewWith(jsView: JSView) -> ScanditRootView {
// To support self sizing js views we need to leverage the RCTRootViewDelegate
// see https://reactnative.dev/docs/communication-ios
let view = ScanditRootView(bridge: bridge,
moduleName: jsView.moduleName,
initialProperties: jsView.initialProperties)
view.sizeFlexibility = .widthAndHeight
view.delegate = self
view.backgroundColor = .clear
view.isUserInteractionEnabled = true
view.addGestureRecognizer(TapGestureRecognizerWithClosure { [weak view] in
guard let view = view else { return }
view.didTap?()
})
return view
}
extension ScanditDataCaptureBarcodeBatch: RCTRootViewDelegate {
func rootViewDidChangeIntrinsicSize(_ rootView: RCTRootView!) {
guard let view = rootView as? ScanditRootView else { return }
rootView.bounds.size = rootView.intrinsicContentSize
guard let trackedBarcode = trackedBarcodeViewCache[view] else {
// Barcode was lost before the view updated its size.
return
}
barcodeBatchModule.setViewForTrackedBarcode(view: view,
trackedBarcodeId: trackedBarcode.identifier,
sessionFrameSequenceId: nil)
}
}
public class ScanditRootView: RCTRootView, TappableView {
public var didTap: (() -> Void)?
}
I have investigated this and noticed that the crash happens only when bridgelessEnabled is enabled. By disabling bridgelessEnabled on App load everything works fine.
It could be that I am doing something wrong, or what we were doing before isn’t working anymore with the new architecture, but we need to be compatible with react-native >= 0.60.0 and for this reason cannot fully move to the new architecture. Could you help us better understand the issue? Could you help us to make it work also when bridgeless is enabled?
Thanks a lot.
Steps to reproduce
- Install the deps of app
- Run android
- Point it to a barcode
- It will crash.
React Native Version
0.79.0-rc.3, 0.78.X
Affected Platforms
Runtime - Android
Areas
Other (please specify)
Output of npx @react-native-community/cli info
info Fetching system and libraries information...
System:
OS: macOS 15.3.2
CPU: (10) arm64 Apple M1 Pro
Memory: 260.20 MB / 32.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 18.19.1
path: ~/.nvm/versions/node/v18.19.1/bin/node
Yarn:
version: 1.22.22
path: ~/.nvm/versions/node/v18.19.1/bin/yarn
npm:
version: 10.2.4
path: ~/.nvm/versions/node/v18.19.1/bin/npm
Watchman:
version: 2024.04.15.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.16.2
path: /Users/ilber/.rbenv/shims/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.2
- iOS 18.2
- macOS 15.2
- tvOS 18.2
- visionOS 2.2
- watchOS 11.2
Android SDK:
API Levels:
- "22"
- "23"
- "27"
- "28"
- "29"
- "30"
- "31"
- "32"
- "33"
- "34"
- "35"
Build Tools:
- 22.0.1
- 28.0.3
- 29.0.3
- 30.0.2
- 30.0.3
- 33.0.0
- 33.0.1
- 33.0.3
- 34.0.0
- 35.0.0
System Images:
- android-34 | Google Play ARM 64 v8a
- android-35 | AOSP ATD Intel x86_64 Atom
- android-35 | Intel x86_64 Atom
Android NDK: Not Found
IDEs:
Android Studio: 2024.3 AI-243.22562.218.2431.13114758
Xcode:
version: 16.2/16C5032a
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.11
path: /Users/ilber/.sdkman/candidates/java/current/bin/javac
Ruby:
version: 3.2.1
path: /Users/ilber/.rbenv/shims/ruby
npmPackages:
"@react-native-community/cli":
installed: 18.0.0
wanted: 18.0.0
react:
installed: 19.0.0
wanted: 19.0.0
react-native:
installed: 0.79.0-rc.3
wanted: 0.79.0-rc.3
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: true
iOS:
hermesEnabled: true
newArchEnabled: true
Stacktrace or Logs
---------------------------- PROCESS STARTED (30995) for package com.scandit.matrixscanbubblessample ----------------------------
2025-03-25 13:01:11.782 527-527 audit auditd E type=1327 audit(1742904071.777:3107): proctitle="com.scandit.matrixscanbubblessample"
2025-03-25 13:01:12.012 30995-31180 AndroidRuntime com.scandit.matrixscanbubblessample E FATAL EXCEPTION: mqt_native_modules (Ask Gemini)
Process: com.scandit.matrixscanbubblessample, PID: 30995
java.lang.RuntimeException: Could not invoke UIManager.createView
at com.facebook.react.bridge.JavaMethodWrapper.invoke(SourceFile:189)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(SourceFile:20)
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(SourceFile:6)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.startNewBackgroundThread$lambda$1(SourceFile:39)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.a(SourceFile:1)
at com.facebook.react.bridge.queue.c.run(SourceFile:1)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(SourceFile:151)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(SourceFile:20)
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(SourceFile:6)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.startNewBackgroundThread$lambda$1(SourceFile:39)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.a(SourceFile:1)
at com.facebook.react.bridge.queue.c.run(SourceFile:1)
at java.lang.Thread.run(Thread.java:920)
Caused by: java.lang.AssertionError: Root node with tag 61 doesn't exist
at V0.a.d(SourceFile:6)
at com.facebook.react.uimanager.H0.j(SourceFile:41)
at com.facebook.react.uimanager.UIManagerModule.createView(SourceFile:54)
at java.lang.reflect.Method.invoke(Native Method)
at com.facebook.react.bridge.JavaMethodWrapper.invoke(SourceFile:151)
at com.facebook.react.bridge.JavaModuleWrapper.invoke(SourceFile:20)
at com.facebook.jni.NativeRunnable.run(Native Method)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(SourceFile:6)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.startNewBackgroundThread$lambda$1(SourceFile:39)
at com.facebook.react.bridge.queue.MessageQueueThreadImpl$Companion.a(SourceFile:1)
at com.facebook.react.bridge.queue.c.run(SourceFile:1)
at java.lang.Thread.run(Thread.java:920)
---------------------------- PROCESS ENDED (30995) for package com.scandit.matrixscanbubblessample ----------------------------
Reproducer
https://github.com/ilber/datacapture-react-native-samples/tree/master/MatrixScanBubblesSample
Screenshots and Videos
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (8 by maintainers)
Thanks a lot @cipolleschi . Sorry for the late reply but I was OOO for a bit. Will come to this soon and let you know. Thanks again.
There is no equivalent for Android, sadly. Also, iOS and Android are a bit different in that respect. I’m not sure that Android has the same concept of Surfaces. @cortinico will know more about it.