I've been watching the React on Native framework from the Android Native components - ReactHorizontalScrollView, Found a method of getOverScrollerFromParent use reflection to obtain mScroller, but through access private API in the form of access to, will be lint to check out mistakes - DiscouragePrivateAPI, this way is not safe? In case the private API changes in the future, mScroller returns a null value? Is there a better solution? Here it the code:
@Nullable
private OverScroller getOverScrollerFromParent() {
OverScroller scroller;
if (!sTriedToGetScrollerField) {
sTriedToGetScrollerField = true;
try {
//Reflective access to mScroller, which is not part of the public SDK and therefore likely to change in future Android releases
sScrollerField =
HorizontalScrollView.class.getDeclaredField("mScroller");
sScrollerField.setAccessible(true);
} catch (NoSuchFieldException e) {
FLog.w(
TAG,
"Failed to get mScroller field for HorizontalScrollView! "
+ "This app will exhibit the bounce-back scrolling bug :(");
}
}
...
return scroller;
}