Don't crash if OEM has replaced OverScroller in ScrollView

Summary: Some OEMs have changed out the default scroller implementation in their ScrollView. We now check for that case and handle it gracefully instead of crashing.

Reviewed By: foghina

Differential Revision: D3876492

fbshipit-source-id: 4d03b88c4972e939c8352eeb9f30275e3ecf76e2
This commit is contained in:
Andy Street 2016-09-19 04:12:22 -07:00 committed by Facebook Github Bot 9
parent 6565929358
commit 5deb528695
1 changed files with 10 additions and 1 deletions

View File

@ -82,7 +82,16 @@ public class ReactScrollView extends ScrollView implements ReactClippingViewGrou
if (sScrollerField != null) {
try {
mScroller = (OverScroller) sScrollerField.get(this);
Object scroller = sScrollerField.get(this);
if (scroller instanceof OverScroller) {
mScroller = (OverScroller) scroller;
} else {
Log.w(
ReactConstants.TAG,
"Failed to cast mScroller field in ScrollView (probably due to OEM changes to AOSP)! " +
"This app will exhibit the bounce-back scrolling bug :(");
mScroller = null;
}
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to get mScroller from ScrollView!", e);
}