Skip to content

Commit

Permalink
Customize state bar
Browse files Browse the repository at this point in the history
  • Loading branch information
ProJend committed Jul 18, 2021
1 parent 4ac1228 commit 7055096
Show file tree
Hide file tree
Showing 25 changed files with 657 additions and 140 deletions.
1 change: 1 addition & 0 deletions True Love/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
<ResourceDictionary Source="Template/Breakpoint.xaml"/>
<ResourceDictionary Source="Template/Button.xaml"/>
<ResourceDictionary Source="Template/Colors.xaml"/>
<ResourceDictionary Source="Template/Fonts.xaml"/>
Expand Down
46 changes: 32 additions & 14 deletions True Love/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using Microsoft.QueryStringDotNET;
using System;
using TrueLove.Lib.Helpers;
using TrueLove.Lib.Models;
using TrueLove.UWP.Pages;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.ApplicationModel.Core;
using Windows.Storage;
using Windows.UI;
using Windows.UI.Notifications;
using Windows.UI.ViewManagement;
Expand All @@ -20,8 +20,6 @@ namespace TrueLove.UWP
/// </summary>
sealed partial class App : Application
{
public static ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;

/// <summary>
/// 初始化单一实例应用程序对象。这是执行的创作代码的第一行,
/// 已执行,逻辑上等同于 main() 或 WinMain()。
Expand Down Expand Up @@ -71,19 +69,16 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
// 确保当前窗口处于活动状态
Window.Current.Activate();

if (localSettings.Values["SetLiveTiles"] == null)
{ // 首次打开先过一边设置
localSettings.Values["SetLiveTiles"] = true;
localSettings.Values["SetHideCommandBar"] = false;
localSettings.Values["SetPageBackgroundColor"] = true;
if (SettingsVariableConverter.localSettings.Values["SetLiveTiles"] == null)
{ // 首次打开先过一边设置
var a = new SettingsPage();
a.AppFirstRun();
a = null;
GC.Collect();
}

if (!Generic.DeviceFamilyMatch(DeviceFamilyList.Mobile)) HideTitleBar();
else HideStatusBar();
else HideStatusBarAsync();
}
}

Expand All @@ -98,10 +93,10 @@ protected override async void OnActivated(IActivatedEventArgs e)
case "Settings":
var settings = new Uri("ms-settings:network-status");
var success = await Windows.System.Launcher.LaunchUriAsync(settings);
localSettings.Values["IsToastPush"] = true;
break;
goto case "Close";

case "Close":
localSettings.Values["IsToastPush"] = true;
GenericVariableConverter.isNetworkToastPush = true;
break;
}
}
Expand Down Expand Up @@ -145,12 +140,35 @@ private void HideTitleBar()
/// <summary>
/// 沉淀状态栏 for Phone
/// </summary>
private void HideStatusBar()
private async void HideStatusBarAsync()
{
var applicationView = ApplicationView.GetForCurrentView();
applicationView.SetDesiredBoundsMode(ApplicationViewBoundsMode.UseCoreWindow);
//applicationView.TryEnterFullScreenMode();

var statusbar = StatusBar.GetForCurrentView();
statusbar.BackgroundColor = Colors.Transparent;
await statusbar.ShowAsync();
//await statusbar.ProgressIndicator.HideAsync();

ApplicationView.GetForCurrentView().VisibleBoundsChanged += (s, e) =>
{
var currentHeight = s.VisibleBounds.Height;

switch (applicationView.Orientation)
{ // 横向
case ApplicationViewOrientation.Landscape:
MainPage.Current.LayoutRoot.Margin = new Thickness(0);

break;

// 纵向
case ApplicationViewOrientation.Portrait:
if (currentHeight < GenericVariableConverter.oldHeight) MainPage.Current.LayoutRoot.Margin = new Thickness(0, 0, 0, 50);
else if (currentHeight > GenericVariableConverter.oldHeight) MainPage.Current.LayoutRoot.Margin = new Thickness(0);
break;
}
GenericVariableConverter.oldHeight = s.VisibleBounds.Height;
};
}
}
}
3 changes: 2 additions & 1 deletion True Love/Pages/DeviceFamily-Mobile/HomePage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@
<VisualStateGroup>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger MinWindowWidth="476"/>
<AdaptiveTrigger
MinWindowWidth="{StaticResource MediumWindowBreakpoint}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="a.Style" Value="{StaticResource Left}"/>
Expand Down
192 changes: 192 additions & 0 deletions True Love/Pages/DeviceFamily-Mobile/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<Page
x:Class="TrueLove.UWP.Pages.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:upOS1709="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 5)"
xmlns:upOS1809="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 7)"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
mc:Ignorable="d" x:Name="Main" RequestedTheme="Dark"
Background="{x:Bind PageBackgroundColor}"
Loaded="Main_Loaded">
<Page.Resources>
<Storyboard x:Name="Close">
<DoubleAnimation Storyboard.TargetName="Translate" Storyboard.TargetProperty="Y" From="0" To="40" >
<DoubleAnimation.EasingFunction>
<ExponentialEase Exponent="7" EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
<Storyboard x:Name="Open">
<DoubleAnimation Storyboard.TargetName="Translate" Storyboard.TargetProperty="Y" From="40" To="0" >
<DoubleAnimation.EasingFunction>
<ExponentialEase Exponent="7" EasingMode="EaseOut"/>
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>

<Storyboard x:Name="EnterStoryboard">
<FadeOutThemeAnimation Storyboard.TargetName="CommandBar" />
</Storyboard>
<Storyboard x:Name="ExitStoryboard">
<FadeInThemeAnimation Storyboard.TargetName="CommandBar" />
</Storyboard>
</Page.Resources>

<Grid x:Name="LayoutRoot" x:FieldModifier="Public" Margin="0 0 0 50" ManipulationMode="System,TranslateX">
<ScrollViewer x:Name="sv" ViewChanged="Sv_ViewChanged"
VerticalScrollBarVisibility="Hidden" HorizontalScrollMode="Disabled"
VerticalScrollMode="Enabled">
<Frame x:Name="ContentFrame"/>
</ScrollViewer>

<Grid x:Name="BackgroundOfBar" MinHeight="60"
VerticalAlignment="Top" HorizontalAlignment="Stretch"
Background="{ThemeResource NavigationViewTopPaneBackground}"
>
<upOS1809:Grid.TranslationTransition>
<Vector3Transition/>
</upOS1809:Grid.TranslationTransition>
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" x:Name="AppTitleBar" Background="Transparent"/>
<TextBlock x:Name="NotificationGrid" Height="40" Margin="6 60 0 0" VerticalAlignment="Bottom">
<upOS1809:TextBlock.OpacityTransition>
<ScalarTransition/>
</upOS1809:TextBlock.OpacityTransition>
<Run x:Name="NotificationIcon" FontSize="20"></Run>
<Run Text=" "/>
<Run x:Name="NotificationHint"></Run>
</TextBlock>
</Grid>

<Grid x:Name="BottonBar" VerticalAlignment="Bottom" HorizontalAlignment="Stretch">
<!--<v1809:Grid.TranslationTransition>
<Vector3Transition/>
</v1809:Grid.TranslationTransition>-->
<upOS1809:Grid.OpacityTransition>
<ScalarTransition/>
</upOS1809:Grid.OpacityTransition>
<Grid.Transitions>
<TransitionCollection>
<PaneThemeTransition/>
</TransitionCollection>
</Grid.Transitions>

<CommandBar DefaultLabelPosition="Bottom" upOS1709:ToolTipService.ToolTip="Right tag on here to switch CommandBar."
Background="{ThemeResource NavigationViewTopPaneBackground}"
RightTapped="CommandBar_RightTapped" x:Name="CommandBar" FlowDirection="LeftToRight" OverflowButtonVisibility="Auto">
<CommandBar.RenderTransform>
<TranslateTransform x:Name="Translate"/>
</CommandBar.RenderTransform>

<!--<AppBarButton Icon="Add" Label="分享故事" Style="{StaticResource AppBarButtonRevealStyle}" ToolTipService.ToolTip="分享你与 Avicii 的故事"/>-->
<AppBarButton x:Name="BackTopButton" IsEnabled="False" Icon="Upload" Label="Back To Top" ToolTipService.ToolTip="Back to top"
Click="BackToTop_Click" Opacity="{x:Bind OpaqueIfEnabled(BackTopButton.IsEnabled), Mode=OneWay}"
upOS1709:Style="{StaticResource AppBarButtonRevealStyle}">
<upOS1809:AppBarButton.OpacityTransition>
<ScalarTransition/>
</upOS1809:AppBarButton.OpacityTransition>
</AppBarButton>
<AppBarButton x:Name="RefreshButton" Icon="Refresh" Label="Refresh" ToolTipService.ToolTip="Refresh dates"
Click="Refresh_Click" Opacity="{x:Bind OpaqueIfEnabled(RefreshButton.IsEnabled), Mode=OneWay}"
IsEnabled="{Binding ElementName=CommentPage,Path=IsSelected}" upOS1709:Style="{StaticResource AppBarButtonRevealStyle}">
<upOS1809:AppBarButton.OpacityTransition>
<ScalarTransition/>
</upOS1809:AppBarButton.OpacityTransition>
</AppBarButton>
<AppBarButton x:Name="CreatComment" Icon="Comment" Label="New Comment" ToolTipService.ToolTip="Share your menory"
Click="CreatComment_Click" Opacity="{x:Bind OpaqueIfEnabled(CreatComment.IsEnabled), Mode=OneWay}"
upOS1709:Style="{StaticResource AppBarButtonRevealStyle}">
<upOS1809:AppBarButton.OpacityTransition>
<ScalarTransition/>
</upOS1809:AppBarButton.OpacityTransition>
</AppBarButton>
<!--<CommandBar.SecondaryCommands>
</CommandBar.SecondaryCommands>-->
</CommandBar>
</Grid>

<muxc:NavigationView x:Name="NavView"
Loaded="NavView_Loaded"
BackRequested="NavView_BackRequested"
ItemInvoked="NavView_ItemInvoked"
PaneDisplayMode="Auto"
IsBackButtonVisible="Auto"
IsTitleBarAutoPaddingEnabled="False"
PaneTitle=" I N L O V I N G M E M O R Y"
>
<muxc:NavigationView.MenuItems>
<muxc:NavigationViewItemHeader Content="True" x:Name="MainPagesHeader"/>
<muxc:NavigationViewItem Content="Memory" x:Name="HomePage" Icon="Home" Tag="home"/>
<muxc:NavigationViewItem Content="Comments" x:Name="CommentPage" Icon="World" Tag="comment"/>
<muxc:NavigationViewItem Content="Images" x:Name="ImagesPage" Tag="image" Visibility="Visible">
<muxc:NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xEB9F;"/>
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
</muxc:NavigationView.MenuItems>
<muxc:NavigationView.FooterMenuItems>
<muxc:NavigationViewItemSeparator x:Name="NavSeparator"/>
<muxc:NavigationViewItem Tag="settings" x:Name="a">
<muxc:NavigationViewItem.Icon>
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE721;"/>
</muxc:NavigationViewItem.Icon>
</muxc:NavigationViewItem>
</muxc:NavigationView.FooterMenuItems>
</muxc:NavigationView>

<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="NV">
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger
MinWindowWidth="{x:Bind NavView.CompactModeThresholdWidth}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="NavView.PaneDisplayMode" Value="Top"/>
<Setter Target="MainPagesHeader.Visibility" Value="Collapsed"/>

<Setter Target="NavView.Margin" Value="50 0 50 0"/>
<Setter Target="BackgroundOfBar.MinHeight" Value="40"/>

<Setter Target="BottonBar.IsTapEnabled" Value="false"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>

<VisualStateGroup x:Name="CB">
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger
MinWindowWidth="741"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="BottonBar.VerticalAlignment" Value="Top"/>
<Setter Target="BottonBar.HorizontalAlignment" Value="Right"/>
<Setter Target="BottonBar.Margin" Value="0 0 50 0"/>
<Setter Target="CommandBar.Background" Value="Transparent"/>
<Setter Target="CommandBar.Height" Value="40"/>
</VisualState.Setters>
</VisualState>
<VisualState>
<VisualState.StateTriggers>
<AdaptiveTrigger
MinWindowWidth="{StaticResource LargeWindowBreakpoint}"/>
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="BottonBar.VerticalAlignment" Value="Top"/>
<Setter Target="BottonBar.HorizontalAlignment" Value="Center"/>
<Setter Target="CommandBar.Background" Value="Transparent"/>
<Setter Target="CommandBar.Height" Value="40"/>
<Setter Target="CommandBar.DefaultLabelPosition" Value="Right"/>

<Setter Target="NavView.Margin" Value="0 20 0 0"/>
<Setter Target="BackgroundOfBar.MinHeight" Value="60"/>
<Setter Target="BottonBar.Margin" Value="0 20 0 0"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</Page>
Loading

0 comments on commit 7055096

Please sign in to comment.