Skip to content

fix: Disable view controller methods swizzling when Xcode is running for previews #2894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kzyryanov
Copy link

Description

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 (and other swizzled methods), always returns nil.

This fix disables swizzling when Xcode is running for previews.

This may bring some issues if RN screens are within SwiftUI navigation stack but at least for basic SwiftUI previews that fix works.

Fixes #1602

Changes

Test code and steps to reproduce

Checklist

Copy link
Member

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey! Thanks!

I'm reluctant to merge this PR atm, since my first impression is that potentially correct behaviour at application runtime is more important than preview.

I don't have any other insights though. Will need to test, whether there are some issue caused for real or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using react-native-screens and SwiftUI Preview at the same project breaks Preview
2 participants