mirror of
https://github.com/status-im/react-native.git
synced 2025-02-28 17:10:50 +00:00
fix removing views from ViewPagerAndroid
Summary: Two things in this diff: 1. Implemented `getItemPosition` in our adapter; the default implementation always returns POSITION_UNCHANGED, which is incorrect, and causes `destroyItem` to never (sometimes?) be called. 2. Fix `destroyItem`: this never worked. `destroyItem` is always called by the ViewPager after a `notifyDataSetChanged()`, so after `removeViewAt`, which removes the view from `mViews`, causing `destroyItem` to throw `IndexOutOfBoundsException` when it tries to get the view. Since our item objects are just views, use that instead of checking `mViews`. Reviewed By: ahmedre Differential Revision: D3555427 fbshipit-source-id: 900c2696162d07f507e850517d483b943ce39a35
This commit is contained in:
parent
03a2f6139f
commit
b0c023c85c
@ -33,7 +33,7 @@ import com.facebook.react.uimanager.events.NativeGestureUtil;
|
||||
|
||||
private class Adapter extends PagerAdapter {
|
||||
|
||||
private List<View> mViews = new ArrayList<>();
|
||||
private final List<View> mViews = new ArrayList<>();
|
||||
|
||||
void addView(View child, int index) {
|
||||
mViews.add(index, child);
|
||||
@ -67,6 +67,11 @@ import com.facebook.react.uimanager.events.NativeGestureUtil;
|
||||
return mViews.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemPosition(Object object) {
|
||||
return mViews.contains(object) ? mViews.indexOf(object) : POSITION_NONE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
View view = mViews.get(position);
|
||||
@ -76,8 +81,7 @@ import com.facebook.react.uimanager.events.NativeGestureUtil;
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
View view = mViews.get(position);
|
||||
container.removeView(view);
|
||||
container.removeView((View) object);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
x
Reference in New Issue
Block a user