Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fix iOS SwipeView background behavior (#14582)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsuarezruiz committed Aug 23, 2022
1 parent 8af69e3 commit be09702
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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"
mc:Ignorable="d"
Title="Test 14444" xmlns:local="using:Xamarin.Forms.Controls"
x:Class="Xamarin.Forms.Controls.Issues.Issue14444"
BackgroundColor="LightGray">
<StackLayout>
<Label
Padding="12"
BackgroundColor="Black"
TextColor="White"
Text="If the SwipeView background is transparent, the test has passed."/>
<StackLayout
Padding="12">
<SwipeView
BackgroundColor="Transparent">
<SwipeView.LeftItems>
<SwipeItemView WidthRequest="50">
<BoxView
HeightRequest="50"
HorizontalOptions="FillAndExpand"
BackgroundColor="Red"/>
</SwipeItemView>
</SwipeView.LeftItems>
<BoxView
HeightRequest="50"
HorizontalOptions="FillAndExpand"
BackgroundColor="Gray"
CornerRadius="16"/>
</SwipeView>
</StackLayout>
</StackLayout>
</local:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Xamarin.Forms.CustomAttributes;
using System.Threading.Tasks;

#if UITEST
using Xamarin.UITest;
using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls.Issues
{
[Issue(IssueTracker.Github, 14444,
"[Bug] SwipeView backgrownd color is set to white on iOS",
PlatformAffected.iOS)]
public partial class Issue14444 : TestContentPage
{
public Issue14444()
{
#if APP
InitializeComponent();
#endif
}

protected override void Init()
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1829,6 +1829,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Issue12590.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13726.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue11795.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14444.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14528.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue14286.xaml.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Issue13236.xaml.cs" />
Expand Down Expand Up @@ -2350,6 +2351,9 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue11795.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue14444.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Issue14286.xaml">
<Generator>MSBuild:UpdateDesignTimeXaml</Generator>
</EmbeddedResource>
Expand Down
17 changes: 6 additions & 11 deletions Xamarin.Forms.Platform.iOS/Renderers/SwipeViewRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,20 +171,15 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE

protected override void SetBackgroundColor(Color color)
{
UIColor backgroundColor = ColorExtensions.BackgroundColor;
Color backgroundColor = Element.BackgroundColor;

if (Element.BackgroundColor != Color.Default)
{
BackgroundColor = Element.BackgroundColor.ToUIColor();
if (Element.BackgroundColor == Color.Default)
return;

if (_contentView != null && (Element.Content == null || (Element.Content != null && Element.Content.BackgroundColor == Color.Default)))
_contentView.BackgroundColor = Element.BackgroundColor.ToUIColor();
}
else
BackgroundColor = backgroundColor;
BackgroundColor = backgroundColor.ToUIColor();

if (_contentView != null && _contentView.BackgroundColor == UIColor.Clear)
_contentView.BackgroundColor = backgroundColor;
if (_contentView != null && (Element.Content == null || (Element.Content != null && Element.Content.BackgroundColor == Color.Default)))
_contentView.BackgroundColor = backgroundColor.ToUIColor();
}

protected override void SetBackground(Brush brush)
Expand Down

0 comments on commit be09702

Please sign in to comment.