software-mansion / react-native-screens

Native navigation primitives for your React Native app.
https://docs.swmansion.com/react-native-screens/
MIT License
3.1k stars 521 forks source link

Using react-native-screens and SwiftUI Preview at the same project breaks Preview #1602

Open sercand opened 2 years ago

sercand commented 2 years ago

Description

When we add a SwiftUI Preview to our project in order to get a preview of a native component, we get an infinite loop of reactNativeScreensChildViewControllerForStatusBarHidden call and preview crashes.

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x000000016b1dffd0
Exception Codes: 0x0000000000000002, 0x000000016b1dffd0
VM Region Info: 0x16b1dffd0 is in 0x1679dc000-0x16b1e0000;  bytes after start: 58736592  bytes before end: 47
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      MALLOC_MEDIUM (reserved)    15f800000-160000000    [ 8192K] rw-/rwx SM=NUL  ...(unallocated)
      GAP OF 0x79dc000 BYTES
--->  STACK GUARD                 1679dc000-16b1e0000    [ 56.0M] ---/rwx SM=NUL  ... for thread 0
      Stack                       16b1e0000-16b9dc000    [ 8176K] rw-/rwx SM=PRV  thread 0
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [18989]

Triggered by Thread:  0

Kernel Triage:
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage
VM - pmap_enter retried due to resource shortage

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   UIKitCore                              0x1116dc008 -[UIViewController(UIContainerViewControllerProtectedMethods) childViewControllers] + 0
1   PermissionView.1.preview-thunk.dylib           0x126726068 -[UIViewController(RNScreens) findChildRNScreensViewController] + 32
2   FirstWords                             0x104b105ec -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 32
3   FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
4   FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
5   FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
6   FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
7   FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
8   FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
9   FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
10  FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
11  FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
12  FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
13  FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100
14  FirstWords                             0x104b10630 -[UIViewController(RNScreens) reactNativeScreensChildViewControllerForStatusBarHidden] + 100

Steps to reproduce

Screens version

3.17

React Native version

0.68.3

Platforms

iOS

Build type

Debug mode

Device

iOS simulator. Xcode Preview

Acknowledgements

Yes

github-actions[bot] commented 2 years ago

Hey! 👋

The issue doesn't seem to contain a minimal reproduction.

Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?

github-actions[bot] commented 2 years ago

Hey! 👋

It looks like you've omitted a few important sections from the issue template.

Please complete Snack or a link to a repository section.

AndersonVanzo commented 2 years ago

Facing the same problem, did you find any solution?

sercand commented 2 years ago

Facing the same problem, did you find any solution?

@AndersonVanzo We decided to split project into different Frameworks and those new frameworks don't have dependency on react-native

karankalsi commented 1 year ago

We are also facing this issue. Any update on this?

lilidotshi commented 11 months ago

Also running into this issue with Previews and Xcode 15

GrandLarseny commented 4 months ago

This issue is still happening. It is difficult to describe exact steps to reproduce since this is basic functionality with SwiftUI in any iOS project that includes React Native components.

What's happening is that in SwiftUI previews the normal setup for UIKit doesn't happen, so the Objective-C method swizzling in RNScreens causes an infinite loop because findChildRNSScreensViewController, which is called by reactNativeScreensChildViewControllerForStatusBarHidden, always returns nil. What I'd really love is some type of workaround to be able to use SwiftUI previews since that is absolutely the preferred method for development.

gmantuanrosa commented 1 month ago

Still looking for a solution to this RNScreen issue but I think none will come in place, maybe changing library?