Skip to content

Commit b4d4ed3

Browse files
authored
Merge pull request #237 from enisn/maui-preview13
MAUI - RadioButton
2 parents 9b390c4 + 9675942 commit b4d4ed3

File tree

11 files changed

+88
-18
lines changed

11 files changed

+88
-18
lines changed

sandbox/SandboxMAUI/MainPage.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
<ScrollView>
88
<StackLayout
9-
Padding="{OnPlatform iOS='30,60,30,30', Default='30'}">
9+
Padding="{OnPlatform iOS='30,60,30,30', Default='30'}" Spacing="10">
1010

1111

1212
<Button Text="CheckBox" Clicked="GoToCheckBoxPage" />
1313

14+
<Button Text="Radio Button" Clicked="GoToRadioButtonPage" />
15+
1416
</StackLayout>
1517
</ScrollView>
1618
</ContentPage>

sandbox/SandboxMAUI/MainPage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,10 @@ async void GoToCheckBoxPage(System.Object sender, System.EventArgs e)
1616
{
1717
await Navigation.PushAsync(new CheckBoxPage());
1818
}
19+
20+
async void GoToRadioButtonPage(System.Object sender, System.EventArgs e)
21+
{
22+
await Navigation.PushAsync(new RadioButtonPage());
23+
}
1924
}
2025
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
4+
xmlns:input="clr-namespace:InputKit.Shared.Controls;assembly=InputKit"
5+
x:Class="SandboxMAUI.Pages.RadioButtonPage"
6+
Title="RadioButtonPage">
7+
<ScrollView>
8+
<StackLayout Padding="25" Spacing="15">
9+
10+
<Button Text="Randomize Colors" Clicked="RandomizeColors" />
11+
<BoxView Color="Black" HeightRequest="1" HorizontalOptions="Fill" Margin="5,10" />
12+
13+
<input:RadioButtonGroupView x:Name="groupView">
14+
<input:RadioButton Text="Option 1" />
15+
<input:RadioButton Text="Option 2" />
16+
<input:RadioButton Text="Option 3 Label Position Before" LabelPosition="Before"/>
17+
<input:RadioButton Text="Option 4 with Custom Image" CheckedImage="circle_check"/>
18+
<input:RadioButton Text="Dolor ullamcorper sit justo magna luptatum at sit dolor sed accusam amet quod nostrud lobortis amet dolore et zzril et"/>
19+
<input:RadioButton Text="Option 5 Disabled" IsDisabled="True"/>
20+
</input:RadioButtonGroupView>
21+
22+
</StackLayout>
23+
</ScrollView>
24+
</ContentPage>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using Microsoft.Maui.Controls;
3+
using Microsoft.Maui.Graphics;
4+
using RadioButton = InputKit.Shared.Controls.RadioButton;
5+
6+
namespace SandboxMAUI.Pages;
7+
8+
public partial class RadioButtonPage : ContentPage
9+
{
10+
public RadioButtonPage()
11+
{
12+
InitializeComponent();
13+
}
14+
15+
private static Random rnd = new Random();
16+
17+
private void RandomizeColors(object sender, EventArgs e)
18+
{
19+
var colors = typeof(Colors).GetFields();
20+
var color = (Color)colors[rnd.Next(colors.Length)].GetValue(null);
21+
foreach (var view in groupView.Children)
22+
{
23+
if (view is RadioButton rb)
24+
{
25+
rb.Color = color;
26+
}
27+
}
28+
29+
if (sender is Button button)
30+
{
31+
button.BackgroundColor = color;
32+
}
33+
}
34+
}
493 Bytes
Loading

src/InputKit/InputKit.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFrameworks>net6.0;net6.0-android;net6.0-ios;</TargetFrameworks>
55
<UseMaui>true</UseMaui>
66
<SingleProject>true</SingleProject>
7-
<MauiVersion>6.0.200-preview.12.2441</MauiVersion>
7+
<MauiVersion>6.0.200-preview.13.2865</MauiVersion>
88
<PackageId>Xamarin.Forms.InputKit</PackageId>
99
<Version>4.0.0-pre.4</Version>
1010

src/InputKit/Platforms/iOS/Handlers/StatefulStackLayoutHandler.iOS.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ private void Tapped(UIGestureRecognizer recognizer)
3232

3333
break;
3434
case UIGestureRecognizerState.Ended:
35-
// TODO: Fix working of native gesture recognizers of MAUI
35+
VisualStateManager.GoToState(element, "Normal");
36+
37+
//// TODO: Fix working of native gesture recognizers of MAUI
3638
foreach (var item in element.GestureRecognizers)
3739
{
3840
Debug.WriteLine(item.GetType().Name);
@@ -42,8 +44,6 @@ private void Tapped(UIGestureRecognizer recognizer)
4244
}
4345
}
4446

45-
VisualStateManager.GoToState(element, "Normal");
46-
4747
break;
4848
}
4949
}

src/InputKit/Shared/Controls/AdvancedEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ public virtual void FocusNext()
494494
if (Parent is Layout parent)
495495
{
496496
int index = parent.Children.IndexOf(this);
497-
for (int i = index + 1; i < (index + 4).Clamp(0, parent.Children.Count); i++)
497+
for (int i = index + 1; i < Math.Clamp(index + 4, 0, parent.Children.Count); i++)
498498
{
499499
if (parent.Children[i] is AdvancedEntry)
500500
{

src/InputKit/Shared/Controls/RadioButton.cs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public partial class RadioButton : StatefulStackLayout
4141
internal Grid IconLayout;
4242
internal IconView iconCircle = new IconView { Source = ImageSource.FromResource(RESOURCE_CIRCLE), FillColor = GlobalSetting.BorderColor, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center, HeightRequest = GlobalSetting.Size, WidthRequest = GlobalSetting.Size };
4343
internal IconView iconChecked = new IconView { Source = ImageSource.FromResource(RESOURCE_DOT), FillColor = GlobalSetting.Color, IsVisible = false, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Center, HeightRequest = GlobalSetting.Size, WidthRequest = GlobalSetting.Size };
44-
internal Label lblText = new Label { IsVisible = false, VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, TextColor = GlobalSetting.TextColor, FontSize = GlobalSetting.FontSize, FontFamily = GlobalSetting.FontFamily };
44+
internal Label lblText = new Label { VerticalTextAlignment = TextAlignment.Center, VerticalOptions = LayoutOptions.CenterAndExpand, HorizontalOptions = LayoutOptions.Fill, TextColor = GlobalSetting.TextColor, FontSize = GlobalSetting.FontSize, FontFamily = GlobalSetting.FontFamily, MaxLines=3, LineBreakMode = LineBreakMode.WordWrap };
4545
private bool _isDisabled;
4646
#endregion
4747

@@ -52,23 +52,26 @@ public partial class RadioButton : StatefulStackLayout
5252
public RadioButton()
5353
{
5454
InitVisualStates();
55-
ApplyIsCheckedAction = ApplyIsChecked;
56-
ApplyIsPressedAction = ApplyIsPressed;
55+
56+
Orientation = StackOrientation.Horizontal;
5757
if (Device.RuntimePlatform != Device.iOS)
5858
lblText.FontSize = lblText.FontSize *= 1.5;
5959

60-
Orientation = StackOrientation.Horizontal;
60+
61+
ApplyIsCheckedAction = ApplyIsChecked;
62+
ApplyIsPressedAction = ApplyIsPressed;
6163

6264
IconLayout = new Grid
6365
{
64-
VerticalOptions = LayoutOptions.CenterAndExpand,
66+
VerticalOptions = LayoutOptions.Center,
6567
Children =
6668
{
6769
iconCircle,
6870
iconChecked
6971
},
7072
MinimumWidthRequest = GlobalSetting.Size * 1.66,
7173
};
74+
7275
ApplyLabelPosition(LabelPosition);
7376

7477
GestureRecognizers.Add(new TapGestureRecognizer { Command = new Command(Tapped) });
@@ -217,13 +220,13 @@ private void ApplyLabelPosition(LabelPosition position)
217220
Children.Clear();
218221
if (position == LabelPosition.After)
219222
{
220-
lblText.HorizontalOptions = LayoutOptions.Start;
223+
IconLayout.HorizontalOptions = LayoutOptions.Center;
221224
Children.Add(IconLayout);
222225
Children.Add(lblText);
223226
}
224227
else
225228
{
226-
lblText.HorizontalOptions = LayoutOptions.StartAndExpand;
229+
IconLayout.HorizontalOptions = LayoutOptions.Center;
227230
Children.Add(lblText);
228231
Children.Add(IconLayout);
229232
}
@@ -273,10 +276,12 @@ public virtual void ApplyIsChecked(bool isChecked)
273276
Checked?.Invoke(this, null);
274277
}
275278
}
279+
276280
public virtual async void ApplyIsPressed(bool isPressed)
277281
{
278-
await iconCircle.ScaleTo(isPressed ? .5 : 1, 100);
282+
await IconLayout.ScaleTo(isPressed ? .8 : 1, 100);
279283
}
284+
280285
void InitVisualStates()
281286
{
282287
VisualStateManager.SetVisualStateGroups(this, new VisualStateGroupList

src/InputKit/Shared/Controls/RadioButtonGroupView.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public partial class RadioButtonGroupView : StatefulStackLayout, IValidatable
2121
/// </summary>
2222
public RadioButtonGroupView()
2323
{
24+
Spacing = 10;
2425
ChildAdded += OnChildAdded;
2526
ChildrenReordered += RadioButtonGroupView_ChildrenReordered;
2627
}

0 commit comments

Comments
 (0)