Resolved: Cross platform way to clear history #283

This commit is contained in:
Rossen Hristov
2015-09-25 11:34:17 +03:00
parent 84b3eb545d
commit f75922102a
7 changed files with 220 additions and 43 deletions

View File

@@ -1,5 +1,4 @@
import application = require("application");
import frameModule = require("ui/frame");
import navPageModule = require("../nav-page");
import trace = require("trace");
@@ -7,14 +6,13 @@ trace.enable();
trace.setCategories(trace.categories.concat(
trace.categories.NativeLifecycle
, trace.categories.Navigation
, trace.categories.ViewHierarchy
, trace.categories.VisualTreeEvents
));
));
application.onLaunch = function (context) {
var frame = new frameModule.Frame();
var pageFactory = function () {
application.mainEntry = {
create: function () {
return new navPageModule.NavPage(0);
};
frame.navigate(pageFactory);
}
}
//backstackVisible: false,
//clearHistory: true
};
application.start();

View File

@@ -6,11 +6,14 @@ import labelModule = require("ui/label");
import buttonModule = require("ui/button");
import textFieldModule = require("ui/text-field");
import enums = require("ui/enums");
import switchModule = require("ui/switch");
export class NavPage extends pagesModule.Page implements definition.ControlsPage {
constructor(id: number) {
super();
this.id = "NavPage " + id;
var stackLayout = new stackLayoutModule.StackLayout();
stackLayout.orientation = enums.Orientation.vertical;
@@ -21,6 +24,11 @@ export class NavPage extends pagesModule.Page implements definition.ControlsPage
});
stackLayout.addChild(goBackButton);
this.on(pagesModule.Page.navigatedToEvent, function () {
//console.log("Navigated to NavPage " + id + "; backStack.length: " + frameModule.topmost().backStack.length);
goBackButton.isEnabled = frameModule.topmost().canGoBack();
});
var stateLabel = new labelModule.Label();
stateLabel.text = "NavPage " + id;
stackLayout.addChild(stateLabel);
@@ -39,13 +47,37 @@ export class NavPage extends pagesModule.Page implements definition.ControlsPage
});
stackLayout.addChild(changeStateButton);
var optionsLayout = new stackLayoutModule.StackLayout();
var addToBackStackLabel = new labelModule.Label();
addToBackStackLabel.text = "backStackVisible";
optionsLayout.addChild(addToBackStackLabel);
var addToBackStackSwitch = new switchModule.Switch();
addToBackStackSwitch.checked = true;
optionsLayout.addChild(addToBackStackSwitch);
var clearHistoryLabel = new labelModule.Label();
clearHistoryLabel.text = "clearHistory";
optionsLayout.addChild(clearHistoryLabel);
var clearHistorySwitch = new switchModule.Switch();
clearHistorySwitch.checked = false;
optionsLayout.addChild(clearHistorySwitch);
stackLayout.addChild(optionsLayout);
var forwardButton = new buttonModule.Button();
forwardButton.text = "->";
forwardButton.on(buttonModule.Button.tapEvent, function () {
var pageFactory = function () {
return new NavPage(id + 1);
};
frameModule.topmost().navigate(pageFactory);
frameModule.topmost().navigate({
create: pageFactory,
backstackVisible: addToBackStackSwitch.checked,
clearHistory: clearHistorySwitch.checked
});
});
stackLayout.addChild(forwardButton);

View File

@@ -29,4 +29,37 @@ export var test_backstackVisible = function() {
frame.topmost().goBack();
TKUnit.waitUntilReady(() => { return frame.topmost().currentPage === mainTestPage; });
}
}
// Clearing the history messes up the tests app.
//export var test_ClearHistory = function () {
// var pageFactory = function (): pageModule.Page {
// return new pageModule.Page();
// };
// var mainTestPage = frame.topmost().currentPage;
// var currentPage: pageModule.Page;
// currentPage = frame.topmost().currentPage;
// frame.topmost().navigate({ create: pageFactory });
// TKUnit.waitUntilReady(() => { return frame.topmost().currentPage !== currentPage; });
// currentPage = frame.topmost().currentPage;
// frame.topmost().navigate({ create: pageFactory });
// TKUnit.waitUntilReady(() => { return frame.topmost().currentPage !== currentPage; });
// currentPage = frame.topmost().currentPage;
// frame.topmost().navigate({ create: pageFactory });
// TKUnit.waitUntilReady(() => { return frame.topmost().currentPage !== currentPage; });
// TKUnit.assert(frame.topmost().canGoBack(), "Frame should be able to go back.");
// TKUnit.assert(frame.topmost().backStack.length === 3, "Back stack should have 3 entries.");
// // Navigate with clear history.
// currentPage = frame.topmost().currentPage;
// frame.topmost().navigate({ create: pageFactory, clearHistory: true });
// TKUnit.waitUntilReady(() => { return frame.topmost().currentPage !== currentPage; });
// TKUnit.assert(!frame.topmost().canGoBack(), "Frame should NOT be able to go back.");
// TKUnit.assert(frame.topmost().backStack.length === 0, "Back stack should have 0 entries.");
//}