Skip to content

Commit

Permalink
fix(Windows): Simplify MainPage.xaml and add acrylic background
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 committed Sep 7, 2020
1 parent 56a44cf commit 13d83d7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 44 deletions.
23 changes: 10 additions & 13 deletions windows/ReactTestApp/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace winrt::ReactTestApp::implementation

SetUpTitleBar();

auto menuItems = MenuFlyout().Items();
auto menuItems = ReactMenuBarItem().Items();
std::optional<::ReactTestApp::Manifest> manifest = ::ReactTestApp::GetManifest();
if (!manifest.has_value()) {
MenuFlyoutItem newMenuItem;
Expand Down Expand Up @@ -81,11 +81,6 @@ namespace winrt::ReactTestApp::implementation
SetInitialProperties(component.initialProperties);
}

void MainPage::OnReactMenuClick(IInspectable const &, RoutedEventArgs)
{
ReactMenuButton().Flyout().ShowAt(ReactMenuButton());
}

MenuFlyoutItem MainPage::MakeComponentMenuButton(::ReactTestApp::Component const &component)
{
hstring componentDisplayName = to_hstring(component.displayName.value_or(component.appKey));
Expand All @@ -100,22 +95,24 @@ namespace winrt::ReactTestApp::implementation

void MainPage::SetUpTitleBar()
{
// Set close, minimize and maximize icons background to transparent
auto appView = ApplicationView::GetForCurrentView().TitleBar();
appView.ButtonBackgroundColor(Colors::Transparent());
appView.BackgroundColor(Colors::Transparent());

auto coreTitleBar = CoreApplication::GetCurrentView().TitleBar();
coreTitleBar.LayoutMetricsChanged({this, &MainPage::OnCoreTitleBarLayoutMetricsChanged});
coreTitleBar.ExtendViewIntoTitleBar(true);
Window::Current().SetTitleBar(BackgroundElement());

// Set close, minimize and maximize icons background to transparent
auto viewTitleBar = ApplicationView::GetForCurrentView().TitleBar();
viewTitleBar.ButtonBackgroundColor(Colors::Transparent());
viewTitleBar.ButtonInactiveBackgroundColor(Colors::Transparent());

Window::Current().SetTitleBar(AppTitleBar());
}

// Adjust height of custom title bar to match close, minimize and maximize icons
void MainPage::OnCoreTitleBarLayoutMetricsChanged(CoreApplicationViewTitleBar const &sender,
IInspectable const &)
{
TitleBar().Height(sender.Height());
AppTitleBar().Height(sender.Height());
AppMenuBar().Height(sender.Height());
}

void MainPage::SetInitialProperties(
Expand Down
2 changes: 0 additions & 2 deletions windows/ReactTestApp/MainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ namespace winrt::ReactTestApp::implementation
Windows::UI::Xaml::RoutedEventArgs);
void LoadFromDevServer(Windows::Foundation::IInspectable const &,
Windows::UI::Xaml::RoutedEventArgs);
void OnReactMenuClick(Windows::Foundation::IInspectable const &,
Windows::UI::Xaml::RoutedEventArgs);
Windows::Foundation::IAsyncAction
OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs const &e);
using Base = MainPageT;
Expand Down
40 changes: 11 additions & 29 deletions windows/ReactTestApp/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,23 @@
mc:Ignorable="d"
xmlns:react="using:Microsoft.ReactNative">

<Page.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="ButtonBackground" Color="{ThemeResource SystemAltHighColor}"/>
</ResourceDictionary>
</Page.Resources>

<Grid>
<Grid Background="{StaticResource SystemControlAcrylicWindowBrush}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>

<Grid x:Name="TitleBar">
<Grid>
<Grid x:Name="BackgroundElement" Background="Transparent">
<TextBlock x:Name="AppTitle" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>

<Button Content="React" x:Name="ReactMenuButton" Click="OnReactMenuClick">
<Button.Flyout>
<MenuFlyout x:Name="MenuFlyout" Placement="BottomEdgeAlignedLeft">
<MenuFlyout.MenuFlyoutPresenterStyle>
<Style TargetType= "MenuFlyoutPresenter" >
<Setter Property = "Margin" Value= "0,-5,0,0"/>
</Style>
</MenuFlyout.MenuFlyoutPresenterStyle>
<MenuFlyoutItem Text="Load from JS bundle" Click="LoadFromJSBundle"/>
<MenuFlyoutItem Text="Load from dev server" Click="LoadFromDevServer"/>
<MenuFlyoutSeparator/>
</MenuFlyout>
</Button.Flyout>
</Button>

<Grid>
<Grid x:Name="AppTitleBar" Background="Transparent">
<TextBlock x:Name="AppTitle" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>

<MenuBar x:Name="AppMenuBar" HorizontalAlignment="Left" VerticalContentAlignment="Stretch" Width="Auto">
<MenuBarItem x:Name="ReactMenuBarItem" Title="React">
<MenuFlyoutItem Text="Load from JS bundle" Click="LoadFromJSBundle"/>
<MenuFlyoutItem Text="Load from dev server" Click="LoadFromDevServer"/>
<MenuFlyoutSeparator/>
</MenuBarItem>
</MenuBar>
</Grid>

<react:ReactRootView x:Name="ReactRootView" Grid.Row="2"/>
Expand Down

0 comments on commit 13d83d7

Please sign in to comment.