jamesmontemagno / Xamarin.Forms-PullToRefreshLayout

Pull To Refresh a ScrollView or ListView in Xamarin.Forms
218 stars 49 forks source link

iOS PullToRefreshLayoutRenderer can be simplified #67

Closed gaocan1992 closed 4 years ago

gaocan1992 commented 5 years ago

I don't think you have to insert refresh control as a subview. It has been already a property of UITableView, UICollectionView and UIScrollView. So even TryOffSetRefresh method is not required if I make this change.

protected bool TryInsertRefresh(UIView view) {
            // Save the refresh control parent.
            refreshControlParent = view;

            if (view is UITableView) {
                var uiTableView = view as UITableView;
                uiTableView = view as UITableView;
                uiTableView.RefreshControl = refreshControl;
                return true;
            }

            if (view is UICollectionView) {
                var uiCollectionView = view as UICollectionView;
                uiCollectionView = view as UICollectionView;
                uiCollectionView.RefreshControl = refreshControl;
                return true;
            }

            if (view is UIWebView) {
                var uiWebView = view as UIWebView;
                uiWebView.ScrollView.RefreshControl = refreshControl;
                return true;
            }

            if (view is UIScrollView) {
                var uiScrollView = view as UIScrollView;
                uiScrollView.RefreshControl = refreshControl;
                uiScrollView.AlwaysBounceVertical = true;
                return true;
            }

            if (view.Subviews == null) return false;

            for (int i = 0; i < view.Subviews.Length; i++) {
                var control = view.Subviews[i];
                if (TryInsertRefresh(control)) return true;
            }

            return false;
        }
public bool IsRefreshing {
            get => _isRefreshing;
            set {
                _isRefreshing = value;
                if (_isRefreshing) {
                    refreshControl.BeginRefreshing();
                }
                else {
                    refreshControl.EndRefreshing();
                }
            }
        }
        private bool _isRefreshing;
jamesmontemagno commented 4 years ago

This library will soon be deprecated by the official RefreshView as part of Xamarin.Forms 4.3. No further work will be done on this library.