[Android, iOS] Allow transparent background color in SwipeView Content (#9726) fixes #9305

* Allow transparent background color in SwipeView

* Update Xamarin.Forms.Controls.Issues.Shared.projitems

Co-authored-by: Rui Marinho <me@ruimarinho.net>
This commit is contained in:
Javier Suárez Ruiz 2020-03-09 15:29:39 +01:00 коммит произвёл GitHub
Родитель c5e3a46dae
Коммит 515c4553db
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 102 добавлений и 11 удалений

Просмотреть файл

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8" ?>
<controls:TestContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
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"
mc:Ignorable="d"
x:Class="Xamarin.Forms.Controls.Issues.Issue9305">
<ContentPage.Content>
<Grid>
<Image
Aspect="AspectFill"
Source="Fruits.jpg"/>
<StackLayout>
<SwipeView>
<SwipeView.LeftItems>
<SwipeItems>
<SwipeItem
Text="Favorite"
BackgroundColor="LightGreen" />
<SwipeItem
Text="Delete"
BackgroundColor="LightPink" />
</SwipeItems>
</SwipeView.LeftItems>
<Grid
HeightRequest="60"
WidthRequest="300">
<Label
Text="Swipe right"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Grid>
</SwipeView>
<SwipeView
BackgroundColor="Transparent">
<SwipeView.LeftItems>
<SwipeItems>
<SwipeItem
Text="Favorite"
BackgroundColor="LightGreen" />
<SwipeItem
Text="Delete"
BackgroundColor="LightPink" />
</SwipeItems>
</SwipeView.LeftItems>
<Grid
HeightRequest="60"
WidthRequest="300">
<Label
Text="Swipe right"
HorizontalOptions="Center"
VerticalOptions="Center" />
</Grid>
</SwipeView>
</StackLayout>
</Grid>
</ContentPage.Content>
</controls:TestContentPage>

Просмотреть файл

@ -0,0 +1,29 @@
using Xamarin.Forms.CustomAttributes;
using System.Collections.Generic;
#if UITEST
using Xamarin.Forms.Core.UITests;
using Xamarin.UITest;
using NUnit.Framework;
#endif
namespace Xamarin.Forms.Controls.Issues
{
[Issue(IssueTracker.Github, 9305, "Swipe View BackgroundColor Issues", PlatformAffected.Android | PlatformAffected.iOS)]
public partial class Issue9305 : TestContentPage
{
public Issue9305()
{
#if APP
Device.SetFlags(new List<string> { ExperimentalFlags.SwipeViewExperimental });
Title = "Issue 9305";
InitializeComponent();
#endif
}
protected override void Init()
{
}
}
}

Просмотреть файл

@ -1268,6 +1268,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue8777.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue8777.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9588.xaml.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue9588.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9329.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue9329.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9305.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue9767.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Issue9767.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
@ -1418,6 +1419,10 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8326.xaml" /> <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8326.xaml" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8449.xaml" /> <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue8449.xaml" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7924.xaml" /> <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue7924.xaml" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue9305.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue9588.xaml"> <EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue9588.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator> <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource> </EmbeddedResource>
@ -1834,4 +1839,4 @@
<Generator>MSBuild:UpdateDesignTimeXaml</Generator> <Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource> </EmbeddedResource>
</ItemGroup> </ItemGroup>
</Project> </Project>

Просмотреть файл

@ -28,7 +28,6 @@ namespace Xamarin.Forms.Platform.Android
public class SwipeViewRenderer : ViewRenderer<SwipeView, AView>, GestureDetector.IOnGestureListener public class SwipeViewRenderer : ViewRenderer<SwipeView, AView>, GestureDetector.IOnGestureListener
{ {
const int SwipeThreshold = 250; const int SwipeThreshold = 250;
const int SwipeThresholdMargin = 0;
const int SwipeItemWidth = 100; const int SwipeItemWidth = 100;
const long SwipeAnimationDuration = 200; const long SwipeAnimationDuration = 200;
const float SwipeMinimumDelta = 10f; const float SwipeMinimumDelta = 10f;
@ -141,7 +140,7 @@ namespace Xamarin.Forms.Platform.Android
SetBackgroundColor(backgroundColor); SetBackgroundColor(backgroundColor);
if (Element.Content == null) if (Element.Content == null || (Element.Content != null && Element.Content.BackgroundColor == Color.Default))
_contentView?.SetBackgroundColor(backgroundColor); _contentView?.SetBackgroundColor(backgroundColor);
} }
else else
@ -578,7 +577,7 @@ namespace Xamarin.Forms.Platform.Android
void UpdateSwipeItems() void UpdateSwipeItems()
{ {
if (_contentView == null) if (_contentView == null || _actionView != null)
return; return;
var items = GetSwipeItemsByDirection(); var items = GetSwipeItemsByDirection();
@ -730,7 +729,7 @@ namespace Xamarin.Forms.Platform.Android
{ {
if (_actionView != null) if (_actionView != null)
{ {
RemoveView(_actionView); _actionView.RemoveFromParent();
_actionView.Dispose(); _actionView.Dispose();
_actionView = null; _actionView = null;
} }
@ -1019,13 +1018,13 @@ namespace Xamarin.Forms.Platform.Android
if (swipeThreshold > contentWidth) if (swipeThreshold > contentWidth)
swipeThreshold = contentWidth; swipeThreshold = contentWidth;
return swipeThreshold - SwipeThresholdMargin; return swipeThreshold;
} }
if (swipeThreshold > contentHeight) if (swipeThreshold > contentHeight)
swipeThreshold = contentHeight; swipeThreshold = contentHeight;
return swipeThreshold - SwipeThresholdMargin / 2; return swipeThreshold;
} }
Size GetSwipeItemSize(ISwipeItem swipeItem) Size GetSwipeItemSize(ISwipeItem swipeItem)

Просмотреть файл

@ -14,7 +14,6 @@ namespace Xamarin.Forms.Platform.iOS
public class SwipeViewRenderer : ViewRenderer<SwipeView, UIView> public class SwipeViewRenderer : ViewRenderer<SwipeView, UIView>
{ {
const double SwipeThreshold = 250; const double SwipeThreshold = 250;
const int SwipeThresholdMargin = 0;
const double SwipeItemWidth = 100; const double SwipeItemWidth = 100;
const double SwipeAnimationDuration = 0.2; const double SwipeAnimationDuration = 0.2;
const double SwipeMinimumDelta = 10; const double SwipeMinimumDelta = 10;
@ -148,7 +147,7 @@ namespace Xamarin.Forms.Platform.iOS
{ {
BackgroundColor = Element.BackgroundColor.ToUIColor(); BackgroundColor = Element.BackgroundColor.ToUIColor();
if (_contentView != null && Element.Content == null) if (_contentView != null && (Element.Content == null || (Element.Content != null && Element.Content.BackgroundColor == Color.Default)))
_contentView.BackgroundColor = Element.BackgroundColor.ToUIColor(); _contentView.BackgroundColor = Element.BackgroundColor.ToUIColor();
} }
else else
@ -916,13 +915,13 @@ namespace Xamarin.Forms.Platform.iOS
if (swipeThreshold > _contentView.Frame.Width) if (swipeThreshold > _contentView.Frame.Width)
swipeThreshold = _contentView.Frame.Width; swipeThreshold = _contentView.Frame.Width;
return swipeThreshold - SwipeThresholdMargin; return swipeThreshold;
} }
if (swipeThreshold > _contentView.Frame.Height) if (swipeThreshold > _contentView.Frame.Height)
swipeThreshold = _contentView.Frame.Height; swipeThreshold = _contentView.Frame.Height;
return swipeThreshold - SwipeThresholdMargin / 2; return swipeThreshold;
} }
Size GetSwipeItemSize(ISwipeItem swipeItem) Size GetSwipeItemSize(ISwipeItem swipeItem)