Run the given callback only inside runOnPageScrollsInitialized
Let `PagedView.runOnPageScrollsInitialized` run the given callback only instead of running all the current existing callbacks inside `mOnPageScrollsInitializedCallbacks` once `mPageScrolls` has been initialized. All the existing callbacks will be run by `PagedView.onPageScrollsInitialized` instead. By doing this, we can avoid some unexpected crash while running the pending callbacks in some scenarios. E.g., removeAllViews. Flag: EXEMPT fix a regression Bug: 385612978 Test: Manual Change-Id: I0877cff752aabd1569dd54a9d04001687f90a5f6
This commit is contained in:
@@ -718,12 +718,14 @@ public abstract class PagedView<T extends View & PageIndicator> extends ViewGrou
|
||||
}
|
||||
|
||||
/**
|
||||
* Queues the given callback to be run once {@code mPageScrolls} has been initialized.
|
||||
* Run the given `callback` immediately once {@code mPageScrolls} has been initialized,
|
||||
* otherwise queue the callback to `mOnPageScrollsInitializedCallbacks`.
|
||||
*/
|
||||
public void runOnPageScrollsInitialized(Runnable callback) {
|
||||
mOnPageScrollsInitializedCallbacks.add(callback);
|
||||
if (isPageScrollsInitialized()) {
|
||||
onPageScrollsInitialized();
|
||||
callback.run();
|
||||
} else {
|
||||
mOnPageScrollsInitializedCallbacks.add(callback);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user