infinitered / bluepotion

Like RedPotion, but for Android
MIT License
74 stars 18 forks source link

Android is tripping over reusable views in some lists. #73

Closed skellock closed 9 years ago

skellock commented 9 years ago

Heyo. Having a few issues with the cell reuse in PMBaseAdapter.

I believe the problem is here:

https://github.com/infinitered/bluepotion/blob/master/lib/project/pro_motion/adapters/pm_base_adapter.rb#L121

I don't think we're going to be able to rely the contents of the adapter to determine which view types are available. They might be in the wrong order or not exist.

Here's the setup I'm seeing right now:

My data starts off like this: [B] and my extra_view_types are [A, B, C, D]. Blue potion then compiles this to: [B, A, B, C, D].

My data refreshes and my list becomes:

[A, C, C, C, C, C, D]. Which, when updating views, compiles to [A, C, D, A, B, C, D].

Problem is here, for slot 1, Android gives me a B view for my A contents.

Android seems to be caching the views in a structure we can't modify. That list gets set once. On first load. Although we can try to change the index of the view with getItemViewType, we can never change what Android is really holding in that position.

That's why I went with the lookup list up (cell_types class method + lookup key in table_data cells) in the original implementation. I didn't like it, but it seemed to be the only want heterogenous lists would work for me.

That's what I've seen at least.

skellock commented 9 years ago

My fix for now is:

class PMBaseAdapterFix < PMBaseAdapter
  def view_types
    @extra_view_types
  end
end

# also override PMListScreen to swap out adapters

And I put the complete list in extra_view_types.

So this isn't super critical to fix right now if you don't have time.

GantMan commented 9 years ago

woops I typed 71 when I meant 73: This should be fixed now.