diff --git a/android/src/main/java/no/asmadsen/unity/view/UnityUtils.java b/android/src/main/java/no/asmadsen/unity/view/UnityUtils.java index e27791b..ea5eadf 100644 --- a/android/src/main/java/no/asmadsen/unity/view/UnityUtils.java +++ b/android/src/main/java/no/asmadsen/unity/view/UnityUtils.java @@ -8,6 +8,7 @@ import android.view.WindowManager; import com.unity3d.player.UnityPlayer; import java.util.concurrent.CopyOnWriteArraySet; +import android.util.Log; import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; @@ -82,15 +83,16 @@ public static void postMessage(String gameObject, String methodName, String mess public static void pause() { if (unityPlayer != null) { - unityPlayer.pause(); + Log.i("Unity", "UnityUtils PAUSE"); _isUnityPaused = true; + unityPlayer.pause(); } } public static void resume() { if (unityPlayer != null) { - unityPlayer.resume(); _isUnityPaused = false; + unityPlayer.resume(); } } diff --git a/android/src/main/java/no/asmadsen/unity/view/UnityViewManager.java b/android/src/main/java/no/asmadsen/unity/view/UnityViewManager.java index 67f8d89..90fdd50 100644 --- a/android/src/main/java/no/asmadsen/unity/view/UnityViewManager.java +++ b/android/src/main/java/no/asmadsen/unity/view/UnityViewManager.java @@ -8,6 +8,7 @@ import com.facebook.react.uimanager.ThemedReactContext; import java.util.Map; import javax.annotation.Nullable; +import android.util.Log; public class UnityViewManager extends SimpleViewManager implements LifecycleEventListener, View.OnAttachStateChangeListener { @@ -54,6 +55,7 @@ public void onDropViewInstance(UnityView view) { public void onHostResume() { if (UnityUtils.isUnityReady()) { UnityUtils.getPlayer().resume(); + Log.i("Unity", "onHostResume() restoreUnityUserState()"); restoreUnityUserState(); } } @@ -62,6 +64,7 @@ public void onHostResume() { public void onHostPause() { if (UnityUtils.isUnityReady()) { // Don't use UnityUtils.pause() + Log.i("Unity", "onHostPause() PAUSE"); UnityUtils.getPlayer().pause(); } } @@ -80,16 +83,18 @@ private void restoreUnityUserState() { handler.postDelayed(new Runnable() { @Override public void run() { - if (UnityUtils.getPlayer() != null) { + if (UnityUtils.getPlayer() != null && UnityUtils.isUnityPaused()) { + Log.i("Unity", "restoreUnityUserState() PAUSE"); UnityUtils.getPlayer().pause(); } } - }, 300); //TODO: 300 is the right one? + }, 200); //TODO: 300 is the right one? } } @Override public void onViewAttachedToWindow(View v) { + Log.i("Unity", "onViewAttachedToWindow() restoreUnityUserState()"); restoreUnityUserState(); } diff --git a/package.json b/package.json index 99c3acb..c86c3ef 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@asmadsen/react-native-unity-view", "title": "React Native Unity View", - "version": "0.0.6", + "version": "0.0.7", "description": "Embed Unity Player inside a React Native app", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -24,13 +24,13 @@ "licenseFilename": "LICENSE", "readmeFilename": "README.md", "peerDependencies": { - "react": "^16.8.1", + "react": "^18.2.0", "react-native": ">=0.60.0" }, "devDependencies": { "@types/prop-types": "^15.7.3", "@types/react": "^16.9.9", - "react": "^16.8.3", + "react": "^18.2.0", "react-native": "^0.60.0", "rimraf": "^3.0.0", "typescript": "^3.6.4"