Skip to content

Commit

Permalink
Fix NPE in RecyclerEventsController
Browse files Browse the repository at this point in the history
Summary: Store mSectionsRecyclerView value in a local var to avoid it being set to null in `setSectionsRecyclerView(..)` between accesses.

Reviewed By: paveldudka

Differential Revision: D13469334

fbshipit-source-id: 76804c1496b769e580a34d4a6eb52e3fc3d68c40
  • Loading branch information
okelepko authored and facebook-github-bot committed Dec 14, 2018
1 parent d40f809 commit 8e29036
Showing 1 changed file with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ public interface OnRecyclerUpdateListener {
new Runnable() {
@Override
public void run() {
if (mSectionsRecyclerView != null && mSectionsRecyclerView.isRefreshing()) {
mSectionsRecyclerView.setRefreshing(false);
SectionsRecyclerView sectionsRecyclerView = mSectionsRecyclerView;
if (sectionsRecyclerView != null && sectionsRecyclerView.isRefreshing()) {
sectionsRecyclerView.setRefreshing(false);
}
}
};
Expand All @@ -60,38 +61,41 @@ public void requestScrollToTop(boolean animated) {
* @param animated if animated is set to true the scroll will happen with an animation.
*/
public void requestScrollToPosition(final int position, final boolean animated) {
if (mSectionsRecyclerView == null) {
SectionsRecyclerView sectionsRecyclerView = mSectionsRecyclerView;
if (sectionsRecyclerView == null) {
return;
}

if (animated) {
mSectionsRecyclerView.getRecyclerView().smoothScrollToPosition(position);
sectionsRecyclerView.getRecyclerView().smoothScrollToPosition(position);
return;
}

mSectionsRecyclerView.getRecyclerView().scrollToPosition(position);
sectionsRecyclerView.getRecyclerView().scrollToPosition(position);
}

public void clearRefreshing() {
if (mSectionsRecyclerView == null || !mSectionsRecyclerView.isRefreshing()) {
SectionsRecyclerView sectionsRecyclerView = mSectionsRecyclerView;
if (sectionsRecyclerView == null || !sectionsRecyclerView.isRefreshing()) {
return;
}

if (ThreadUtils.isMainThread()) {
mSectionsRecyclerView.setRefreshing(false);
sectionsRecyclerView.setRefreshing(false);
return;
}

mSectionsRecyclerView.removeCallbacks(mClearRefreshRunnable);
mSectionsRecyclerView.post(mClearRefreshRunnable);
sectionsRecyclerView.removeCallbacks(mClearRefreshRunnable);
sectionsRecyclerView.post(mClearRefreshRunnable);
}

public void showRefreshing() {
if (mSectionsRecyclerView == null || mSectionsRecyclerView.isRefreshing()) {
SectionsRecyclerView sectionsRecyclerView = mSectionsRecyclerView;
if (sectionsRecyclerView == null || sectionsRecyclerView.isRefreshing()) {
return;
}
ThreadUtils.assertMainThread();
mSectionsRecyclerView.setRefreshing(true);
sectionsRecyclerView.setRefreshing(true);
}

void setSectionsRecyclerView(@Nullable SectionsRecyclerView sectionsRecyclerView) {
Expand All @@ -104,7 +108,8 @@ void setSectionsRecyclerView(@Nullable SectionsRecyclerView sectionsRecyclerView
}

public @Nullable RecyclerView getRecyclerView() {
return mSectionsRecyclerView == null ? null : mSectionsRecyclerView.getRecyclerView();
SectionsRecyclerView sectionsRecyclerView = mSectionsRecyclerView;
return sectionsRecyclerView == null ? null : sectionsRecyclerView.getRecyclerView();
}

public void setOnRecyclerUpdateListener(
Expand Down

0 comments on commit 8e29036

Please sign in to comment.