Skip to content

iOS unity build blackscreen, unmounting on blur, and not properly pausing/resuming when that's fixed #180

Description

@SethCram

Today I used patch-package to patch @azesmway/react-native-unity@1.0.11 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/@azesmway/react-native-unity/ios/RNUnityView.mm b/node_modules/@azesmway/react-native-unity/ios/RNUnityView.mm
index a4caa74..46e1a38 100644
--- a/node_modules/@azesmway/react-native-unity/ios/RNUnityView.mm
+++ b/node_modules/@azesmway/react-native-unity/ios/RNUnityView.mm
@@ -84,9 +84,14 @@ static RNUnityView *sharedInstance;
 - (void)layoutSubviews {
    [super layoutSubviews];
 
+   if(![self unityIsInitialized]) {
+      [self initUnityModule];
+   }
+
    if([self unityIsInitialized]) {
       self.ufw.appController.rootView.frame = self.bounds;
       [self addSubview:self.ufw.appController.rootView];
+      [[self ufw] pause:false];
    }
 }
 
@@ -158,14 +163,12 @@ static RNUnityView *sharedInstance;
     [super prepareForRecycle];
 
     if ([self unityIsInitialized]) {
-      [[self ufw] unloadApplication];
-
+      [[self ufw] pause:true];
+      // Keep Unity running when the view is recycled; just detach the view tree.
       NSArray *viewsToRemove = self.subviews;
       for (UIView *v in viewsToRemove) {
           [v removeFromSuperview];
       }
-
-      [self setUfw:nil];
     }
 }
 

I believe the issues were likely caused by the new fabric architecture. When I upgraded the Expo SDK 49 -> 53 I started having these issues.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions