Skip to content

Commit

Permalink
Fixes #37
Browse files Browse the repository at this point in the history
ensure that we actually need to move it and save out original cords
  • Loading branch information
jamesmontemagno committed Feb 2, 2018
1 parent dc5ba9a commit 7c293c3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
39 changes: 31 additions & 8 deletions PullToRefresh/PullToRefresh.iOS/PullToRefreshLayoutRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,26 +78,40 @@ protected override void OnElementChanged (ElementChangedEventArgs<Refractored.Xa
UpdateIsSwipeToRefreshEnabled();
}

bool set;
nfloat origininalY;

bool TryOffsetRefresh(UIView view, bool refreshing, int index = 0)
{
if (view is UITableView)
{
var uiTableView = view as UITableView;
if (!set)
{
origininalY = uiTableView.ContentOffset.Y;
set = true;
}

if (refreshing)
uiTableView.SetContentOffset(new CoreGraphics.CGPoint(0, uiTableView.ContentOffset.Y - refreshControl.Frame.Size.Height), true);
uiTableView.SetContentOffset(new CoreGraphics.CGPoint(0, origininalY - refreshControl.Frame.Size.Height), true);
else
uiTableView.SetContentOffset(new CoreGraphics.CGPoint(0, uiTableView.ContentOffset.Y + refreshControl.Frame.Size.Height), true);
uiTableView.SetContentOffset(new CoreGraphics.CGPoint(0, origininalY), true);
return true;
}

if (view is UICollectionView)
{

var uiCollectionView = view as UICollectionView;
if (!set)
{
origininalY = uiCollectionView.ContentOffset.Y;
set = true;
}
if (refreshing)
uiCollectionView.SetContentOffset(new CoreGraphics.CGPoint(0, uiCollectionView.ContentOffset.Y - refreshControl.Frame.Size.Height), true);
uiCollectionView.SetContentOffset(new CoreGraphics.CGPoint(0, origininalY - refreshControl.Frame.Size.Height), true);
else
uiCollectionView.SetContentOffset(new CoreGraphics.CGPoint(0, uiCollectionView.ContentOffset.Y + refreshControl.Frame.Size.Height), true);
uiCollectionView.SetContentOffset(new CoreGraphics.CGPoint(0, origininalY), true);
return true;
}

Expand All @@ -112,10 +126,16 @@ bool TryOffsetRefresh(UIView view, bool refreshing, int index = 0)
if (view is UIScrollView)
{
var uiScrollView = view as UIScrollView;

if (!set)
{
origininalY = uiScrollView.ContentOffset.Y;
set = true;
}
if (refreshing)
uiScrollView.SetContentOffset(new CoreGraphics.CGPoint(0, uiScrollView.ContentOffset.Y - refreshControl.Frame.Size.Height), true);
uiScrollView.SetContentOffset(new CoreGraphics.CGPoint(0, origininalY - refreshControl.Frame.Size.Height), true);
else
uiScrollView.SetContentOffset(new CoreGraphics.CGPoint(0, uiScrollView.ContentOffset.Y + refreshControl.Frame.Size.Height), true);
uiScrollView.SetContentOffset(new CoreGraphics.CGPoint(0, origininalY), true);
return true;
}

Expand Down Expand Up @@ -250,14 +270,17 @@ public bool IsRefreshing
{
get { return isRefreshing;}
set
{
{
bool changed = IsRefreshing != value;

isRefreshing = value;
if (isRefreshing)
refreshControl.BeginRefreshing();
else
refreshControl.EndRefreshing();

TryOffsetRefresh(this, IsRefreshing);
if(changed)
TryOffsetRefresh(this, IsRefreshing);
}
}

Expand Down
7 changes: 7 additions & 0 deletions RefreshSample/Views/ScrollViewPageManual.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public ScrollViewPageManual(bool insideLayout)
BindingContext = new TestViewModel (this);
var buttonStart = new Button { Text = "Start" };
var buttonStop = new Button { Text = "Stop" };
var buttonStartStop = new Button { Text = "Start/Stop" };

var grid = new Grid
{
Expand Down Expand Up @@ -80,6 +81,11 @@ public ScrollViewPageManual(bool insideLayout)

buttonStart.Clicked += (sender, args) => refreshView.IsRefreshing = true;
buttonStop.Clicked += (sender, args) => refreshView.IsRefreshing = false;
buttonStartStop.Clicked += (sender, args) =>
{
refreshView.IsRefreshing = true;
refreshView.IsRefreshing = false;
};


if (insideLayout)
Expand All @@ -100,6 +106,7 @@ public ScrollViewPageManual(bool insideLayout)
},
buttonStart,
buttonStop,
buttonStartStop,
refreshView
}
};
Expand Down

0 comments on commit 7c293c3

Please sign in to comment.