Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[iOS] Frames' content update #20501

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Maui.Controls.Sample.Issues.Issue19127"
xmlns:ns="clr-namespace:Maui.Controls.Sample.Issues">
<VerticalStackLayout
VerticalOptions="Center">
<Button Text="{Binding IsCameraEnabled, StringFormat='Toggle Camera View ({0})'}"
Command="{Binding EnableCamera}"
AutomationId="button" />

<Frame x:Name="frame"
HeightRequest="191">
<Frame.Triggers>
<DataTrigger TargetType="Frame" Binding="{Binding IsCameraEnabled}" Value="False">
<Setter Property="Content">
<Grid BackgroundColor="Gray">
<Label AutomationId="label1" Text="Camera is Disabled" TextColor="White" />
</Grid>
</Setter>
</DataTrigger>
<DataTrigger TargetType="Frame" Binding="{Binding IsCameraEnabled}" Value="True">
<Setter Property="Content">
<Grid BackgroundColor="HotPink">
<Label AutomationId="label2" Text="Camera is Enabled" TextColor="White" />
</Grid>
</Setter>
</DataTrigger>
</Frame.Triggers>
</Frame>
</VerticalStackLayout>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.ComponentModel;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;

namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 19127, "Triggers are not working on Frame control", PlatformAffected.iOS)]
public partial class Issue19127 : ContentPage
{
public Issue19127()
{
InitializeComponent();
BindingContext = new Issue19127Settings();
}
}

public class Issue19127Settings : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

public Command EnableCamera { get; set; }

private bool _isCameraEnabled;
public bool IsCameraEnabled
{
get { return _isCameraEnabled; }
set
{
_isCameraEnabled = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(IsCameraEnabled)));
}
}

public Issue19127Settings()
{
IsCameraEnabled = false;
EnableCamera = new Command(() => ToggleEnableCamera());
}

private void ToggleEnableCamera()
{
IsCameraEnabled = !_isCameraEnabled;
}
}
}
33 changes: 23 additions & 10 deletions src/Controls/src/Core/Compatibility/Handlers/iOS/FrameRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,17 @@ namespace Microsoft.Maui.Controls.Handlers.Compatibility
public class FrameRenderer : VisualElementRenderer<Frame>
{
public static IPropertyMapper<Frame, FrameRenderer> Mapper
= new PropertyMapper<Frame, FrameRenderer>(VisualElementRendererMapper);
= new PropertyMapper<Frame, FrameRenderer>(VisualElementRendererMapper)
{
[VisualElement.BackgroundColorProperty.PropertyName] = (h, _) => h.SetupLayer(),
[VisualElement.BackgroundProperty.PropertyName] = (h, _) => h.SetupLayer(),
[Microsoft.Maui.Controls.Frame.BorderColorProperty.PropertyName] = (h, _) => h.SetupLayer(),
[Microsoft.Maui.Controls.Frame.CornerRadiusProperty.PropertyName] = (h, _) => h.SetupLayer(),
[Microsoft.Maui.Controls.Frame.IsClippedToBoundsProperty.PropertyName] = (h, _) => h.SetupLayer(),
[VisualElement.IsVisibleProperty.PropertyName] = (h, _) => h.SetupLayer(),
[Controls.Frame.HasShadowProperty.PropertyName] = (h, _) => h.UpdateShadow(),
[Microsoft.Maui.Controls.Frame.ContentProperty.PropertyName] = (h, _) => h.UpdateContent(),
};

public static CommandMapper<Frame, FrameRenderer> CommandMapper
= new CommandMapper<Frame, FrameRenderer>(VisualElementRendererCommandMapper);
Expand Down Expand Up @@ -59,16 +69,19 @@ protected override void OnElementChanged(ElementChangedEventArgs<Frame> e)
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
}

if (e.PropertyName == VisualElement.BackgroundColorProperty.PropertyName ||
e.PropertyName == VisualElement.BackgroundProperty.PropertyName ||
e.PropertyName == Microsoft.Maui.Controls.Frame.BorderColorProperty.PropertyName ||
e.PropertyName == Microsoft.Maui.Controls.Frame.CornerRadiusProperty.PropertyName ||
e.PropertyName == Microsoft.Maui.Controls.Frame.IsClippedToBoundsProperty.PropertyName ||
e.PropertyName == VisualElement.IsVisibleProperty.PropertyName)
SetupLayer();
else if (e.PropertyName == Controls.Frame.HasShadowProperty.PropertyName)
UpdateShadow();
void UpdateContent()
{
_actualView.ClearSubviews();

var content = Element?.Content;

if (content == null || MauiContext == null)
return;

var platformView = content.ToPlatform(MauiContext);
_actualView.AddSubview(platformView);
}

public override void TraitCollectionDidChange(UITraitCollection previousTraitCollection)
Expand Down
30 changes: 30 additions & 0 deletions src/Controls/tests/UITests/Tests/Issues/Issue19127.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.AppiumTests.Issues
{
public class Issue19127 : _IssuesUITest
{
public override string Issue => "Triggers are not working on Frame control";

public Issue19127(TestDevice device) : base(device)
{
}

[Test]
public void ContentOfFrameShouldChange()
{
_ = App.WaitForElement("button");

var textBeforeClick = App.FindElement("label1").GetText();

App.Click("button");
kubaflo marked this conversation as resolved.
Show resolved Hide resolved

var textAfterClick = App.FindElement("label2").GetText();

Assert.AreEqual(textBeforeClick, "Camera is Disabled");
Assert.AreEqual(textAfterClick, "Camera is Enabled");
}
}
}
Loading