问题
I have an xbox one app that has a webview containing a javascript app.
In my React app I have something like this:
navigator.gamepadInputEmulation = 'gamepad';
window.addEventListener('onkeydown', function(event) {
if (event.keyCode === 196) {
event.stopImmediatePropagation();
// custom back button logic
}
});
The custom back button logic runs but then the default controller back button logic also runs even with event.stopImmediatePropagation();
Is there any fix for this?
If I set navigator.gamepadInputEmulation = 'keyboard';
this issue goes away but then all the controller input events run twice.
回答1:
Here is a quick fix for you, just intercept the 'backrequested' and set it as handled:
var systemNavManager = Windows.UI.Core.SystemNavigationManager.getForCurrentView();
systemNavManager.addEventListener("backrequested", (event)=>event.handled = true, false);
Hope that helps!
来源:https://stackoverflow.com/questions/56981247/xbox-one-controller-prevent-default-back-button-behavior-with-javascript