Skip to content
This repository was archived by the owner on May 31, 2025. It is now read-only.

Bump React version and add logging on Android #100

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions android/src/main/java/no/asmadsen/unity/view/UnityUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnityView>
implements LifecycleEventListener, View.OnAttachStateChangeListener {
Expand Down Expand Up @@ -54,6 +55,7 @@ public void onDropViewInstance(UnityView view) {
public void onHostResume() {
if (UnityUtils.isUnityReady()) {
UnityUtils.getPlayer().resume();
Log.i("Unity", "onHostResume() restoreUnityUserState()");
restoreUnityUserState();
}
}
Expand All @@ -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();
}
}
Expand All @@ -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();
}

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -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"
Expand Down