react-native-screens: App Crashes with message "-[RCTView setSheetLargestUndimmedDetent:]: unrecognized selector sent to instance"
Description
Problem
First of all, I’ve integrated ReactNative with my iOS native App. There is no problem with using the basic components of ReactNative. However, when I register RootStackNavigator as an entryPoint, the app crashes with the following error:
-[RCTView setSheetLargestUndimmedDetent:]: unrecognized selector sent to instance
As I said above, my app is based on iOS, and only a few screens are implemented with ReactNative. so I had to implement my custom BridgeManager which returns rootViewFactory to render ReactNative View.
React Native Code Example:
index.js
const { AppRegistry } = require('react-native')
import 'react-native-gesture-handler'
import 'react-native-reanimated'
import NoticeRootStackNavigator from './src/navigation/notice/NoticeRootStackNavigator'
AppRegistry.registerComponent('NoticeList', () => NoticeRootStackNavigator)
NoticeRootStackNavigator
export type NoticeStackParamList = {
NoticeList: undefined;
NoticeDetail: undefined;
}
export type NoticeNavigationProp = StackNavigationProp<NoticeStackParamList>;
const NoticeStack = createStackNavigator<NoticeStackParamList>();
const NoticeRootStackNavigator = () => {
const screenOptions = useNavigatorScreenOptions();
return (
<NavigationContainer>
<NoticeStack.Navigator screenOptions={screenOptions} initialRouteName="NoticeList">
<NoticeStack.Screen name="NoticeList" component={NoticeList} />
<NoticeStack.Screen name="NoticeDetail" component={NoticeDetail} />
</NoticeStack.Navigator>
</NavigationContainer>
);
}
export default memo(NoticeRootStackNavigator);
iOS Code Example
CustomRCTBridgeManager.mm
#import "CustomRCTBridgeManager.h"
#import "RCTAppSetupUtils.h"
#import <React/RCTComponentViewFactory.h>
#import <React/CoreModulesPlugins.h>
@interface CustomRCTBridgeManager () <RCTTurboModuleManagerDelegate>
@end
@implementation CustomRCTBridgeManager
+ (instancetype)shared {
static CustomRCTBridgeManager *shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared = [[self alloc] init];
});
return shared;
}
- (instancetype)init {
self = [super init];
if (self) {
[self configureBridge];
}
return self;
}
- (void)configureBridge {
_rootViewFactory = [self createRCTRootViewFactory];
_bridge = _rootViewFactory.bridge;
}
- (UIView *)createRootView: (NSString *)moduleName andInitialProperties:(NSDictionary * _Nullable)initialProperties {
if (initialProperties == nil) {
initialProperties = self.initialProps;
}
return [self.rootViewFactory viewWithModuleName:moduleName
initialProperties:initialProperties
launchOptions:nil];
}
- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge {
#if DEBUG
return [NSURL URLWithString:@"http://localhost:8081/index.bundle?platform=ios"];
#else
return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}
#pragma mark - New Arch Enabled settings
- (BOOL)newArchEnabled
{
#if RCT_NEW_ARCH_ENABLED
return YES;
#else
return NO;
#endif
}
- (BOOL)turboModuleEnabled
{
return [self newArchEnabled];
}
- (BOOL)fabricEnabled
{
return [self newArchEnabled];
}
- (BOOL)bridgelessEnabled
{
return [self newArchEnabled];
}
#pragma mark - RCTTurboModuleManagerDelegate
- (id<RCTTurboModule>)getModuleInstanceFromClass:(Class)moduleClass
{
return RCTAppSetupDefaultModuleFromClass(moduleClass);
}
- (Class)getModuleClassFromName:(const char *)name {
#if RN_DISABLE_OSS_PLUGIN_HEADER
return RCTTurboModulePluginClassProvider(name);
#else
return RCTCoreModulesClassProvider(name);
#endif
}
- (RCTRootViewFactory *)createRCTRootViewFactory
{
__weak __typeof(self) weakSelf = self;
RCTBundleURLBlock bundleUrlBlock = ^{
return [weakSelf sourceURLForBridge:weakSelf.bridge];
};
RCTRootViewFactoryConfiguration *configuration =
[[RCTRootViewFactoryConfiguration alloc] initWithBundleURLBlock:bundleUrlBlock
newArchEnabled:self.fabricEnabled
turboModuleEnabled:self.turboModuleEnabled
bridgelessEnabled:self.bridgelessEnabled];
return [[RCTRootViewFactory alloc] initWithConfiguration:configuration andTurboModuleManagerDelegate:self];
}
@end
NoticeViewController
final class NoticeListViewController: ReactNativeViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationItem.title = "NoticeList"
configureRCTView()
}
private func configureRCTView() {
guard let bridgeManager = QandaRCTBridgeManager.shared() else { return }
let reactView = bridgeManager.createRootView(ReactNativeScreen.notice, andInitialProperties: nil)
self.view = reactView
}
}
Steps to reproduce
- enable new architecture by running
RCT_NEW_ARCH_ENABLED=1 bundle exec pod install - navigate to ViewController which it’s view is RNScreen
- it successfully loads bundle from metro server
- after loading finished, app crashes.
Snack or a link to a repository
sorry it’s my company’s private repo
Screens version
3.31.1
React Native version
0.74.2
Platforms
iOS
JavaScript runtime
Hermes
Workflow
React Native (without Expo)
Architecture
Fabric (New Architecture)
Build type
Debug mode
Device
iOS simulator
Device model
iPhone 15 Pro
Acknowledgements
Yes
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 1
- Comments: 54 (11 by maintainers)
I was facing the same issue with React Native v0.77.0 and realised that I had not made the edits described in the upgrade guide. Following the upgrade guide, I made the edits to AppDelegate.mm and it worked fine.
Ref: https://reactnative.dev/blog/2025/01/21/version-0.77#rctappdependencyprovider
Setting
detachInactiveScreenstofalseresolved the issue, However, this seems to be a workaround rather than addressing the root cause.This is the fix.
Most likely people are forgetting to add these changes because when upgrading from 0.76 -> 0.77, the community template migrated from
AppDelegate.mmtoAppDelegate.swift, and people are ignoring it thinking it’s just syntax change.It’s not,
RCTAppDependencyProviderwas also added when migrating from Obj-C++ to Swift, and needs to be added toAppDelegate.mmif you’re sticking with it.Let me know in case these instructions resolve the issue so that I can close the ticket, please.
@kkafar our project is actually using 3.35.0 for react-native-screens, along with the following versions for the react-navigation libraries:
"@react-navigation/bottom-tabs": "6.6.1", "@react-navigation/native": "6.1.18", "@react-navigation/stack": "6.4.1",I did also, prior to your message, try to update to 4.4.0, but that did not resolve the issue. From playing around with it, it’s affecting all the different navigators provided by react-navigation, as the ‘detachInactiveScreens’ prop needs to be applied to all navigators for the app not to crash. I can try and provide a minimal repo, but 3.35.0 was the initial setup where we experienced the issue.
Experiencing the same issue on iOS after updating React Native to 0.76. Running react-native-screens 3.35.0, and the latest 6.x.x versions of the required react navigation components. Using old architecture of RN. Crash happens immediately on opening the app.
As @hoonjoo-park mentioned, adding
detachInactiveScreens={false}to each of the navigators does resolve the issue, but this is suboptimal.That’s great news, thanks. I’ll close the ticket as it seems that the issue happens due to misconfiguration related to autolinking and is not related to the library. Let me know in case you experience the same issue and methods mentioned above do not work.
The link provided @pkalani1999 & @YukiKitagata look like valid explanation.
@huxinhai @princekumarpaswan @ahmedgit2 @sriprasad19 @Amurmurmur this is something you might want to try out.
@spale44 screens 4.x are intended to work with
react-navigation@v7. If that’s feasible for you I recommend using the 7.x.x line, if not - you should downgrade screens version to 3.x line.