Dropdown rendering certain items as blank if selectedIndex manipulated outside
shyamseshadri opened this issue · comments
Happening in a NG + Nativescript App. Only tested on Android.
Seeing cases where if the selectedIndex is manipulated outside the dropdown (via Angular bindings), then the dropdown items disappear.
Have a base repro case for this at https://github.com/shyamseshadri/nativescript-dropdown-bugrepro
Used the basic Nativescript + Ng template.
- Run the app using "tns run android"
- Navigate into an item by clicking on any a list item.
- You should see a drop down list with items 1 to 15, and an Add or Subtract button
- Click Add button a few times.
- Click and open the dropdown, you should see missing items.
Checked the other issues, (#163), this is happening even when it is not in a TabView
@PeterStaev debugged this a bit more, from what I can make out, the following is happening:
- The issue seems to be in the _getRealizedView function: https://github.com/PeterStaev/NativeScript-Drop-Down/blob/master/drop-down.android.ts#L188
- For some reason, when I trigger the flow above,
this._realizedItems[realizedViewType].get(convertView)
seems to be null. - If I make the following addition to the beginning of the method, then it starts to work:
public _getRealizedView(convertView: android.view.View, realizedViewType: RealizedViewType): View {
if (convertView) {
let layout = this._realizedItems[realizedViewType].get(convertView);
if (layout) {
return layout;
}
convertView = null;
}
if (!convertView) {
// Same as before
Again, not sure of the implication of making this change though...
Hey @shyamseshadri , thanks for looking into this. Seems the problem is with this line: https://github.com/PeterStaev/NativeScript-Drop-Down/blob/master/drop-down.android.ts#L463
Last time I checked for some reason the Spinner never reused views. So this ended up making the _realizedItems
full of views that were not getting disposed but also were not used. I have to debug this a bit more and see what would be the best way to handle this.
Super, sounds good. I'm going to use my hack locally in the meantime to create my builds so its not a stopper, let me know if I can help in anyway