Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 9ae129a

Browse files
committed
handle navigation back button events (within-unity solution)
1 parent c57b265 commit 9ae129a

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

Runtime/engine/UIWidgetsPanel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ internal void applyRenderTexture(Rect screenRect, Texture texture, Material mat)
196196
protected virtual void Update() {
197197
this._displayMetrics.Update();
198198
UIWidgetsMessageManager.ensureUIWidgetsMessageManagerIfNeeded();
199+
200+
#if UNITY_ANDROID
201+
if (Input.GetKeyDown(KeyCode.Escape)) {
202+
this._windowAdapter.withBinding(() => {
203+
WidgetsBinding.instance.handlePopRoute();
204+
});
205+
}
206+
#endif
199207

200208
if (!this._viewMetricsCallbackRegistered) {
201209
this._viewMetricsCallbackRegistered = true;

Runtime/widgets/binding.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using Unity.UIWidgets.foundation;
55
using Unity.UIWidgets.rendering;
66
using Unity.UIWidgets.ui;
7+
using UnityEngine;
78

89
namespace Unity.UIWidgets.widgets {
910
public interface WidgetsBindingObserver {
@@ -54,6 +55,23 @@ public bool removeObserver(WidgetsBindingObserver observer) {
5455
return this._observers.Remove(observer);
5556
}
5657

58+
public void handlePopRoute() {
59+
var idx = -1;
60+
61+
void _handlePopRouteSub(bool result) {
62+
if (!result) {
63+
idx++;
64+
if (idx >= this._observers.Count) {
65+
Application.Quit();
66+
return;
67+
}
68+
this._observers[idx].didPopRoute().Then(_handlePopRouteSub);
69+
}
70+
}
71+
72+
_handlePopRouteSub(false);
73+
}
74+
5775
public readonly WidgetInspectorService widgetInspectorService;
5876

5977
protected override void handleMetricsChanged() {

0 commit comments

Comments
 (0)