Skip to content
Closed
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
Expand Up @@ -112,7 +112,9 @@ void UpdateIconAndStyle(ToolbarItem item)
}
item.IconImageSource.LoadImage(mauiContext, result =>
{
Image = result?.Value;
Image = item.IconImageSource is not FontImageSource
? result?.Value.ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
: result?.Value;
Style = UIBarButtonItemStyle.Plain;
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected override UICollectionViewLayout SelectLayout()
var weakItemsView = new WeakReference<CarouselView>(ItemsView);
var weakController = new WeakReference<CarouselViewController2>((CarouselViewController2)Controller);

return LayoutFactory2.CreateCarouselLayout(weakItemsView,weakController);
return LayoutFactory2.CreateCarouselLayout(weakItemsView, weakController);
}

protected override void ScrollToRequested(object sender, ScrollToRequestEventArgs args)
Expand Down
14 changes: 6 additions & 8 deletions src/Controls/src/Core/Label/Label.iOS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,17 @@ public static void MapMaxLines(ILabelHandler handler, Label label)
handler.PlatformView?.UpdateMaxLines(label);
}

static void MapFormatting(ILabelHandler handler, Label label)
internal static void MapFormatting(ILabelHandler handler, Label label)
{
// we need to re-apply color and font for HTML labels
if (!label.HasFormattedTextSpans && label.TextType == TextType.Html)
if (IsPlainText(label))
{
LabelHandler.MapFormatting(handler, label);
}
else
{
handler.UpdateValue(nameof(ILabel.TextColor));
handler.UpdateValue(nameof(ILabel.Font));
}

if (!IsPlainText(label))
return;

LabelHandler.MapFormatting(handler, label);
}

void RecalculateSpanPositions(Size size)
Expand Down
17 changes: 16 additions & 1 deletion src/Controls/src/Core/Platform/iOS/Extensions/LabelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,22 @@ public static void UpdateText(this UILabel platformLabel, Label label)
switch (label.TextType)
{
case TextType.Html:
platformLabel.UpdateTextHtml(label);
// NOTE: Setting HTML text this will crash with some sort of consistency error.
// https://github.com/dotnet/maui/issues/25946
// Here we have to dispatch back the the main queue to avoid the crash.
// This is observed with CarouselView 1 but not with 2, so hopefully this
// will be just disappear once we switch.
CoreFoundation.DispatchQueue.MainQueue.DispatchAsync(() =>
{
platformLabel.UpdateTextHtml(label);

if (label.Handler is LabelHandler labelHandler)
Label.MapFormatting(labelHandler, label);

// NOTE: Because we are updating text outside the normal layout
// pass, we need to invalidate the measure for the next pass.
label.InvalidateMeasure();
});
break;

default:
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public override string ToString()
new GalleryPageFactory(() => new TimePickerCoreGalleryPage(), "Time Picker Gallery"),
new GalleryPageFactory(() => new WebViewCoreGalleryPage(), "WebView Gallery"),
new GalleryPageFactory(() => new SliderControlPage(), "Slider Feature Matrix"),
new GalleryPageFactory(() => new CheckBoxControlPage(), "CheckBox Feature Matrix"),
new GalleryPageFactory(() => new CollectionViewFeaturePage(), "CollectionView Feature Matrix"),
new GalleryPageFactory(() => new CarouselViewFeaturePage(), "CarouselView Feature Matrix"),

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
<?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"
xmlns:local="clr-namespace:Maui.Controls.Sample"
x:Class="Maui.Controls.Sample.CheckBoxControlPage"
x:DataType="local:CheckBoxFeatureMatrixViewModel"
Title="CheckBoxFeature">

<Grid Padding="20"
RowDefinitions="*, Auto, Auto, Auto"
ColumnDefinitions="0.5*, 0.5*"
RowSpacing="10">
<!-- CheckBox Control -->

<CheckBox IsChecked="{Binding IsChecked}"
Color="{Binding Color}"
Grid.ColumnSpan="2"
HorizontalOptions="Center"
VerticalOptions="Center"
IsEnabled="{Binding IsEnabled}"
IsVisible="{Binding IsVisible}"
CheckedChanged="OnCheckBoxCheckedChanged"
AutomationId="CheckBoxControl"/>


<!-- IsChecked Value -->
<Label Grid.Row="1"
Grid.Column="0"
Text="IsChecked:"
FontSize="16"
VerticalTextAlignment="Start"
HorizontalTextAlignment="Start"
Margin="65,0,10,10"/>
<Label Grid.Row="1"
Grid.Column="1"
Text="{Binding IsChecked}"
FontSize="16"
VerticalTextAlignment="Start"
HorizontalTextAlignment="Start"
AutomationId="IsCheckedLabel"/>

<!-- Event Status -->
<Label Grid.Row="2"
Grid.Column="0"
FontSize="16"
Text="Triggered Events:"
IsVisible="{Binding IsEventStatusLabelVisible}"
VerticalTextAlignment="Start"
HorizontalTextAlignment="Start"
Margin="80,0,10,10"/>
<Label Grid.Row="2"
Grid.Column="1"
Text="{Binding CheckedChangedStatus}"
FontSize="16"
VerticalTextAlignment="Start"
HorizontalTextAlignment="Start"
AutomationId="CheckedChangedStatusLabel"
Margin="0,0,10,10"/>

<StackLayout Spacing="10"
Padding="10"
Grid.Row="3"
Grid.ColumnSpan="2">

<Label Text="CheckBox Properties"
FontAttributes="Bold"
FontSize="14"
Margin="0,0,0,10"/>

<StackLayout Orientation="Vertical">
<StackLayout Orientation="Horizontal">
<Label Text="IsChecked"
FontAttributes="Bold"
Margin="0,15,0,0"/>
<Switch IsToggled="{Binding IsChecked}"
AutomationId="IsCheckedSwitch"/>

</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="IsEnabled"
FontAttributes="Bold"
Margin="0,15,0,0"/>
<Switch IsToggled="{Binding IsEnabled}"
AutomationId="IsEnabledSwitch"/>
</StackLayout>
<StackLayout Orientation="Horizontal">
<Label Text="IsVisible"
FontAttributes="Bold"
Margin="0,15,0,0"/>
<Switch IsToggled="{Binding IsVisible}"
AutomationId="IsVisibleSwitch"/>
</StackLayout>
</StackLayout>

<!-- Color -->

<Grid ColumnDefinitions="*,0.3*,0.3*,0.3*"
ColumnSpacing="15"
HorizontalOptions="Start">
<Label Text="Color"
FontAttributes="Bold"
VerticalOptions="Center"/>
<Button BackgroundColor="Blue"
Grid.Column="1"
Command="{Binding SetColorCommand}"
CommandParameter="Blue"
AutomationId="BlueColorButton"/>
<Button BackgroundColor="Green"
Grid.Column="2"
Command="{Binding SetColorCommand}"
CommandParameter="Green"
AutomationId="GreenColorButton"/>
<Button BackgroundColor="Gray"
Grid.Column="3"
Command="{Binding SetColorCommand}"
AutomationId="DefaultColorButton"/>
</Grid>

<Button Text="Reset Changes"
Clicked="NavigateToOptionsPage_Clicked"
AutomationId="ResetButton"/>
</StackLayout>
</Grid>
</ContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;
using System.Windows.Input;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample;

public partial class CheckBoxControlPage : ContentPage
{
private CheckBoxFeatureMatrixViewModel _viewModel;

public CheckBoxControlPage()
{
InitializeComponent();
_viewModel = new CheckBoxFeatureMatrixViewModel();
_viewModel.SetColorCommand = new Command<string>(OnSetColor);
BindingContext = _viewModel;
}

private void OnSetColor(string colorName)
{
switch (colorName)
{
case "Blue":
_viewModel.Color = Colors.Blue;
break;
case "Green":
_viewModel.Color = Colors.Green;
break;
case "Default":
default:
_viewModel.Color = null;
break;
}
}

private void NavigateToOptionsPage_Clicked(object sender, EventArgs e)
{
_viewModel = new CheckBoxFeatureMatrixViewModel();
_viewModel.SetColorCommand = new Command<string>(OnSetColor);
BindingContext = _viewModel;
}

private void OnCheckBoxCheckedChanged(object sender, CheckedChangedEventArgs e)
{
_viewModel.CheckedChangedCommand.Execute(null);
}

}


// Extension of the CheckBoxFeatureMatrixViewModel to add commands for the options page
public partial class CheckBoxFeatureMatrixViewModel
{
public ICommand SetColorCommand { get; set; }
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
using Microsoft.Maui.Controls;

namespace Maui.Controls.Sample;

public partial class CheckBoxFeatureMatrixViewModel : INotifyPropertyChanged
{
private bool _isChecked = true;
private Color _color = null;
private bool _isEnabled = true;
private bool _isVisible = true;
private string _checkedChangedStatus = string.Empty;
private bool _isEventStatusLabelVisible = false;

public event PropertyChangedEventHandler PropertyChanged;

public CheckBoxFeatureMatrixViewModel()
{
CheckedChangedCommand = new Command(OnCheckedChanged);
}

public bool IsChecked
{
get => _isChecked;
set
{
if (_isChecked != value)
{
_isChecked = value;
OnPropertyChanged();
}
}
}

public Color Color
{
get => _color;
set
{
if (_color != value)
{
_color = value;
OnPropertyChanged();
}
}
}

public bool IsEnabled
{
get => _isEnabled;
set
{
if (_isEnabled != value)
{
_isEnabled = value;
OnPropertyChanged();
}
}
}

public bool IsVisible
{
get => _isVisible;
set
{
if (_isVisible != value)
{
_isVisible = value;
OnPropertyChanged();
}
}
}

public string CheckedChangedStatus
{
get => _checkedChangedStatus;
set
{
if (_checkedChangedStatus != value)
{
if (!string.IsNullOrEmpty(value))
{
IsEventStatusLabelVisible = true;
}
_checkedChangedStatus = value;
OnPropertyChanged();
}
}
}

public bool IsEventStatusLabelVisible
{
get => _isEventStatusLabelVisible;
set
{
if (_isEventStatusLabelVisible != value)
{
_isEventStatusLabelVisible = value;
OnPropertyChanged();
}
}
}

public ICommand CheckedChangedCommand { get; }

private void OnCheckedChanged()
{
CheckedChangedStatus = "CheckedChanged Triggered";
}

protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
Loading
Loading