1

I am attempting to hide the ActionBar and FloatingActionButton in native when the user scrolls the content of a ReactNativeView. Intuitively, this should be done with a callback from JS back to native. However, the documentation states "a native module is supposed to invoke its callback only once." This is unsuitable for my use case as I need to be able to monitor a consistent stream of scrolling callbacks.

To get around this, I set up a GlobalLayoutListener on the ReactNativeView and set my OnScrollChangeListener when I observed that React Native injected the ReactScrollView. This works perfectly on API 22. However, on API 21, it throws a NoClassDefFoundError at the point that I attempt to set the OnScrollChangeListener. There are a couple errors above the stack trace: 'Link of class ScrollAnimator failed' and 'Unable to resolve virtual method ScrollView.setOnScrollChangeListener.'

I understand the NoClassDefFoundError arises from the library being present at compile time, but not at run time. This is a project configuration issue often caused by having references to two different versions of the same library. More can be read about NoClassDefFoundError in this popular StackOverflow question.

I am fairly sure I don't have such a project configuration issue because it works just fine on API 22. So, what's going on here then? Further, am I going about solving this problem the right way? Or, is there a better way to emit scroll change events from JS to native?

Community
  • 1
  • 1
Mike Ortiz
  • 4,031
  • 4
  • 27
  • 54

1 Answers1

0

The View.OnScrollChangeListener is added in API level 23. A work around would be to use

mScrollView.getViewTreeObserver().addOnScrollChangedListener(listenerInstance);

The above callback listeners will not be much helpful if you are trying to get X,Y values.

Leons
  • 201
  • 1
  • 7