Skip to content

View try to trigger method on a null object in initIndicator methold in class BannerViewPager #356

@ryan20012013

Description

@ryan20012013

Hi,

    if (isCustomIndicator) {
      mIndicatorLayout.removeAllViews();
    } else if (mIndicatorView == null) {
      mIndicatorView = new IndicatorView(getContext());
    }

There is a case where the isCustomIndicator is true and the mIndicatorView is null.
In BottomNavigationView, the fragment does not destroy when switching tab but goes through onViewDestory and onCreateView.
Given the following condition:

  1. BannerViewPager is marked with a id in xml layout
  2. BannerViewPager is created between the onCreateView and onViewDestory
  3. create configuration is different between the 2 create, in my case, one uses setIndicatorView and the other dont (Init data have >= 2 item and the second time it have 1 where no indicator will be shown)

The combination of 1 and 2 cause the onRestoreInstanceState onSaveInstanceState passing state between different instance of view thus leading to a isCustomIndicator set to true but mIndicatorView is null.

I know this might be considered as a incorrect way of using the library given the existence of refreshData and setIndicatorVisibility, but i still think it would be a better idea to

    if (mIndicatorView != null) {
      mIndicatorLayout.removeAllViews();
    } else {
      mIndicatorView = new IndicatorView(getContext());
    }

in setIndicatorValues which covers all the logical cases.

Please let me know you thought on this and what else do i needed to provide. For example to reproduce, if needed, i should be able to provide it on Saturday.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions