-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to keep a page loaded (instead of re-rendering it) when using an ons-sliding-menu or an ons-split-view #21
Comments
+1 |
I've added a simple (and maybe ugly) ability to cache pages in Sliding Menu, by adding the code below to scope.ons.slidingMenu.setAbovePage: scope.ons.slidingMenu.setAbovePage = function (pageUrl) {
if (this.currentPageUrl === pageUrl) {
// same page -> ignore
return;
}
if (pageUrl) {
var cachedPage = this.cachedPages[pageUrl];
if (!cachedPage) {
$http({
url: pageUrl,
method: "GET"
}).error(function (e) {
console.error(e);
}).success(function (data, status, headers, config) {
var templateHTML = angular.element(data.trim());
var pageElement = angular.element('<div></div>');
pageElement.addClass('page');
pageElement[0].style.opacity = 0;
var pageContent = $compile(templateHTML)(scope);
pageElement.append(pageContent);
this.$abovePage.append(pageElement);
this.cachedPages[config.url] = pageElement;
// prevent black flash
setTimeout(function () {
pageElement[0].style.opacity = 1;
if (this.currentPageElement) {
// this.currentPageElement.remove();
this.currentPageElement.addClass('hiddenView');
}
this.currentPageElement = pageElement;
}.bind(this), 0);
this.currentPageUrl = pageUrl;
}.bind(this));
} else {
// We opt for the cached version of the page
// this.$abovePage.append(cachedPage);
cachedPage.removeClass('hiddenView');
setTimeout(function () {
cachedPage[0].style.opacity = 1;
if (this.currentPageElement) {
//this.currentPageElement.remove();
this.currentPageElement.addClass('hiddenView');
}
this.currentPageElement = cachedPage;
}.bind(this), 0);
this.currentPageUrl = pageUrl;
}
} else {
throw new Error('cannot set undefined page');
}
}.bind(this); css .hiddenView {
display: none;
} I'm not removing the page from the dom, but instead hiding it. If the page is removed (instead of hidden), attached bindings stop working (for example, if the page has an ons-navigator-toolbar, click on buttons will not work if you open a cached page). |
Great job!! |
Hey @kruyvanna , I guess you'll like this: our app built with OnsenUI is now available in App Store and Google Play: https://itunes.apple.com/en/app/boonzi-personal-finance/id808920979 The fix I proposed in this issue is working just fine in this app, along with the changes you did in the navigation branch. :) |
@JoaoSaleiro : wow this is amazing!!! 👍 Also if you like, you can write a blog about your app in our blog. Again, great job!! |
By the way, we searched for the app in Japan's Google Play, but it's not there. |
Hey @kruyvanna, sorry for the late answer. |
great! |
When using an ons-sliding-menu or a ons-split-view, it's common the need to keep a page loaded in background, instead of reloading and re-rendering it.
Imagine the following scenario:
1- An app with an ons-sliding-menu
2- The most used page (mainPage.html) is a List with data, where the user is working with that data
3- The user frequently uses the ons-sliding-menu to navigate to other sections, but he will frequently get back to the mainPage.html
4- While navigating, mainPage.html is being re-rendered all the time. This creates two issues: a) it's really hard for the developer to keep the state of the mainPage.html b) it slows down the navigation
ons-sliding-menu should introduce the ability to keep a page cached, instead of re-rendering it completely
The text was updated successfully, but these errors were encountered: