处理硬件后退按钮单击
Handle hardware back button click
我不知道如何让我的 winjs(react-winjs) 应用程序使用硬件后退按钮。这是我的导航功能的示例:
handleNavigation(location) {
this.setState({
location: location
});
WinJS.Navigation.navigate(`/${location}`);
console.log(WinJS.Navigation.history);
}
console.log(WinJS.Navigation.history)
以正确的历史顺序输出名为 "backStack" 的正确数组,但单击 windows phone 模拟器上的硬件后退按钮只是简单地退出应用程序。
我是不是遗漏了什么明显的东西?
这是我设法找到并尝试但没有成功的内容(我确实也找到了一些很好的 C# 文档,但不是我需要的):
谢谢
确实这是一个非常愚蠢的错误,我没有等待 winjs/windows 就绪就初始化了我的应用程序,我应该这样初始化它:
(function () {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// This is how you should initialize your app
ReactDOM.render(<App />, document.getElementById('app'));
} else {
// TODO: This application was suspended and then terminated.
// To create a smooth user experience, restore application state here so that it looks like the app never stopped running.
}
args.setPromise(WinJS.UI.processAll());
}
};
app.oncheckpoint = function (args) {
// TODO: This application is about to be suspended. Save any state that needs to persist across suspensions here.
// You might use the WinJS.Application.sessionState object, which is automatically saved and restored across suspension.
// If you need to complete an asynchronous operation before your application is suspended, call args.setPromise().
};
app.start();
})();
这样我就可以在我的组件 componentWillMount 函数中将 EventListener 添加到 "backclick" 并且它有效:
componentWillMount() {
WinJS.Application.addEventListener("backclick", function () {
document.body.style.background = "red"; //or for example setState/show notification etc...
});
}
我不知道如何让我的 winjs(react-winjs) 应用程序使用硬件后退按钮。这是我的导航功能的示例:
handleNavigation(location) {
this.setState({
location: location
});
WinJS.Navigation.navigate(`/${location}`);
console.log(WinJS.Navigation.history);
}
console.log(WinJS.Navigation.history)
以正确的历史顺序输出名为 "backStack" 的正确数组,但单击 windows phone 模拟器上的硬件后退按钮只是简单地退出应用程序。
我是不是遗漏了什么明显的东西?
这是我设法找到并尝试但没有成功的内容(我确实也找到了一些很好的 C# 文档,但不是我需要的):
谢谢
确实这是一个非常愚蠢的错误,我没有等待 winjs/windows 就绪就初始化了我的应用程序,我应该这样初始化它:
(function () {
"use strict";
var app = WinJS.Application;
var activation = Windows.ApplicationModel.Activation;
app.onactivated = function (args) {
if (args.detail.kind === activation.ActivationKind.launch) {
if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
// This is how you should initialize your app
ReactDOM.render(<App />, document.getElementById('app'));
} else {
// TODO: This application was suspended and then terminated.
// To create a smooth user experience, restore application state here so that it looks like the app never stopped running.
}
args.setPromise(WinJS.UI.processAll());
}
};
app.oncheckpoint = function (args) {
// TODO: This application is about to be suspended. Save any state that needs to persist across suspensions here.
// You might use the WinJS.Application.sessionState object, which is automatically saved and restored across suspension.
// If you need to complete an asynchronous operation before your application is suspended, call args.setPromise().
};
app.start();
})();
这样我就可以在我的组件 componentWillMount 函数中将 EventListener 添加到 "backclick" 并且它有效:
componentWillMount() {
WinJS.Application.addEventListener("backclick", function () {
document.body.style.background = "red"; //or for example setState/show notification etc...
});
}