Closed Whip closed 6 years ago
Hi @VeeK727,
We investigated the project and found that the issue in your case is related to the fact that the items in the RadListView have been removed and added on every page loaded event. And regarding that, the ListView will try to restart the state of the selected items, before the items have been loaded. To solve your case, I would suggest to set up a flag which will set up the request to be executed on the initial page load. For example:
let firstload = true;
exports.onLoaded = function(args) {
page = args.object;
if(firstload){
purityVM = new observableModule.fromObject({
userAvatar: settings.getString("userAvatar"),
userEmail: settings.getString("userEmail")
});
purities = new observableArrayModule.ObservableArray();
page.bindingContext = purityVM;
prodSearchCriteria = page.navigationContext;
purityVM.set("purities", purities);
console.log(prodSearchCriteria);
http.request({
url: config.apiUrl+"purities.php",
method: "POST",
headers: { "Content-Type": "application/json" },
content: JSON.stringify({
auth: config.apiAuth,
category: prodSearchCriteria.category
})
}).then(function(request){
var response = JSON.parse(request.content);
for (var i = 0; i < response.data.length; i++) {
purities.push({
id: response.data[i].id,
name: response.data[i].name,
image: config.siteUrl+"/img/icons/"+response.data[i].icon,
width: boxWidth
});
}
// console.log(purities);
}, function(error){
console.log(JSON.stringify(error));
});
selectionList = view.getViewById(page, "selectionList");
}
firstload=false;
}
That does work ... but kinda. I can come back to the page now but if I go to home page > categories > purities. THe page is loaded blank. It seems the flag is still set to false, but the data is gone.
Edit: Is there a way to learn whether user is clicking on items in the app to "move forwards" or using back button to "move backwards"? I'm having other issues too which could be solved with this, like product list page is not saving filters when you go to detail page and back because everything gets loaded like a new page.
Hi @VeeK727,
In Android, you can capture the tap on the back button. Check out the article here. You can also check if some of the page events will help you to solve your case navigatedTo
, navigatingTo
, navigatedFrom
, navigatingFrom
- https://pointdeveloper.com/nativescript-page-navigation-events/
Thank you very much for the article. I've been looking for this since I started my first NS project. This article doesn't come up in my search, instead I've been using this weird code which I can't even understand. Using the code in your linked article, I set a boolean in application-settings to true and I run my code only when this code is false. Here's the code if someone else need this. app.js
function backEvent(args) {
var currentPage = frame.topmost().currentPage;
if (currentPage && currentPage.exports && typeof currentPage.exports.backEvent === "function") {
currentPage.exports.backEvent(args); //if you need to take a custom action on one or some pages you can define backEvent function on that page and it will be executed. Otherwise code in 'else' will be executed
} else {
settings.setBoolean("comingBack", true);
}
}
On every page
exports.onLoaded = function(args){
if(settings.getBoolean("comingBack") == false){
// load your page, run your code
} else {
settings.setBoolean("comingBack", false); // when you come back to this page, set this boolean to false, so any pages you further visit will load. If you pressed back again, this will be set to true by app.js code
}
}
Did you verify this is a real problem by searching the NativeScript Forum?
Yes. THe issue is similar to #350 and #271 but both says the issue has been fixed already
Tell us about the problem
I have a page where I display a list in grid view and multiple selections. User can select desired items and press Next and the ids of the selected items are passed to the next page as context. Now when you press back button the app crashes with following error
If I don't select an item and press Next, then I come back, the page is fine. It seems like RadListView is trying to select the items even before they're loaded.
Which platform(s) does your issue occur on?
Android
Please provide the following version numbers that your issue occurs with:
Please tell us how to recreate the issue in as much detail as possible.
Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.
XML
JS
Please use arbitrary values where there isn't one available. Like I can't share the
config.apiAuth
here