Skip to content
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

fix: change -[RNSScreenContainer init] to call -[UIView initWithFrame:] designated initalizer #2161

Conversation

Brett-Best
Copy link
Contributor

Description

Ensures RNSScreenContainer UIView subclass calls a designated initializer, this fixes an issue where subclassing RNSScreenContainer would recursively loop through the inits - ending in a crash.

UIView.h has:
- (instancetype)initWithFrame:(CGRect)frame NS_DESIGNATED_INITIALIZER;

Checklist

@kkafar
Copy link
Member

kkafar commented May 29, 2024

Hey @Brett-Best, while indeed we do not call designated initializer on our parent class (thus this change makes sense) but I do not see a scenario of how this would lead to a crash? Could you elaborate a bit?

@Brett-Best
Copy link
Contributor Author

We have a subclass of RNSScreenContainerView which has a custom init (#4-#3) that takes some dependencies.
We call super.init() in #3, this then goes to #2 which then due to the current super call ends up back in NativeAppView [not the superclass of RNSScreenContainerView] #1 and then attempts to call the unimplemented init(frame: in our subclass.

Changing to the designated initialiser makes #2 go to UIView rather than NativeAppView, fixing the problem.

#0 in NativeAppView.init(frame:) ()
#1 in @objc NativeAppView.init(frame:) ()
#2 in -[RNSScreenContainerView init] at /node_modules/react-native-screens/ios/RNSScreenContainer.mm:63
#3 in NativeAppView.init(analyticsInteractor:bundleProvider:deepLinkRouter:routeConfigService:router:screenDimensionsManager:socialProfileInteractor:) at mobile/Bridge/NativeComponents/NativeAppView.swift:75
#4 in NativeAppView.__allocating_init(analyticsInteractor:bundleProvider:deepLinkRouter:routeConfigService:router:screenDimensionsManager:socialProfileInteractor:) ()
#5 in closure #1 in NativeAppViewManager.view() at mobile/Bridge/NativeComponents/NativeAppViewManager.swift:49
#6 in partial apply for closure #1 in NativeAppViewManager.view() ()
#7 in static MainActor.assumeIsolated<τ_0_0>(_:file:line:) ()
#8 in static MainActor.assumeIsolated<τ_0_0>(_:file:line:) ()
#9 in NativeAppViewManager.view() at mobile/Bridge/NativeComponents/NativeAppViewManager.swift:48
#10 in @objc NativeAppViewManager.view() ()
#11 in -[RCTComponentData createViewWithTag:rootTag:] at /node_modules/react-native/React/Views/RCTComponentData.m:82
#12 in __50-[RCTUIManager createView:viewName:rootTag:props:]_block_invoke at /node_modules/react-native/React/Modules/RCTUIManager.m:1007

@Brett-Best
Copy link
Contributor Author

@kkafar any chance this could also get included in the release this week if all goes well?

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.

Yeah yeah, I think we're fine here now. Thanks for these details!

@kkafar kkafar merged commit 2a06781 into software-mansion:main Jun 4, 2024
5 checks passed
@Brett-Best Brett-Best deleted the fix/RNSScreenContainer-super-init-call branch June 9, 2024 14:32
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.

2 participants