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

Commit eddb0e6

Browse files
committed
Merge branch 'main' into develop
2 parents e6aaba3 + 3abf5fa commit eddb0e6

33 files changed

+375
-69
lines changed

samples/XCT.Sample/Pages/Views/CameraViewPage.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ void CameraView_MediaCaptured(object sender, MediaCapturedEventArgs e)
7575
case CameraCaptureMode.Default:
7676
case CameraCaptureMode.Photo:
7777
previewPicture.IsVisible = true;
78+
previewPicture.Rotation = e.Rotation;
7879
previewPicture.Source = e.Image;
7980
doCameraThings.Text = "Snap Picture";
8081
break;
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<pages:BasePage
3+
xmlns:pages="clr-namespace:Xamarin.CommunityToolkit.Sample.Pages"
4+
xmlns="http://xamarin.com/schemas/2014/forms"
5+
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
6+
x:Class="Xamarin.CommunityToolkit.Sample.Pages.Views.TabView.TabViewItemVisualStatePage">
7+
<pages:BasePage.Resources>
8+
<ResourceDictionary>
9+
10+
</ResourceDictionary>
11+
</pages:BasePage.Resources>
12+
<ContentPage.Content>
13+
<xct:TabView
14+
TabStripPlacement="Bottom"
15+
TabStripBackgroundColor="Blue"
16+
TabStripHeight="60"
17+
TabIndicatorColor="Yellow"
18+
TabContentBackgroundColor="Yellow">
19+
<xct:TabViewItem
20+
Icon="triangle.png"
21+
Text="Tab 1"
22+
TextColor="White"
23+
TextColorSelected="Yellow"
24+
FontSize="12">
25+
<VisualStateManager.VisualStateGroups>
26+
<VisualStateGroup x:Name="CommonStates">
27+
<VisualState x:Name="Selected">
28+
<VisualState.Setters>
29+
<Setter Property="BackgroundColor" Value="Red" />
30+
</VisualState.Setters>
31+
</VisualState>
32+
<VisualState x:Name="Unselected">
33+
<VisualState.Setters>
34+
<Setter Property="BackgroundColor" Value="IndianRed" />
35+
</VisualState.Setters>
36+
</VisualState>
37+
</VisualStateGroup>
38+
</VisualStateManager.VisualStateGroups>
39+
<Grid
40+
BackgroundColor="Gray">
41+
<Label
42+
HorizontalOptions="Center"
43+
VerticalOptions="Center"
44+
Text="TabContent1" />
45+
</Grid>
46+
</xct:TabViewItem>
47+
<xct:TabViewItem
48+
Icon="circle.png"
49+
Text="Tab 2"
50+
TextColor="White"
51+
TextColorSelected="Yellow"
52+
FontSize="12">
53+
<VisualStateManager.VisualStateGroups>
54+
<VisualStateGroup x:Name="CommonStates">
55+
<VisualState x:Name="Selected">
56+
<VisualState.Setters>
57+
<Setter Property="BackgroundColor" Value="Green" />
58+
</VisualState.Setters>
59+
</VisualState>
60+
<VisualState x:Name="Unselected">
61+
<VisualState.Setters>
62+
<Setter Property="BackgroundColor" Value="LightGreen" />
63+
</VisualState.Setters>
64+
</VisualState>
65+
</VisualStateGroup>
66+
</VisualStateManager.VisualStateGroups>
67+
<Grid>
68+
<Label
69+
HorizontalOptions="Center"
70+
VerticalOptions="Center"
71+
Text="TabContent2" />
72+
</Grid>
73+
</xct:TabViewItem>
74+
<xct:TabViewItem
75+
Icon="rectangle.png"
76+
Text="Tab 3"
77+
TextColor="White"
78+
TextColorSelected="Yellow"
79+
FontSize="12">
80+
<VisualStateManager.VisualStateGroups>
81+
<VisualStateGroup x:Name="CommonStates">
82+
<VisualState x:Name="Selected">
83+
<VisualState.Setters>
84+
<Setter Property="BackgroundColor" Value="Pink" />
85+
</VisualState.Setters>
86+
</VisualState>
87+
<VisualState x:Name="Unselected">
88+
<VisualState.Setters>
89+
<Setter Property="BackgroundColor" Value="LightPink" />
90+
</VisualState.Setters>
91+
</VisualState>
92+
</VisualStateGroup>
93+
</VisualStateManager.VisualStateGroups>
94+
<Grid
95+
BackgroundColor="LightSteelBlue">
96+
<Label
97+
HorizontalOptions="Center"
98+
VerticalOptions="Center"
99+
Text="TabContent3" />
100+
</Grid>
101+
</xct:TabViewItem>
102+
</xct:TabView>
103+
</ContentPage.Content>
104+
</pages:BasePage>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace Xamarin.CommunityToolkit.Sample.Pages.Views.TabView
2+
{
3+
public partial class TabViewItemVisualStatePage : BasePage
4+
{
5+
public TabViewItemVisualStatePage() => InitializeComponent();
6+
}
7+
}

samples/XCT.Sample/ViewModels/Views/TabViewViewModel.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ protected override IEnumerable<SectionModel> CreateItems() => new[]
3838
new SectionModel(typeof(TabWidthPage), "TabWidth",
3939
"Customize the tabs width"),
4040

41+
new SectionModel(typeof(TabViewItemVisualStatePage), "TabViewItem VisualState",
42+
"Using TabViewItem VisualStates"),
43+
4144
new SectionModel(typeof(NoContentPage), "Tab without Content",
4245
"Only the TabStrip is visible"),
4346

src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Behaviors/UserStoppedTypingBehavior_Tests.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class UserStoppedTypingBehavior_Tests
1212
const int defaultLengthThreshold = 0;
1313

1414
[Fact]
15-
public async Task ExecuteCommandWhenTimeThresholdHasExpired()
15+
public async Task ShouldExecuteCommandWhenTimeThresholdHasExpired()
1616
{
1717
// arrange
1818
var commandHasBeenExecuted = false;
@@ -26,6 +26,22 @@ public async Task ExecuteCommandWhenTimeThresholdHasExpired()
2626
Assert.True(commandHasBeenExecuted);
2727
}
2828

29+
[Fact]
30+
public async Task ShouldExecuteCommandWithSpecificParameterWhenSpecified()
31+
{
32+
// arrange
33+
var commandHasBeenExecuted = false;
34+
var entry = CreateEntryWithBehavior(command: new Command<bool>((s) => commandHasBeenExecuted = true),
35+
commandParameter: true);
36+
37+
// act
38+
entry.Text = "1";
39+
await Task.Delay(defaultTimeThreshold + 100);
40+
41+
// assert
42+
Assert.True(commandHasBeenExecuted);
43+
}
44+
2945
[Fact]
3046
public async Task ShouldNotExecuteCommandBeforeTimeThresholdHasExpired()
3147
{
@@ -144,7 +160,8 @@ public async Task ShouldExecuteCommandImmediatelyWhenMinimumLengthThreholdHasNot
144160
public Entry CreateEntryWithBehavior(int timeThreshold = defaultTimeThreshold,
145161
int lengthThreshold = defaultLengthThreshold,
146162
bool shouldDismissKeyboardAutomatically = false,
147-
ICommand command = null)
163+
ICommand command = null,
164+
object commandParameter = null)
148165
{
149166
var entry = new Entry
150167
{
@@ -155,7 +172,8 @@ public Entry CreateEntryWithBehavior(int timeThreshold = defaultTimeThreshold,
155172
StoppedTypingTimeThreshold = timeThreshold,
156173
MinimumLengthThreshold = lengthThreshold,
157174
ShouldDismissKeyboardAutomatically = shouldDismissKeyboardAutomatically,
158-
Command = command
175+
Command = command,
176+
CommandParameter = commandParameter
159177
}
160178
}
161179
};

src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemSelectedEventArgsConverter_Tests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ public class ItemSelectedEventArgsConverter_Tests
1515
{
1616
// We know it's deprecated, still good to test it
1717
#pragma warning disable CS0618 // Type or member is obsolete
18-
new object[] { new SelectedItemChangedEventArgs(expectedValue), expectedValue},
18+
new object[] { new SelectedItemChangedEventArgs(expectedValue), expectedValue },
19+
new object[] { null, null },
1920
#pragma warning restore CS0618 // Type or member is obsolete
20-
};
21+
};
2122

2223
[Theory]
2324
[MemberData(nameof(GetData))]

src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Converters/ItemTappedEventArgsConverter_Tests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ public class ItemTappedEventArgsConverter_Tests
1515
{
1616
// We know it's deprecated, still good to test it
1717
#pragma warning disable CS0618 // Type or member is obsolete
18-
new object[] { new ItemTappedEventArgs(null, expectedValue), expectedValue},
18+
new object[] { new ItemTappedEventArgs(null, expectedValue), expectedValue },
19+
new object[] { new ItemTappedEventArgs(null, null), null },
1920
#pragma warning restore CS0618 // Type or member is obsolete
20-
};
21+
};
2122

2223
[Theory]
2324
[MemberData(nameof(GetData))]

src/CommunityToolkit/Xamarin.CommunityToolkit.UnitTests/Helpers/LocalizationResourceManagerTests/LocalizationResourceManagerTests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,22 @@ public void LocalizationResourceManager_GetCulture_Equal_Indexer()
4343
Assert.Equal(responceResourceManagerCulture2, responceIndexerCulture2);
4444
Assert.Equal(responceResourceManagerCulture2, responceGetValueCulture2);
4545
}
46+
47+
[Fact]
48+
public void LocalizationResourceManager_PropertyChanged_Triggered()
49+
{
50+
// Arrange
51+
var culture2 = new CultureInfo("en");
52+
localizationManager.SetCulture(culture2);
53+
CultureInfo changedCulture = null;
54+
localizationManager.PropertyChanged += (s, e) => changedCulture = localizationManager.CurrentCulture;
55+
56+
// Act, Assert
57+
localizationManager.Init(resourceManager, initialCulture);
58+
Assert.Equal(initialCulture, changedCulture);
59+
60+
localizationManager.SetCulture(culture2);
61+
Assert.Equal(culture2, changedCulture);
62+
}
4663
}
4764
}

src/CommunityToolkit/Xamarin.CommunityToolkit/Behaviors/UserStoppedTypingBehavior.shared.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public class UserStoppedTypingBehavior : BaseBehavior<InputView>
1818
public static readonly BindableProperty CommandProperty
1919
= BindableProperty.Create(nameof(Command), typeof(ICommand), typeof(UserStoppedTypingBehavior));
2020

21+
/// <summary>
22+
/// Backing BindableProperty for the <see cref="CommandParameter"/> property.
23+
/// </summary>
24+
public static readonly BindableProperty CommandParameterProperty
25+
= BindableProperty.Create(nameof(CommandParameter), typeof(object), typeof(UserStoppedTypingBehavior));
26+
2127
/// <summary>
2228
/// Backing BindableProperty for the <see cref="StoppedTypingTimeThreshold"/> property.
2329
/// </summary>
@@ -47,6 +53,15 @@ public ICommand Command
4753
set => SetValue(CommandProperty, value);
4854
}
4955

56+
/// <summary>
57+
/// An optional parameter to forward to the <see cref="Command"/>. This is a bindable property.
58+
/// </summary>
59+
public object CommandParameter
60+
{
61+
get => GetValue(CommandParameterProperty);
62+
set => SetValue(CommandParameterProperty, value);
63+
}
64+
5065
/// <summary>
5166
/// The time of inactivity in milliseconds after which <see cref="Command"/> will be executed. If <see cref="MinimumLengthThreshold"/> is also set, the condition there also needs to be met. This is a bindable property.
5267
/// </summary>
@@ -100,8 +115,8 @@ void OnTextPropertyChanged()
100115
if (ShouldDismissKeyboardAutomatically)
101116
Device.BeginInvokeOnMainThread(View.Unfocus);
102117

103-
if (Command?.CanExecute(View.Text) ?? false)
104-
Command.Execute(View.Text);
118+
if (Command?.CanExecute(CommandParameter ?? View.Text) ?? false)
119+
Command.Execute(CommandParameter ?? View.Text);
105120
});
106121
}
107122
}

src/CommunityToolkit/Xamarin.CommunityToolkit/Converters/ItemSelectedEventArgsConverter.shared.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@ public class ItemSelectedEventArgsConverter : ValueConverterExtension, IValueCon
1919
/// <param name="culture">The culture to use in the converter. This is not implemented.</param>
2020
/// <returns>A <see cref="SelectedItemChangedEventArgs.SelectedItem"/> object from object of type <see cref="SelectedItemChangedEventArgs"/>.</returns>
2121
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
22-
=> value is SelectedItemChangedEventArgs selectedItemChangedEventArgs
22+
{
23+
if (value == null)
24+
return null;
25+
26+
return value is SelectedItemChangedEventArgs selectedItemChangedEventArgs
2327
? selectedItemChangedEventArgs.SelectedItem
2428
: throw new ArgumentException("Expected value to be of type SelectedItemChangedEventArgs", nameof(value));
29+
}
2530

2631
/// <summary>
2732
/// This method is not implemented and will throw a <see cref="NotImplementedException"/>.

0 commit comments

Comments
 (0)