- // Dispatch the nested scroll.
- dispatchNestedScroll(0, deltaY, 0, 0, null);
+ // Set the scroll delta Y to initially be the same as the pre-scroll delta Y.
+ int scrollDeltaY = preScrollDeltaY;
+
+ // Dispatch the nested pre-school. This scrolls the app bar if it needs it. `offsetInWindow` will be returned with an updated value.
+ if (dispatchNestedPreScroll(0, preScrollDeltaY, consumedScroll, offsetInWindow)) {
+ // Update the scroll delta Y if some of it was consumed.
+ scrollDeltaY = preScrollDeltaY - consumedScroll[1];
+ }
+
+ // Check to see if the WebView is at the top and and the scroll action is downward.
+ if ((webViewYPosition == 0) && (scrollDeltaY < 0)) { // Swipe to refresh is being engaged.
+ // Stop the nested scroll so that swipe to refresh has complete control.
+ stopNestedScroll();
+ } else { // Swipe to refresh is not being engaged.
+ // Start the nested scroll so that the app bar can scroll off the screen.
+ startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
+
+ // Dispatch the nested scroll. This scrolls the WebView. The delta Y unconsumed normally controls the swipe refresh layout, but that is handled with the `if` statement above.
+ dispatchNestedScroll(0, scrollDeltaY, 0, 0, offsetInWindow);
+
+ // Store the current Y position for use in the next action move.
+ previousYPosition = previousYPosition - scrollDeltaY;
+ }