public void OnScrollChanged(Android.Widget.ScrollView who, int l, int t, int oldl, int oldt) { if (OnScrollChangedListener != null) { OnScrollChangedListener.OnScrollChanged(who, l, t, oldl, oldt); } var isSignificantDelta = Math.Abs(t - lastScrollY) > ScrollThreshold; if (isSignificantDelta) { if (t > lastScrollY) { OnScrollUp(); } else { OnScrollDown(); } } lastScrollY = t; }
private bool CanScrollUp(Android.Views.View view) { if (!RefreshView.IsPullToRefreshEnabled) { return(true); } else { ViewGroup viewGroup = view as ViewGroup; if (viewGroup == null) { return(base.CanChildScrollUp()); } int sdk = (int)global::Android.OS.Build.VERSION.SdkInt; if (sdk >= 16) { // //is a scroll container such as listview, scroll view, gridview // if (viewGroup.IsScrollContainer) { return(base.CanChildScrollUp()); } } // //if you have something custom and you can't scroll up you might need to enable this //for instance on a custom recycler view where the code above isn't working! // for (int i = 0; i < viewGroup.ChildCount; i++) { var child = viewGroup.GetChildAt(i); if (child is Android.Widget.AbsListView) { Android.Widget.AbsListView list = child as Android.Widget.AbsListView; if (list != null) { if (list.FirstVisiblePosition == 0) { Android.Views.View subChild = list.GetChildAt(0); return(subChild != null && subChild.Top != 0); } // //if children are in list and we are scrolled a bit... sure you can scroll up // return(true); } } else if (child is Android.Widget.ScrollView) { Android.Widget.ScrollView scrollview = child as Android.Widget.ScrollView; return(scrollview.ScrollY <= 0.0); } else if (child is Android.Webkit.WebView) { Android.Webkit.WebView webView = child as Android.Webkit.WebView; return(webView.ScrollY > 0.0); } else if (child is Android.Support.V4.Widget.SwipeRefreshLayout) { return(CanScrollUp(child as ViewGroup)); } // //else if something else like a recycler view? // } return(false); } }