Skip to content

Commit

Permalink
Merge branch '4.0.0' into 4.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarinho committed Jun 11, 2019
2 parents 70f8363 + 15b01e5 commit 17a60f6
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void Init ()
{
var listview = new ListView ();
listview.ItemTemplate = new DataTemplate (typeof (ItemTemplate));
listview.ItemsSource = new string[] { "item1", "item2", "item3", "item4", "item5" };
listview.ItemsSource = new string[] { "item1", "item2", "item3", "item4", "item5", null, null };
var btnBack = new Button { Text = "back", Command = new Command (() => Navigation.PopAsync ()) };
listview.ItemSelected += (s, e) => Navigation.PushAsync (new ContentPage { Content = btnBack });
var btnPush = new Button {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Xamarin.Forms.Controls.Issues.Issue5268">
<ListView x:Name="MyListView"
IsPullToRefreshEnabled="True"
IsRefreshing="{Binding IsBusy, Mode=OneWay}"
ItemsSource="{Binding Sources}"
BackgroundColor="Blue"
RefreshCommand="{Binding Command}" RowHeight="100">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ScrollView>
<StackLayout>
<Label Text="{Binding Val}" MaxLines="100" HorizontalTextAlignment="Center" TextColor="White" FontSize="14" />
<Label Text="{Binding Val}" MaxLines="100" HorizontalTextAlignment="Center" TextColor="White" FontSize="14" />
<Label Text="{Binding Val}" MaxLines="100" HorizontalTextAlignment="Center" TextColor="White" FontSize="14" />
<Label Text="{Binding Val}" MaxLines="100" HorizontalTextAlignment="Center" TextColor="White" FontSize="14" />
<Label Text="{Binding Val}" MaxLines="100" HorizontalTextAlignment="Center" TextColor="White" FontSize="14" />
</StackLayout>
</ScrollView>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#if APP
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 5268, "ListView with PullToRefresh enabled gestures conflict", PlatformAffected.Android)]
public partial class Issue5268 : ContentPage
{
[Preserve(AllMembers = true)]
public class SrcItem
{
public string Val { get; set; }
}

string GenerateLongString() => string.Join(" \n", Enumerable.Range(0, 50).Select(i => $"{Sources.Count} item"));

public ObservableCollection<SrcItem> Sources { get; }
public ICommand Command { get; }

public Issue5268()
{
InitializeComponent();
Sources = new ObservableCollection<SrcItem>();
Command = new Command(AddData);
Sources.Add(new SrcItem { Val = GenerateLongString() });
MyListView.BindingContext = this;
}

void AddData()
{
IsBusy = true;
Sources.Add(new SrcItem { Val = GenerateLongString() });
IsBusy = false;
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,10 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue6130.xaml.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Issue5268.xaml.cs">
<DependentUpon>Issue5268.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)LegacyComponents\NonAppCompatSwitch.cs" />
<Compile Include="$(MSBuildThisFileDirectory)MapsModalCrash.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ModalActivityIndicatorTest.cs" />
Expand Down Expand Up @@ -1249,4 +1253,10 @@
<DependentUpon>Issue6130.xaml</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue5268.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</EmbeddedResource>
</ItemGroup>
</Project>
57 changes: 55 additions & 2 deletions Xamarin.Forms.Platform.Android/Renderers/ListViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
using Android.Widget;
using Android.Runtime;

namespace Xamarin.Forms.Platform.Android
{
Expand Down Expand Up @@ -102,6 +103,9 @@ protected override Size MinimumSize()
return new Size(40, 40);
}

protected virtual SwipeRefreshLayout CreateNativePullToRefresh(Context context)
=> new SwipeRefreshLayoutWithFixedNestedScrolling(context);

protected override void OnAttachedToWindow()
{
base.OnAttachedToWindow();
Expand Down Expand Up @@ -154,9 +158,9 @@ protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
nativeListView = CreateNativeControl();
if (Forms.IsLollipopOrNewer)
nativeListView.NestedScrollingEnabled = true;
_refresh = new SwipeRefreshLayout(ctx);
_refresh = CreateNativePullToRefresh(ctx);
_refresh.SetOnRefreshListener(this);
_refresh.AddView(nativeListView, LayoutParams.MatchParent);
_refresh.AddView(nativeListView, new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent));
SetNativeControl(nativeListView, _refresh);

_headerView = new Container(ctx);
Expand Down Expand Up @@ -523,5 +527,54 @@ protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec)
SetMeasuredDimension(widthSpec, heightSpec);
}
}

class SwipeRefreshLayoutWithFixedNestedScrolling : SwipeRefreshLayout
{
float _touchSlop;
float _initialDownY;
bool _nestedScrollAccepted;
bool _nestedScrollCalled;

public SwipeRefreshLayoutWithFixedNestedScrolling(Context ctx) : base(ctx)
{
_touchSlop = ViewConfiguration.Get(ctx).ScaledTouchSlop;
}

public override bool OnInterceptTouchEvent(MotionEvent ev)
{
if (ev.Action == MotionEventActions.Down)
_initialDownY = ev.GetAxisValue(Axis.Y);

var isBeingDragged = base.OnInterceptTouchEvent(ev);

if (!isBeingDragged && ev.Action == MotionEventActions.Move && _nestedScrollAccepted && !_nestedScrollCalled)
{
var y = ev.GetAxisValue(Axis.Y);
var dy = (y - _initialDownY) / 2;
isBeingDragged = dy > _touchSlop;
}

return isBeingDragged;
}

public override void OnNestedScrollAccepted(AView child, AView target, [GeneratedEnum] ScrollAxis axes)
{
base.OnNestedScrollAccepted(child, target, axes);
_nestedScrollAccepted = true;
_nestedScrollCalled = false;
}

public override void OnStopNestedScroll(AView child)
{
base.OnStopNestedScroll(child);
_nestedScrollAccepted = false;
}

public override void OnNestedScroll(AView target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed)
{
base.OnNestedScroll(target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed);
_nestedScrollCalled = true;
}
}
}
}
12 changes: 11 additions & 1 deletion Xamarin.Forms.Platform.UAP/ListViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@ public class ListViewRenderer : ViewRenderer<ListView, FrameworkElement>

protected WListView List { get; private set; }

protected class ListViewTransparent : WListView
{
public ListViewTransparent() : base() { }

// Container is not created when the item is null.
// To prevent this, base container preparationan receives an empty object.
protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
=> base.PrepareContainerForItemOverride(element, item ?? new object());
}

protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)
{
base.OnElementChanged(e);
Expand All @@ -59,7 +69,7 @@ protected override void OnElementChanged(ElementChangedEventArgs<ListView> e)

if (List == null)
{
List = new WListView
List = new ListViewTransparent
{
IsSynchronizedWithCurrentItem = false,
ItemTemplate = (Windows.UI.Xaml.DataTemplate)WApp.Current.Resources["CellTemplate"],
Expand Down

0 comments on commit 17a60f6

Please sign in to comment.