Skip to content

Commit

Permalink
feat: Implement WinUI CommandBar and AppBar
Browse files Browse the repository at this point in the history
  • Loading branch information
kazo0 committed Oct 31, 2021
1 parent a2f497c commit ce12824
Show file tree
Hide file tree
Showing 113 changed files with 18,195 additions and 4,412 deletions.
6 changes: 6 additions & 0 deletions build/PackageDiffIgnore.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7267,6 +7267,12 @@
<Member
fullName="System.Void Windows.ApplicationModel.Calls.PhoneCallManager..ctor()"
reason="API alignment" />
<Member
fullName="System.Void Windows.UI.Xaml.Controls.Primitives.AppBarTemplateSettings..ctor(Windows.UI.Xaml.Controls.AppBar appBar)"
reason="API alignment" />
<Member
fullName="System.Void Windows.UI.Xaml.Controls.Primitives.CommandBarTemplateSettings..ctor(Windows.UI.Xaml.Controls.CommandBar commandBar)"
reason="API alignment" />
</Methods>
<Events>
<Member
Expand Down
4 changes: 0 additions & 4 deletions src/SamplesApp/SamplesApp.Shared/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,6 @@ public static void ConfigureFilters()

static void ConfigureFeatureFlags()
{
#if !NETFX_CORE
Uno.UI.FeatureConfiguration.Style.UseUWPDefaultStylesOverride[typeof(CommandBar)] = false;
#endif

#if __IOS__
Uno.UI.FeatureConfiguration.CommandBar.AllowNativePresenterContent = true;
#endif
Expand Down
16 changes: 11 additions & 5 deletions src/SamplesApp/SamplesApp.UITests/RuntimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,26 +42,31 @@ IAppQuery AllQuery(IAppQuery query)
var unitTestsControl = new QueryEx(q => AllQuery(q).Marked("UnitTestsRootControl"));

async Task<bool> IsTestExecutionDone()
{
return await GetWithRetry("IsTestExecutionDone", () => runningState.GetDependencyPropertyValue("Text")?.ToString().Equals("Finished", StringComparison.OrdinalIgnoreCase) ?? false);
}

async Task<T> GetWithRetry<T>(string logName, Func<T> getter, int timeoutSeconds = 10)
{
var sw = Stopwatch.StartNew();
Exception lastException = null;
do
{
try
{
return runningState.GetDependencyPropertyValue("Text")?.ToString().Equals("Finished", StringComparison.OrdinalIgnoreCase) ?? false;
return getter();
}
catch (Exception e)
{
lastException = e;
Console.WriteLine($"IsTestExecutionDone failed with {e.Message}");
Console.WriteLine($"{logName} failed with {e.Message}");
}

await Task.Delay(TimeSpan.FromSeconds(.5));

Console.WriteLine($"IsTestExecutionDone retrying");
Console.WriteLine($"{logName} retrying");
}
while (sw.Elapsed < TimeSpan.FromSeconds(10));
while (sw.Elapsed < TimeSpan.FromSeconds(timeoutSeconds));

throw lastException;
}
Expand All @@ -75,7 +80,8 @@ async Task<bool> IsTestExecutionDone()

while(DateTimeOffset.Now - lastChange < TestRunTimeout)
{
var newValue = GetValue(nameof(runTestCount), runTestCount);
var newValue = await GetWithRetry("GetRunTestCount", () => runTestCount.GetDependencyPropertyValue("Text")?.ToString());

if (lastValue != newValue)
{
lastChange = DateTimeOffset.Now;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Page x:Class="UITests.Microsoft_UI_Xaml_Controls.CommandBarTests.CommandBar_Primary_And_Secondary"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CommandBarTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:not_win="http://uno.ui/not_win"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d not_win"
Background="Red">

<CommandBar VerticalAlignment="Center">
<CommandBar.PrimaryCommands>
<AppBarButton Label="PCommand" />
<AppBarButton Label="PCommand" />
<AppBarButton Label="PCommand" />
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>
<AppBarButton Label="SCommand" />
<AppBarButton Label="SCommand" />
<AppBarButton Label="SCommand" />
</CommandBar.SecondaryCommands>
</CommandBar>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Uno.UI.Samples.Controls;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238

namespace UITests.Microsoft_UI_Xaml_Controls.CommandBarTests
{
[Sample("CommandBar")]
public sealed partial class CommandBar_Primary_And_Secondary : Page
{
public CommandBar_Primary_And_Secondary()
{
this.InitializeComponent();
}
}
}
7 changes: 7 additions & 0 deletions src/SamplesApp/UITests.Shared/UITests.Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\CommandBarTests\CommandBar_Primary_And_Secondary.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ImageIconTests\ImageIconPage.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -4368,6 +4372,9 @@
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ColorPickerTests\WinUIColorPickerPage.xaml.cs">
<DependentUpon>WinUIColorPickerPage.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\CommandBarTests\CommandBar_Primary_And_Secondary.xaml.cs">
<DependentUpon>CommandBar_Primary_And_Secondary.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)Microsoft_UI_Xaml_Controls\ImageIconTests\ImageIconPage.xaml.cs">
<DependentUpon>ImageIconPage.xaml</DependentUpon>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
</Grid.RowDefinitions>

<CommandBar x:Name="AppCommandBar"
Style="{StaticResource NativeDefaultCommandBar}"
Grid.Row="0"
Content="Title"
Background="Red">

<!-- Disabled Button -->
<AppBarButton x:Uid="ButtonDisabled"
Style="{StaticResource NativeDefaultAppBarButton}"
Content="Disabled"
IsEnabled="False" />

<!-- Done Button -->
<AppBarButton x:Uid="ButtonDone"
Style="{StaticResource NativeDefaultAppBarButton}"
Content="Done"
Foreground="Blue"
Click="OnCommandBarButtonClick" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
Grid.Row="2" />

</Grid>
</Page>
</Page>
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,60 @@
</AppBarButton.Icon>
</AppBarButton>

<android:CommandBar Content="Title"
toolkit:CommandBarExtensions.Subtitle="Subtitle" />
<android:Grid>
<CommandBar Content="Title"
toolkit:CommandBarExtensions.Subtitle="Subtitle" />
</android:Grid>

<xamarin:CommandBar Content="Title">
<toolkit:CommandBarExtensions.NavigationCommand>
<AppBarButton Command="{Binding Command}"
Label="Label">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Icons/menu.png" />
</AppBarButton.Icon>
</AppBarButton>
</toolkit:CommandBarExtensions.NavigationCommand>
</xamarin:CommandBar>
<xamarin:Grid>
<CommandBar Content="Title">
<toolkit:CommandBarExtensions.NavigationCommand>
<AppBarButton Command="{Binding Command}"
Label="Label">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Icons/menu.png" />
</AppBarButton.Icon>
</AppBarButton>
</toolkit:CommandBarExtensions.NavigationCommand>
</CommandBar>
</xamarin:Grid>

<xamarin:CommandBar Content="Title"
Background="Tomato"
Foreground="White">
<toolkit:CommandBarExtensions.NavigationCommand>
<AppBarButton Command="{Binding Command}"
Label="Label"
Foreground="White">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Icons/menu.png" />
</AppBarButton.Icon>
</AppBarButton>
</toolkit:CommandBarExtensions.NavigationCommand>
</xamarin:CommandBar>
<xamarin:Grid>
<CommandBar Content="Title"
Background="Tomato"
Foreground="White">
<toolkit:CommandBarExtensions.NavigationCommand>
<AppBarButton Command="{Binding Command}"
Label="Label"
Foreground="White">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Icons/menu.png" />
</AppBarButton.Icon>
</AppBarButton>
</toolkit:CommandBarExtensions.NavigationCommand>
</CommandBar>
</xamarin:Grid>

<ios:CommandBar Content="Title"
toolkit:CommandBarExtensions.BackButtonForeground="Red">
<toolkit:CommandBarExtensions.NavigationCommand>
<AppBarButton Command="{Binding Command}"
Label="Label">
<ios:Grid>
<CommandBar Content="Title"
toolkit:CommandBarExtensions.BackButtonForeground="Red">
<toolkit:CommandBarExtensions.NavigationCommand>
<AppBarButton Command="{Binding Command}"
Label="Label">
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Icons/menu.png" />
</AppBarButton.Icon>
</AppBarButton>
</toolkit:CommandBarExtensions.NavigationCommand>
<AppBarButton Content="Button" />
<AppBarButton>
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Icons/menu.png" />
<BitmapIcon UriSource="ms-appx:///Assets/Icons/search.png" />
</AppBarButton.Icon>
</AppBarButton>
</toolkit:CommandBarExtensions.NavigationCommand>
<AppBarButton Content="Button" />
<AppBarButton>
<AppBarButton.Icon>
<BitmapIcon UriSource="ms-appx:///Assets/Icons/search.png" />
</AppBarButton.Icon>
</AppBarButton>
</ios:CommandBar>
</CommandBar>
</ios:Grid>


</StackPanel>
</ScrollViewer>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,47 +1,54 @@
<Page
x:Class="UITests.Windows_UI_Xaml_Controls.CommandBar.CommandBar_Native_With_AppBarButton_With_Foreground"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.CommandBar"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d xamarin ios android"
xmlns:xamarin="http://nventive.com/xamarin"
xmlns:ios="http://nventive.com/ios"
xmlns:android="http://nventive.com/android"

Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Page x:Class="UITests.Windows_UI_Xaml_Controls.CommandBar.CommandBar_Native_With_AppBarButton_With_Foreground"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UITests.Windows_UI_Xaml_Controls.CommandBar"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d xamarin ios android"
xmlns:xamarin="http://nventive.com/xamarin"
xmlns:ios="http://nventive.com/ios"
xmlns:android="http://nventive.com/android"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Page.Resources>
<Style x:Name="NativeCommandbarStyle"
TargetType="CommandBar"
xamarin:BasedOn="{StaticResource NativeDefaultCommandBar}"/>
TargetType="CommandBar"
xamarin:BasedOn="{StaticResource NativeDefaultCommandBar}" />
</Page.Resources>

<Grid>
<android:Grid>
<CommandBar x:Name="MyCommandBar"
Style="{StaticResource NativeCommandbarStyle}"
Background="Gray">
<CommandBar.PrimaryCommands>
<AppBarButton Content="Hello">
<AppBarButton.Icon>
<BitmapIcon x:Name="MyIcon"
UriSource="ms-appx:///Assets/Icons/star_full.png"
Foreground="Red" />
</AppBarButton.Icon>
</AppBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
</android:Grid>


<android:CommandBar x:Name="MyCommandBar"
Style="{StaticResource NativeCommandbarStyle}"
Background="Gray">
<CommandBar.PrimaryCommands>
<AppBarButton Content="Hello">
<AppBarButton.Icon>
<BitmapIcon x:Name="MyIcon" UriSource="ms-appx:///Assets/Icons/star_full.png" Foreground="Red"/>
</AppBarButton.Icon>
</AppBarButton>
</CommandBar.PrimaryCommands>
</android:CommandBar>
<ios:Grid>
<CommandBar x:Name="MyCommandBar"
Style="{StaticResource NativeCommandbarStyle}"
Background="Gray">
<CommandBar.PrimaryCommands>
<AppBarButton Content="Hello">
<AppBarButton.Icon>
<BitmapIcon x:Name="MyIcon"
UriSource="ms-appx:///Assets/Icons/star_full.png"
Foreground="Red" />
</AppBarButton.Icon>
</AppBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
</ios:Grid>

<ios:CommandBar x:Name="MyCommandBar"
Style="{StaticResource NativeCommandbarStyle}"
Background="Gray">
<CommandBar.PrimaryCommands>
<AppBarButton Content="Hello">
<AppBarButton.Icon>
<BitmapIcon x:Name="MyIcon" UriSource="ms-appx:///Assets/Icons/star_full.png" Foreground="Red"/>
</AppBarButton.Icon>
</AppBarButton>
</CommandBar.PrimaryCommands>
</ios:CommandBar>
</Grid>
</Page>
Loading

0 comments on commit ce12824

Please sign in to comment.