[Android] Fix issue using SwipeView in ListView using a RippleEffect (#11380)
* Added repro sample * Fixed the issue Co-authored-by: Samantha Houts <samhouts@users.noreply.github.com> fixes #11374
This commit is contained in:
Родитель
c8ccf6089c
Коммит
3ebae5dd11
|
@ -0,0 +1,40 @@
|
|||
using Android.Util;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Internals;
|
||||
using Xamarin.Forms.Platform.Android;
|
||||
using AView = Android.Views.View;
|
||||
|
||||
[assembly: ExportEffect(typeof(Xamarin.Forms.ControlGallery.Android.RippleEffect), nameof(Xamarin.Forms.ControlGallery.Android.RippleEffect))]
|
||||
namespace Xamarin.Forms.ControlGallery.Android
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
public class RippleEffect : PlatformEffect
|
||||
{
|
||||
protected override void OnAttached()
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Container is AView view)
|
||||
{
|
||||
view.Clickable = true;
|
||||
view.Focusable = true;
|
||||
|
||||
using (var outValue = new TypedValue())
|
||||
{
|
||||
view.Context.Theme.ResolveAttribute(Resource.Attribute.selectableItemBackground, outValue, true);
|
||||
view.SetBackgroundResource(outValue.ResourceId);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnDetached()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -137,6 +137,7 @@
|
|||
<Compile Include="Issue7249SwitchRenderer.cs" />
|
||||
<Compile Include="_9087CustomRenderer.cs" />
|
||||
<Compile Include="_10940CustomRenderer.cs" />
|
||||
<Compile Include="RippleEffect.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AndroidAsset Include="Assets\default.css" />
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<local:TestContentPage xmlns="http://xamarin.com/schemas/2014/forms"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
|
||||
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="using:Xamarin.Forms.Controls"
|
||||
xmlns:effects="clr-namespace:Xamarin.Forms.Controls.Issues"
|
||||
mc:Ignorable="d"
|
||||
Title="Test 11374"
|
||||
x:Class="Xamarin.Forms.Controls.Issues.Issue11374">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Label
|
||||
Padding="12"
|
||||
BackgroundColor="Black"
|
||||
TextColor="White"
|
||||
Text="Swipe an Item to the right or left. If you can open the SwipeView, the test has passed."/>
|
||||
<ListView
|
||||
x:Name="ItemsListView"
|
||||
Grid.Row="1"
|
||||
ItemsSource="{Binding Items}"
|
||||
VerticalOptions="FillAndExpand"
|
||||
HasUnevenRows="true"
|
||||
SelectionMode="Single"
|
||||
SeparatorVisibility="None"
|
||||
CachingStrategy="RecycleElementAndDataTemplate">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ViewCell Height="64">
|
||||
<SwipeView>
|
||||
<SwipeView.LeftItems>
|
||||
<SwipeItems
|
||||
SwipeBehaviorOnInvoked="Close">
|
||||
<SwipeItemView>
|
||||
<Label
|
||||
Text="Left Swipe"
|
||||
Padding="25,0,25,0"
|
||||
VerticalOptions="FillAndExpand"
|
||||
VerticalTextAlignment="Center">
|
||||
</Label>
|
||||
</SwipeItemView>
|
||||
</SwipeItems>
|
||||
</SwipeView.LeftItems>
|
||||
<SwipeView.RightItems>
|
||||
<SwipeItems SwipeBehaviorOnInvoked="Close">
|
||||
<SwipeItemView>
|
||||
<Label
|
||||
Text="Right Swipe"
|
||||
Padding="25,0,25,0"
|
||||
VerticalOptions="FillAndExpand"
|
||||
VerticalTextAlignment="Center">
|
||||
</Label>
|
||||
</SwipeItemView>
|
||||
</SwipeItems>
|
||||
</SwipeView.RightItems>
|
||||
<ContentView
|
||||
BackgroundColor="White">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.Effects>
|
||||
<effects:RippleEffect />
|
||||
</Grid.Effects>
|
||||
<StackLayout Padding="10">
|
||||
<Label
|
||||
Text="{Binding .}"
|
||||
d:Text="{Binding .}"
|
||||
LineBreakMode="NoWrap"
|
||||
FontSize="16" />
|
||||
</StackLayout>
|
||||
</Grid>
|
||||
</ContentView>
|
||||
</SwipeView>
|
||||
</ViewCell>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
</Grid>
|
||||
</local:TestContentPage>
|
|
@ -0,0 +1,69 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Xamarin.Forms.CustomAttributes;
|
||||
using Xamarin.Forms.Internals;
|
||||
|
||||
#if UITEST
|
||||
using Xamarin.UITest;
|
||||
using NUnit.Framework;
|
||||
using Xamarin.Forms.Core.UITests;
|
||||
#endif
|
||||
|
||||
namespace Xamarin.Forms.Controls.Issues
|
||||
{
|
||||
[Preserve(AllMembers = true)]
|
||||
[Issue(IssueTracker.Github, 11374,
|
||||
"[Bug] [Android] SwipeView in ListView is not working with RippleEffect and Release configuration",
|
||||
PlatformAffected.Android)]
|
||||
public partial class Issue11374 : TestContentPage
|
||||
{
|
||||
public Issue11374()
|
||||
{
|
||||
#if APP
|
||||
Device.SetFlags(new List<string> { ExperimentalFlags.SwipeViewExperimental });
|
||||
|
||||
InitializeComponent();
|
||||
#endif
|
||||
}
|
||||
|
||||
protected override void Init()
|
||||
{
|
||||
BindingContext = new Issue11374ViewModel();
|
||||
}
|
||||
}
|
||||
|
||||
[Preserve(AllMembers = true)]
|
||||
public class Issue11374ViewModel : BindableObject
|
||||
{
|
||||
public ObservableCollection<string> Items { get; set; }
|
||||
|
||||
public Command LoadItemsCommand { get; set; }
|
||||
|
||||
public Issue11374ViewModel()
|
||||
{
|
||||
LoadItems();
|
||||
}
|
||||
|
||||
void LoadItems()
|
||||
{
|
||||
Items = new ObservableCollection<string>
|
||||
{
|
||||
"Item 1",
|
||||
"Item 2",
|
||||
"Item 3",
|
||||
"Item 4",
|
||||
"Item 5"
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[Preserve(AllMembers = true)]
|
||||
public class RippleEffect : RoutingEffect
|
||||
{
|
||||
public RippleEffect() : base($"{Effects.ResolutionGroupName}.{nameof(RippleEffect)}")
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1440,6 +1440,7 @@
|
|||
<Compile Include="$(MSBuildThisFileDirectory)Issue11291.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue11244.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue11272.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue11374.xaml.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue11430.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Issue11247.cs" />
|
||||
</ItemGroup>
|
||||
|
@ -1690,6 +1691,9 @@
|
|||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11120.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11374.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11262.xaml">
|
||||
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
|
||||
</EmbeddedResource>
|
||||
|
|
|
@ -277,7 +277,7 @@ namespace Xamarin.Forms.Platform.Android
|
|||
|
||||
public override bool OnInterceptTouchEvent(MotionEvent e)
|
||||
{
|
||||
return false;
|
||||
return ShouldInterceptTouch(e);
|
||||
}
|
||||
|
||||
public override bool DispatchTouchEvent(MotionEvent e)
|
||||
|
|
Загрузка…
Ссылка в новой задаче