@remvst/game-navigation-core 1.10.0 → 1.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/navigation/resolver.js +1 -1
- package/lib/navigation/screen-stack.js +3 -0
- package/lib/plugins/back-navigation-plugin.js +3 -3
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/navigation/back-navigation-listener.ts +3 -3
- package/src/navigation/resolver.ts +1 -1
- package/src/navigation/screen-stack.ts +4 -0
- package/src/plugins/back-navigation-plugin.ts +56 -53
package/lib/index.d.ts
CHANGED
|
@@ -9,10 +9,10 @@ export * from "./navigation/screen-stack";
|
|
|
9
9
|
export * from "./ui/screen";
|
|
10
10
|
export * from "./ui/screen-delegate";
|
|
11
11
|
export * from "./plugins/automation-game-plugin";
|
|
12
|
+
export * from "./plugins/back-navigation-plugin";
|
|
12
13
|
export * from "./plugins/blur-pausing-game-plugin";
|
|
13
14
|
export * from "./plugins/fullscreen-button-game-plugin";
|
|
14
15
|
export * from "./plugins/metrics-game-plugin";
|
|
15
|
-
export * from "./plugins/back-navigation-plugin";
|
|
16
16
|
export * from "./plugins/storage-game-plugin";
|
|
17
17
|
export * from "./plugins/time-keys-game-plugin";
|
|
18
18
|
export * from "./plugins/version-label-game-plugin";
|
package/lib/index.js
CHANGED
|
@@ -25,10 +25,10 @@ __exportStar(require("./navigation/screen-stack"), exports);
|
|
|
25
25
|
__exportStar(require("./ui/screen"), exports);
|
|
26
26
|
__exportStar(require("./ui/screen-delegate"), exports);
|
|
27
27
|
__exportStar(require("./plugins/automation-game-plugin"), exports);
|
|
28
|
+
__exportStar(require("./plugins/back-navigation-plugin"), exports);
|
|
28
29
|
__exportStar(require("./plugins/blur-pausing-game-plugin"), exports);
|
|
29
30
|
__exportStar(require("./plugins/fullscreen-button-game-plugin"), exports);
|
|
30
31
|
__exportStar(require("./plugins/metrics-game-plugin"), exports);
|
|
31
|
-
__exportStar(require("./plugins/back-navigation-plugin"), exports);
|
|
32
32
|
__exportStar(require("./plugins/storage-game-plugin"), exports);
|
|
33
33
|
__exportStar(require("./plugins/time-keys-game-plugin"), exports);
|
|
34
34
|
__exportStar(require("./plugins/version-label-game-plugin"), exports);
|
|
@@ -5,7 +5,7 @@ const game_plugin_1 = require("../game/game-plugin");
|
|
|
5
5
|
class BackNavigationPlugin extends game_plugin_1.GamePlugin {
|
|
6
6
|
constructor() {
|
|
7
7
|
super(...arguments);
|
|
8
|
-
this.key =
|
|
8
|
+
this.key = "back-navigation";
|
|
9
9
|
this.pushedState = false;
|
|
10
10
|
}
|
|
11
11
|
setup() {
|
|
@@ -13,13 +13,13 @@ class BackNavigationPlugin extends game_plugin_1.GamePlugin {
|
|
|
13
13
|
const { length } = history;
|
|
14
14
|
if (length > 0)
|
|
15
15
|
history.go(-length);
|
|
16
|
-
window.addEventListener(
|
|
16
|
+
window.addEventListener("popstate", () => this.onPopState());
|
|
17
17
|
}
|
|
18
18
|
pushState() {
|
|
19
19
|
if (this.pushedState)
|
|
20
20
|
return;
|
|
21
21
|
this.pushedState = true;
|
|
22
|
-
window.history.pushState({},
|
|
22
|
+
window.history.pushState({}, "", "");
|
|
23
23
|
}
|
|
24
24
|
popState() {
|
|
25
25
|
if (!this.pushedState)
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -13,10 +13,10 @@ export * from "./ui/screen";
|
|
|
13
13
|
export * from "./ui/screen-delegate";
|
|
14
14
|
|
|
15
15
|
export * from "./plugins/automation-game-plugin";
|
|
16
|
+
export * from "./plugins/back-navigation-plugin";
|
|
16
17
|
export * from "./plugins/blur-pausing-game-plugin";
|
|
17
18
|
export * from "./plugins/fullscreen-button-game-plugin";
|
|
18
19
|
export * from "./plugins/metrics-game-plugin";
|
|
19
|
-
export * from "./plugins/back-navigation-plugin";
|
|
20
20
|
export * from "./plugins/storage-game-plugin";
|
|
21
21
|
export * from "./plugins/time-keys-game-plugin";
|
|
22
22
|
export * from "./plugins/version-label-game-plugin";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export interface BackNavigationListener {
|
|
2
|
-
onBackNavigation(): void;
|
|
3
|
-
}
|
|
1
|
+
export interface BackNavigationListener {
|
|
2
|
+
onBackNavigation(): void;
|
|
3
|
+
}
|
|
@@ -1,53 +1,56 @@
|
|
|
1
|
-
import { GamePlugin } from "../game/game-plugin";
|
|
2
|
-
import { BackNavigationListener } from "../navigation/back-navigation-listener";
|
|
3
|
-
import { Screen } from "../ui/screen";
|
|
4
|
-
|
|
5
|
-
export class BackNavigationPlugin extends GamePlugin {
|
|
6
|
-
readonly key =
|
|
7
|
-
|
|
8
|
-
private pushedState = false;
|
|
9
|
-
|
|
10
|
-
setup(): void {
|
|
11
|
-
super.setup();
|
|
12
|
-
|
|
13
|
-
const { length} = history;
|
|
14
|
-
if (length > 0) history.go(-length);
|
|
15
|
-
|
|
16
|
-
window.addEventListener(
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
pushState() {
|
|
20
|
-
if (this.pushedState) return;
|
|
21
|
-
this.pushedState = true;
|
|
22
|
-
window.history.pushState({},
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
popState() {
|
|
26
|
-
if (!this.pushedState) return;
|
|
27
|
-
this.pushedState = false;
|
|
28
|
-
window.history.back();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
private onPopState() {
|
|
32
|
-
this.pushedState = false;
|
|
33
|
-
|
|
34
|
-
const currentScreen =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
1
|
+
import { GamePlugin } from "../game/game-plugin";
|
|
2
|
+
import { BackNavigationListener } from "../navigation/back-navigation-listener";
|
|
3
|
+
import { Screen } from "../ui/screen";
|
|
4
|
+
|
|
5
|
+
export class BackNavigationPlugin extends GamePlugin {
|
|
6
|
+
readonly key = "back-navigation";
|
|
7
|
+
|
|
8
|
+
private pushedState = false;
|
|
9
|
+
|
|
10
|
+
setup(): void {
|
|
11
|
+
super.setup();
|
|
12
|
+
|
|
13
|
+
const { length } = history;
|
|
14
|
+
if (length > 0) history.go(-length);
|
|
15
|
+
|
|
16
|
+
window.addEventListener("popstate", () => this.onPopState());
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
pushState() {
|
|
20
|
+
if (this.pushedState) return;
|
|
21
|
+
this.pushedState = true;
|
|
22
|
+
window.history.pushState({}, "", "");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
popState() {
|
|
26
|
+
if (!this.pushedState) return;
|
|
27
|
+
this.pushedState = false;
|
|
28
|
+
window.history.back();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
private onPopState() {
|
|
32
|
+
this.pushedState = false;
|
|
33
|
+
|
|
34
|
+
const currentScreen =
|
|
35
|
+
this.game.screenStack.current() as unknown as BackNavigationListener | null;
|
|
36
|
+
if (!currentScreen?.onBackNavigation) return;
|
|
37
|
+
|
|
38
|
+
this.pushState();
|
|
39
|
+
currentScreen.onBackNavigation();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setupScreen(screen: Screen) {
|
|
43
|
+
super.setupScreen(screen);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
onCurrentScreenChanged(screen: Screen | null): void {
|
|
47
|
+
const handlesBackNavigation = (
|
|
48
|
+
screen as unknown as BackNavigationListener
|
|
49
|
+
)?.onBackNavigation;
|
|
50
|
+
if (handlesBackNavigation) {
|
|
51
|
+
this.pushState();
|
|
52
|
+
} else {
|
|
53
|
+
this.popState();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|