Skip to content

Commit 3256b01

Browse files
authored
Merge pull request #78 from Luluno01/main
Expose windowFocusChanged as a command
2 parents 8231900 + 072a83d commit 3256b01

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ export default Unity;
163163

164164
- `unloadUnity()` - the Unity is unloaded automatically when the react-native component is unmounted, but if you want to unload the Unity, you can call this method
165165
- `pauseUnity?: (pause: boolean)` - pause the Unity
166+
- `windowFocusChanged(hasFocus: boolean = false)` - simulate focus change (intended to be used to recover from black screen (not rendering) after remounting Unity view when `resumeUnity` does not work) **ANDROID ONLY**
166167

167168
# Contributing
168169

Diff for: android/src/main/java/com/azesmwayreactnativeunity/ReactNativeUnityViewManager.java

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ public void receiveCommand(
105105
case "resumeUnity":
106106
ReactNativeUnity.getPlayer().resume();
107107
return;
108+
case "windowFocusChanged":
109+
ReactNativeUnity.getPlayer().windowFocusChanged(args.getBoolean(0));
110+
return;
108111
default:
109112
throw new IllegalArgumentException(String.format(
110113
"Unsupported command %s received by %s.",

Diff for: src/index.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ export default class UnityView extends React.Component<ReactNativeUnityViewProps
6565
);
6666
}
6767

68+
public windowFocusChanged(hasFocus = true) {
69+
if (Platform.OS !== 'android') return;
70+
UIManager.dispatchViewManagerCommand(
71+
findNodeHandle(this),
72+
this.getCommand('windowFocusChanged'),
73+
[Boolean(hasFocus)]
74+
);
75+
}
76+
6877
private getCommand(cmd: string): any {
6978
if (Platform.OS === 'ios') {
7079
return UIManager.getViewManagerConfig('ReactNativeUnityView').Commands[

0 commit comments

Comments
 (0)