Add an iOS withDangerousMod to the Expo config plugin that patches RCTThirdPartyComponentsProvider.mm#176
Add an iOS withDangerousMod to the Expo config plugin that patches RCTThirdPartyComponentsProvider.mm#176Th0mYT wants to merge 43 commits intoazesmway:mainfrom
Conversation
- Detect Expo projects automatically via app.json - Use correct framework search paths for both Expo and RN CLI - Add Expo config plugin for automatic setup - Update README with Expo-specific instructions Fixes: Unity framework not found in Expo projects
…ess of updateProps
…ngs mod configuration
…es and simplify config type
|
@Th0mYT Thanks for the improvements! |
@azesmway of course. If you want, I'm working on the fork to further optimize the package for both Android and iOS. I'm also updating the plugin for expo. If you want, after finishing these changes and testing everything I can create a new PR with these changes. |
ok |
I updated the PR. Summary of changes ios/RNUnityView.mm — New Architecture fix
android/.../UPlayer.java — Type cast fix
plugin/src/index.ts — Expo config plugin refactor Several issues fixed to make the plugin safe to run multiple times (e.g. after repeated npx expo prebuild):
tsconfig.json — Plugin path alias
package.json — Build setup for the plugin
|
…uctor and fix setZ
- Replace RCTEventEmitter with EventDispatcher for new arch compat - Add dispatchEvent() helper with old/new arch routing + null checks - Guard sendMessageToMobileApp against null view - Fix pauseUnity to use static pause()/resume() to track _isUnityPaused - Replace hardcoded "MyMessage" in callbacks with dispatchEvent() - Log exceptions in createViewInstance instead of swallowing - Clear stale view ref in onDropViewInstance if instance matches - Add TAG constant for logging
# Conflicts: # package.json
…oid devices - Set `android:enableOnBackInvokedCallback` to `false` in the manifest. - Use `tools:replace` to override conflicting value set by `unityLibrary`. - Avoid crashes caused by `OnBackInvokedCallback` on pre-API 33 devices.
- Post `onReady()` calls to the main thread to prevent view hierarchy updates off the main thread. - Wrap `sendMessageToMobileApp` event dispatch in a main thread handler.
…ensions - Post a forced layout runnable to address issues with parent views
…chitecture - Add fallback using OnGlobalLayoutListener to handle delayed group dimensions. - Use ThemedReactContext in view creation for proper surface association. - Update dispatchEvent logic to retrieve surfaceId directly from ThemedReactContext if parent chain fails. - Bump package version to 1.0.17.
- Reset z-elevation to make Unity visible after re-parenting. - Add delayed resume to prevent black screen on remount by allowing surface creation. - Bump package version to 1.0.18.
…arenting - Introduce direct SurfaceView surfaceCreated hook for precise Unity resume timing. - Add fallback for cases without SurfaceView by implementing a delayed resume. - Refactor surface detection into a new helper method for cleaner logic.
- Adjust z-elevation for proper Unity visibility after re-parenting. - Add precise surface resume logic using SurfaceView and OnPreDrawListener. - Refactor resume timing to account for Choreographer and compositor updates.
- Add pause logic in `onDetachedFromWindow` to stop rendering frames before backgrounding. - Prevents "BufferQueueProducer disconnect: not connected" error.
…ompatibility - Handle FLAG_FULLSCREEN deprecation with conditional logic. - Add detailed logging for UnityPlayer constructor resolution to improve debugging. - Catch and log alignment errors on Unity native library loading. - Enhance robustness of UnityPlayer initialization.
…ment adjustments - Add a 2-second timeout fallback to resume Unity if surfaceCreated never fires. - Ensure proper frame measurement before layout to prevent missed surfaceCreated events. - Improve logging for better debugging of surface and group layout issues.
|
Hi @azesmway! I've updated the PR with several improvements focused on stability and Android compatibility. Android surface & rendering fixes
New Architecture (Fabric) compatibility
Android API 30+ compatibility
Other
Happy to discuss any of the changes or provide more context if needed! |
What was changed: plugin/src/index.ts (and its compiled output plugin/build/index.js)
What was broken: Expo's prebuild ran the C++ codegen for unityview but never generated the Fabric registration step. RNUnityViewCls() was defined in RNUnityView.mm but never
called, so Fabric couldn't find the component by name, fell back to the legacy interop layer, and updateProps was never dispatched.
The fix — withIosFabricRegistration: A new iOS withDangerousMod that runs at the end of every npx expo prebuild and patches RCTThirdPartyComponentsProvider.mm with two insertions:
// 1. Forward declaration (before @implementation)
Class RNUnityViewCls(void);
// 2. Dictionary entry (inside thirdPartyFabricComponents)
@"RNUnityView" : RNUnityViewCls(),
Call chain after the fix (matches what should happen):
codegenNativeComponent('RNUnityView')
→ Fabric finds RNUnityView via RCTThirdPartyComponentsProvider
→ initWithFrame: (lambda set, initUnityModule called as belt-and-suspenders)
→ updateEventEmitter:
→ updateProps: ← initUnityModule() ← Unity starts ✓
The initUnityModule call in initWithFrame: from the previous commit remains — it acts as a safety net for any edge case where updateProps might still be delayed.