Skip to content

Commit

Permalink
Merge pull request #230 from adospace/fix-229
Browse files Browse the repository at this point in the history
fixes #229
  • Loading branch information
adospace committed Apr 10, 2024
2 parents 57f8a3a + 772e7a1 commit 9e285d1
Show file tree
Hide file tree
Showing 14 changed files with 124 additions and 89 deletions.
4 changes: 4 additions & 0 deletions samples/MauiReactor.TestApp/HomePage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public override VisualNode Render()
{
new PickerPage()
},
new FlyoutItem("Visual State Test Page")
{
new VisualStateTestPage()
},
}
.ItemTemplate(RenderItemTemplate);
}
Expand Down
4 changes: 2 additions & 2 deletions samples/MauiReactor.TestApp/Pages/CarouselTestPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public override VisualNode Render()
.HCenter()
.VCenter()
.IndicatorTemplate(() => new Label("Test"))
.VisualState("CommonStates", "Normal", MauiControls.Label.TextColorProperty, Colors.Black)
.VisualState("CommonStates", "Selected", MauiControls.Label.TextColorProperty, Colors.White)
.IndicatorVisualState("CommonStates", "Normal", MauiControls.Label.TextColorProperty, Colors.Black)
.IndicatorVisualState("CommonStates", "Selected", MauiControls.Label.TextColorProperty, Colors.White)
.GridRow(1),
}
}
Expand Down
7 changes: 6 additions & 1 deletion samples/MauiReactor.TestApp/Pages/CollectionViewPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Microsoft.Maui.Controls.VisualStateManager;

namespace MauiReactor.TestApp.Pages
{
Expand All @@ -23,15 +24,19 @@ public override VisualNode Render()
{
new CollectionView()
.AutomationId("list") //AutomationId used for test
.SelectionMode(MauiControls.SelectionMode.Single)
.ItemsSource(ItemsSource, RenderItem)
.ItemVisualState(nameof(CommonStates), CommonStates.Normal, MauiControls.VisualElement.BackgroundColorProperty, Colors.Transparent)
.ItemVisualState(nameof(CommonStates), CommonStates.Selected, MauiControls.VisualElement.BackgroundColorProperty, Colors.LightCoral)
};
}

private VisualNode RenderItem(Tuple<string, string> item)
=> SwipeView(
VStack(spacing: 5,
Label(item.Item1).AutomationId(item.Item1), //AutomationId used for test
Label(item.Item2)
Label(item.Item2)

).AutomationId($"Container_{item.Item1}")
)
.RightItems([
Expand Down
38 changes: 38 additions & 0 deletions samples/MauiReactor.TestApp/Pages/VisualStateTestPage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using MauiReactor.TestApp.Services;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static Microsoft.Maui.Controls.VisualStateManager;
namespace MauiReactor.TestApp.Pages;

class VisualStateTestPage : Component
{
public override VisualNode Render()
=> ContentPage("Visual States Test Page",
VStack(
Entry()
.Placeholder("Entry 1")
.VisualState(nameof(CommonStates), CommonStates.Normal, MauiControls.Entry.FontSizeProperty, 35)
.VisualState(nameof(CommonStates), CommonStates.Focused, MauiControls.VisualElement.BackgroundColorProperty, Colors.Red)
.VisualState(nameof(CommonStates), "Unfocused", MauiControls.VisualElement.BackgroundColorProperty, Colors.Yellow),
Entry()
.Placeholder("Entry 2")
.VisualState(nameof(CommonStates), CommonStates.Normal, MauiControls.Entry.FontSizeProperty, 35)
.VisualState(nameof(CommonStates), CommonStates.Focused, MauiControls.VisualElement.BackgroundColorProperty, Colors.Red)
.VisualState(nameof(CommonStates), "Unfocused", MauiControls.VisualElement.BackgroundColorProperty, Colors.Yellow),

Button("Button")
.VisualState(nameof(CommonStates), CommonStates.Normal)
.VisualState(nameof(CommonStates), "Pressed", MauiControls.VisualElement.BackgroundColorProperty, Colors.Aqua)



)
.Spacing(10)
.Center()
);

}
4 changes: 2 additions & 2 deletions src/MauiReactor.Scaffold/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static string ToResevedWordTypeName(this string typename)
"Boolean" => "bool",
"Decimal" => "decimal",
"String" => "string",
"Object" => "object",
"Object" => "object?",
_ => typename,
};
}
Expand All @@ -54,7 +54,7 @@ public static string ToResevedWordFullTypeName(this string fulltypename)
"System.Boolean" => "bool",
"System.Decimal" => "decimal",
"System.String" => "string",
"System.Object" => "object",
"System.Object" => "object?",
_ => fulltypename.Replace('+', '.'),
};
}
Expand Down
4 changes: 2 additions & 2 deletions src/MauiReactor.ScaffoldGenerator/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static string ToReservedWordTypeName(this string typeName)
"Boolean" => "bool",
"Decimal" => "decimal",
"String" => "string",
"Object" => "object",
"Object" => "object?",
_ => typeName,
};
}
Expand All @@ -54,7 +54,7 @@ public static string ToReservedWordFullTypeName(this string fullTypeName)
"System.Boolean" => "bool",
"System.Decimal" => "decimal",
"System.String" => "string",
"System.Object" => "object",
"System.Object" => "object?",
_ => fullTypeName.Replace('+', '.'),
};
}
Expand Down
6 changes: 3 additions & 3 deletions src/MauiReactor/CarouselView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,17 +283,17 @@ public static T IsScrollAnimated<T>(this T carouselView, Func<bool> isScrollAnim
return carouselView;
}

public static T CurrentItem<T>(this T carouselView, object currentItem)
public static T CurrentItem<T>(this T carouselView, object? currentItem)
where T : ICarouselView
{
carouselView.CurrentItem = currentItem;
return carouselView;
}

public static T CurrentItem<T>(this T carouselView, Func<object> currentItemFunc)
public static T CurrentItem<T>(this T carouselView, Func<object?> currentItemFunc)
where T : ICarouselView
{
carouselView.CurrentItem = new PropertyValue<object>(currentItemFunc);
carouselView.CurrentItem = new PropertyValue<object?>(currentItemFunc);
return carouselView;
}

Expand Down
26 changes: 14 additions & 12 deletions src/MauiReactor/IndicatorView.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,26 @@ public static partial class IndicatorViewExtensions
return indicatorView;
}

public static T IndicatorVisualState<T>(this T indicatorView, string groupName, string stateName, BindableProperty property, object? value, string? targetName = null) where T : IIndicatorView
public static T IndicatorVisualState<T>(this T indicatorView, string groupName, string stateName, BindableProperty? property = null, object? value = null, string? targetName = null) where T : IIndicatorView
{
indicatorView.IndicatorVisualStateGroups ??= [];

indicatorView.IndicatorVisualStateGroups.TryGetValue(groupName, out var group);
indicatorView.IndicatorVisualStateGroups.Set(groupName, stateName, property, value, targetName);

if (group == null)
{
indicatorView.IndicatorVisualStateGroups.Add(groupName, group = []);
}
//indicatorView.IndicatorVisualStateGroups.TryGetValue(groupName, out var group);

group.TryGetValue(stateName, out var state);
if (state == null)
{
group.Add(stateName, state = []);
}
//if (group == null)
//{
// indicatorView.IndicatorVisualStateGroups.Add(groupName, group = []);
//}

//group.TryGetValue(stateName, out var state);
//if (state == null)
//{
// group.Add(stateName, state = []);
//}

state.Add(new VisualStatePropertySetter(property, value, targetName));
//state.Add(new VisualStatePropertySetter(property, value, targetName));

return indicatorView;
}
Expand Down
17 changes: 2 additions & 15 deletions src/MauiReactor/ItemsView.partial.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,24 +249,11 @@ public static partial class ItemsViewExtensions
return itemsView;
}

public static T ItemVisualState<T>(this T itemsView, string groupName, string stateName, BindableProperty property, object? value, string? targetName = null) where T : IItemsView
public static T ItemVisualState<T>(this T itemsView, string groupName, string stateName, BindableProperty? property = null, object? value = null, string? targetName = null) where T : IItemsView
{
itemsView.ItemVisualStateGroups ??= [];

itemsView.ItemVisualStateGroups.TryGetValue(groupName, out var group);

if (group == null)
{
itemsView.ItemVisualStateGroups.Add(groupName, group = []);
}

group.TryGetValue(stateName, out var state);
if (state == null)
{
group.Add(stateName, state = []);
}

state.Add(new VisualStatePropertySetter(property, value, targetName));
itemsView.ItemVisualStateGroups.Set(groupName, stateName, property, value, targetName);

return itemsView;
}
Expand Down
6 changes: 3 additions & 3 deletions src/MauiReactor/ListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,17 +328,17 @@ public static T IsRefreshing<T>(this T listView, Func<bool> isRefreshingFunc)
return listView;
}

public static T SelectedItem<T>(this T listView, object selectedItem)
public static T SelectedItem<T>(this T listView, object? selectedItem)
where T : IListView
{
listView.SelectedItem = selectedItem;
return listView;
}

public static T SelectedItem<T>(this T listView, Func<object> selectedItemFunc)
public static T SelectedItem<T>(this T listView, Func<object?> selectedItemFunc)
where T : IListView
{
listView.SelectedItem = new PropertyValue<object>(selectedItemFunc);
listView.SelectedItem = new PropertyValue<object?>(selectedItemFunc);
return listView;
}

Expand Down
6 changes: 3 additions & 3 deletions src/MauiReactor/MultiPage`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,17 @@ protected override void OnDetachNativeEvents()

public static partial class MultiPageExtensions
{
public static T SelectedItem<T>(this T multiPage, object selectedItem)
public static T SelectedItem<T>(this T multiPage, object? selectedItem)
where T : IGenericMultiPage
{
multiPage.SelectedItem = selectedItem;
return multiPage;
}

public static T SelectedItem<T>(this T multiPage, Func<object> selectedItemFunc)
public static T SelectedItem<T>(this T multiPage, Func<object?> selectedItemFunc)
where T : IGenericMultiPage
{
multiPage.SelectedItem = new PropertyValue<object>(selectedItemFunc);
multiPage.SelectedItem = new PropertyValue<object?>(selectedItemFunc);
return multiPage;
}

Expand Down
6 changes: 3 additions & 3 deletions src/MauiReactor/RadioButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,17 @@ public static partial class RadioButtonExtensions
static void SetCharacterSpacing(object radioButton, RxAnimation animation) => ((IRadioButton)radioButton).CharacterSpacing = ((RxDoubleAnimation)animation).CurrentValue();
static void SetFontSize(object radioButton, RxAnimation animation) => ((IRadioButton)radioButton).FontSize = ((RxDoubleAnimation)animation).CurrentValue();
static void SetBorderWidth(object radioButton, RxAnimation animation) => ((IRadioButton)radioButton).BorderWidth = ((RxDoubleAnimation)animation).CurrentValue();
public static T Value<T>(this T radioButton, object value)
public static T Value<T>(this T radioButton, object? value)
where T : IRadioButton
{
radioButton.Value = value;
return radioButton;
}

public static T Value<T>(this T radioButton, Func<object> valueFunc)
public static T Value<T>(this T radioButton, Func<object?> valueFunc)
where T : IRadioButton
{
radioButton.Value = new PropertyValue<object>(valueFunc);
radioButton.Value = new PropertyValue<object?>(valueFunc);
return radioButton;
}

Expand Down
6 changes: 3 additions & 3 deletions src/MauiReactor/SelectableItemsView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,17 +139,17 @@ public static T SelectionMode<T>(this T selectableItemsView, Func<Microsoft.Maui
return selectableItemsView;
}

public static T SelectedItem<T>(this T selectableItemsView, object selectedItem)
public static T SelectedItem<T>(this T selectableItemsView, object? selectedItem)
where T : ISelectableItemsView
{
selectableItemsView.SelectedItem = selectedItem;
return selectableItemsView;
}

public static T SelectedItem<T>(this T selectableItemsView, Func<object> selectedItemFunc)
public static T SelectedItem<T>(this T selectableItemsView, Func<object?> selectedItemFunc)
where T : ISelectableItemsView
{
selectableItemsView.SelectedItem = new PropertyValue<object>(selectedItemFunc);
selectableItemsView.SelectedItem = new PropertyValue<object?>(selectedItemFunc);
return selectableItemsView;
}

Expand Down
Loading

0 comments on commit 9e285d1

Please sign in to comment.