fix(ios): Initialize Unity in layoutSubviews for Fabric support #174
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When using React Native's new architecture (Fabric), Unity fails to initialize on iOS because updateProps is not reliably called during the initial component render cycle. This happens when:
No props are explicitly passed to the Unity view component
Props don't change between initial renders
The component uses only event handler props
This results in Unity never starting, showing "N/A" for SDK version, and games not loading on iOS devices.
Solution
Initialize Unity in layoutSubviews instead of relying solely on updateProps. The layoutSubviews method is always called by the iOS view system when a view is about to be displayed, making it a more reliable initialization point.
The check if(![self unityIsInitialized]) prevents double-initialization, ensuring this works correctly in both Fabric and the old architecture.
Testing
✅ Tested on real iOS devices (iPhone 15 Pro) with Fabric enabled
✅ Unity now initializes correctly and games load properly
✅ SDK version is correctly reported
✅ Backwards compatible with old architecture (Paper)
Related Issues
This addresses the root cause of Unity not initializing in Fabric mode, which may be affecting other developers using the new architecture but not yet reported.