Skip to content
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

[Android] Pager multiple itemTemplates do not work when dynamically loading data #47

Closed
PeterStaev opened this issue Mar 9, 2018 · 1 comment
Assignees

Comments

@PeterStaev
Copy link

So I have an ObservableArray that is first initialized with null values. Then when the index of the pager is changed I'm loading data from the backend and replacing the null value with the appropriate Observable model object for the view. I'm having 2 different templates - one that is for null object and one for non-null objects. After the data is loaded and I replace the null object it still shows the blank template for the item. From what I've traced this is due to two problems:

  1. The code in the instantiateItem does not take into consideration the template, it is just based by index:
    const template = this.owner._getItemTemplate(position);
    if (this.owner._viewMap.has(position)) {
    const cachedView = this.owner._viewMap.get(position);
    let convertView = cachedView ? cachedView.nativeView : null;
    if (convertView) {
    // collection.addView(convertView);
    return convertView;
    }
    }

    This can easily be fixed by instead using just the position to use ${position}-${template.key} as the key for the cached view map.
  2. (The bigger one) Although when an item in the ObservableArray is changed the refres() methos is correctly called but the adapter's notifyDataSetChanged() does not cause the views to be regenerated. So basically it does nothing... You can read more about the possible solutions here: https://stackoverflow.com/a/7287121/5272836.
@triniwiz triniwiz self-assigned this Mar 11, 2018
@triniwiz
Copy link
Owner

Great suggestions @PeterStaev

@triniwiz triniwiz added the bug label Mar 11, 2018
triniwiz added a commit that referenced this issue Dec 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants