From 98833961a03f24332054bc8003bfe7469d1d9f2d Mon Sep 17 00:00:00 2001 From: Tsanie Lily Date: Tue, 5 May 2020 20:26:47 +0800 Subject: [PATCH] ui fix, navigation bar adjust --- Pixiview.iOS/Pixiview.iOS.csproj | 1 + Pixiview.iOS/Renderers/AdaptedPageRenderer.cs | 17 ++- .../Renderers/NavigationPageRenderer.cs | 18 +++ Pixiview/App.cs | 4 +- Pixiview/MainPage.xaml | 16 ++- Pixiview/MainPage.xaml.cs | 16 ++- Pixiview/UI/AdaptedPage.cs | 46 ++++++++ Pixiview/UI/NavigationTitle.cs | 105 ------------------ Pixiview/UI/StyleDefinition.cs | 2 + Pixiview/UI/Theme/ThemeBase.cs | 10 ++ Pixiview/Utils/Extensions.cs | 12 +- Pixiview/Utils/UIFactory.cs | 2 +- Pixiview/ViewIllustPage.xaml | 12 ++ Pixiview/ViewIllustPage.xaml.cs | 18 +++ 14 files changed, 158 insertions(+), 121 deletions(-) create mode 100644 Pixiview.iOS/Renderers/NavigationPageRenderer.cs delete mode 100644 Pixiview/UI/NavigationTitle.cs create mode 100644 Pixiview/ViewIllustPage.xaml create mode 100644 Pixiview/ViewIllustPage.xaml.cs diff --git a/Pixiview.iOS/Pixiview.iOS.csproj b/Pixiview.iOS/Pixiview.iOS.csproj index eb8b40c..3d7a376 100644 --- a/Pixiview.iOS/Pixiview.iOS.csproj +++ b/Pixiview.iOS/Pixiview.iOS.csproj @@ -75,6 +75,7 @@ + diff --git a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs index da6d078..ce1f434 100644 --- a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs +++ b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs @@ -21,18 +21,27 @@ namespace Pixiview.iOS.Renderers if (Element is AdaptedPage page) { + //var mode = ForPage.GetLargeTitleDisplay(page); + //NavigationItem.LargeTitleDisplayMode = UINavigationItemLargeTitleDisplayMode.Automatic; + page.OnLoad(); } } + public override bool PrefersHomeIndicatorAutoHidden => Screen.GetHomeIndicatorAutoHidden(Element); + public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); - var style = ConvertStyle(StatusBar.GetStatusBarStyle(Element)); - if (UIApplication.SharedApplication.StatusBarStyle != style) + var element = Element; + if (element != null) { - SetStatusBarStyle(style); + var style = ConvertStyle(Screen.GetStatusBarStyle(element)); + if (UIApplication.SharedApplication.StatusBarStyle != style) + { + SetStatusBarStyle(style); + } } observer = UIDevice.Notifications.ObserveOrientationDidChange(ChangeOrientation); @@ -95,7 +104,7 @@ namespace Pixiview.iOS.Renderers lastOrientation = current; if (current == UIDeviceOrientation.Portrait && UIApplication.SharedApplication.StatusBarHidden) { - var style = ConvertStyle(StatusBar.GetStatusBarStyle(Element)); + var style = ConvertStyle(Screen.GetStatusBarStyle(Element)); if (style != UIStatusBarStyle.BlackOpaque) { UIApplication.SharedApplication.SetStatusBarHidden(false, true); diff --git a/Pixiview.iOS/Renderers/NavigationPageRenderer.cs b/Pixiview.iOS/Renderers/NavigationPageRenderer.cs new file mode 100644 index 0000000..e4580c0 --- /dev/null +++ b/Pixiview.iOS/Renderers/NavigationPageRenderer.cs @@ -0,0 +1,18 @@ +using Pixiview.iOS.Renderers; +using UIKit; +using Xamarin.Forms; +using Xamarin.Forms.Platform.iOS; + +[assembly: ExportRenderer(typeof(NavigationPage), typeof(NavigationPageRenderer))] +namespace Pixiview.iOS.Renderers +{ + public class NavigationPageRenderer : NavigationRenderer + { + public override void WillMoveToParentViewController(UIViewController parent) + { + NavigationBar.Translucent = true; + + base.WillMoveToParentViewController(parent); + } + } +} diff --git a/Pixiview/App.cs b/Pixiview/App.cs index 686436b..0234461 100644 --- a/Pixiview/App.cs +++ b/Pixiview/App.cs @@ -66,10 +66,10 @@ namespace Pixiview protected override void OnStart() { var service = DependencyService.Get(); - InitResources(service); InitLanguage(service); - MainPage = UIFactory.CreateNavigationPage(new MainPage()); + + InitResources(service); } protected override void OnSleep() diff --git a/Pixiview/MainPage.xaml b/Pixiview/MainPage.xaml index 648fc7d..e0308f8 100644 --- a/Pixiview/MainPage.xaml +++ b/Pixiview/MainPage.xaml @@ -9,14 +9,20 @@ xmlns:r="clr-namespace:Pixiview.Resources" mc:Ignorable="d" x:Class="Pixiview.MainPage" + util:Screen.StatusBarStyle="{DynamicResource StatusBarStyle}" BackgroundColor="{DynamicResource WindowColor}" - OrientationChanged="Page_OrientationChanged" - util:StatusBar.StatusBarStyle="{DynamicResource StatusBarStyle}"> - + Title="{r:Text Follow}" + OrientationChanged="Page_OrientationChanged"> + + + + + Aspect="AspectFill"> diff --git a/Pixiview/MainPage.xaml.cs b/Pixiview/MainPage.xaml.cs index 86269ae..4122f0c 100644 --- a/Pixiview/MainPage.xaml.cs +++ b/Pixiview/MainPage.xaml.cs @@ -82,7 +82,10 @@ namespace Pixiview base.OnAppearing(); Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged; - Loading = true; + if (!loaded) + { + Loading = true; + } } protected override void OnDisappearing() @@ -98,7 +101,10 @@ namespace Pixiview { if (e.NetworkAccess == NetworkAccess.Internet || e.NetworkAccess == NetworkAccess.ConstrainedInternet) { - Loading = true; + if (!loaded) + { + Loading = true; + } } } @@ -177,7 +183,11 @@ namespace Pixiview private void OnIllustImageTapped(IllustItem illust) { - DisplayAlert("title", $"open illust: {illust.Id}", "Ok"); + Start(() => + { + var page = new ViewIllustPage(illust); + Navigation.PushAsync(page); + }); } private void Page_OrientationChanged(object sender, OrientationEventArgs e) diff --git a/Pixiview/UI/AdaptedPage.cs b/Pixiview/UI/AdaptedPage.cs index f2b6223..37d4490 100644 --- a/Pixiview/UI/AdaptedPage.cs +++ b/Pixiview/UI/AdaptedPage.cs @@ -42,6 +42,52 @@ namespace Pixiview.UI OrientationChanged?.Invoke(this, new OrientationEventArgs { CurrentOrientation = orientation }); } + + protected void Start(Action action) + { + if (Tap.IsBusy) + { + App.DebugPrint("gesture recognizer is now busy..."); + return; + } + using (Tap.Start()) + { + action(); + } + } + + private class Tap : IDisposable + { + public static bool IsBusy => _instance?.isBusy == true; + + private static readonly object sync = new object(); + private static Tap _instance; + + private Tap() { } + + public static Tap Start() + { + if (_instance == null) + { + _instance = new Tap(); + } + lock (sync) + { + _instance.isBusy = true; + } + return _instance; + } + + private bool isBusy = false; + + public void Dispose() + { + lock (sync) + { + isBusy = false; + } + } + } } public class OrientationEventArgs : EventArgs diff --git a/Pixiview/UI/NavigationTitle.cs b/Pixiview/UI/NavigationTitle.cs deleted file mode 100644 index faced7e..0000000 --- a/Pixiview/UI/NavigationTitle.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System; -using Pixiview.UI.Theme; -using Xamarin.Forms; - -namespace Pixiview.UI -{ - public class NavigationTitle : ContentView - { - public static readonly BindableProperty TitleProperty = BindableProperty.Create( - nameof(Title), typeof(string), typeof(NavigationTitle)); - public static readonly BindableProperty IsLeftButtonVisibleProperty = BindableProperty.Create( - nameof(IsLeftButtonVisible), typeof(bool), typeof(NavigationTitle)); - public static readonly BindableProperty IsRightButtonVisibleProperty = BindableProperty.Create( - nameof(IsRightButtonVisible), typeof(bool), typeof(NavigationTitle)); - public static readonly BindableProperty RightButtonTextProperty = BindableProperty.Create( - nameof(RightButtonText), typeof(string), typeof(NavigationTitle)); - - public string Title - { - get => (string)GetValue(TitleProperty); - set => SetValue(TitleProperty, value); - } - public bool IsLeftButtonVisible - { - get => (bool)GetValue(IsLeftButtonVisibleProperty); - set => SetValue(IsLeftButtonVisibleProperty, value); - } - public bool IsRightButtonVisible - { - get => (bool)GetValue(IsRightButtonVisibleProperty); - set => SetValue(IsRightButtonVisibleProperty, value); - } - public string RightButtonText - { - get => (string)GetValue(RightButtonTextProperty); - set => SetValue(RightButtonTextProperty, value); - } - - public event EventHandler LeftButtonClicked; - public event EventHandler RightButtonClicked; - - public NavigationTitle() - { - BindingContext = this; - - var left = GetLinkButton(nameof(IsLeftButtonVisible), - padding: StyleDefinition.HorizonRight10); - left.SetDynamicResource(Button.FontFamilyProperty, ThemeBase.IconRegularFontFamily); - left.SetDynamicResource(Button.TextProperty, ThemeBase.IconLeft); - left.Clicked += Left_Clicked; - - var title = new Label(); - title.SetDynamicResource(StyleProperty, ThemeBase.TitleLabel); - title.SetBinding(Label.TextProperty, nameof(Title)); - Grid.SetColumnSpan(title, 3); - - var right = GetLinkButton(nameof(IsRightButtonVisible), - text: nameof(RightButtonText), - horizon: LayoutOptions.End, - padding: StyleDefinition.HorizonLeft10); - right.Clicked += Right_Clicked; - Grid.SetColumn(right, 2); - - Content = new Grid - { - ColumnDefinitions = - { - new ColumnDefinition { Width = GridLength.Auto }, - new ColumnDefinition(), - new ColumnDefinition { Width = GridLength.Auto } - }, - ColumnSpacing = 0, - Children = { title, left, right } - }; - } - - private void Left_Clicked(object sender, EventArgs e) - { - LeftButtonClicked?.Invoke(sender, e); - } - - private void Right_Clicked(object sender, EventArgs e) - { - RightButtonClicked?.Invoke(sender, e); - } - - private Button GetLinkButton(string visibility, string text = null, LayoutOptions horizon = default, Thickness padding = default) - { - var button = new Button - { - VerticalOptions = LayoutOptions.Center, - HorizontalOptions = horizon, - Padding = padding - }; - button.SetBinding(IsVisibleProperty, visibility); - if (text != null) - { - button.SetBinding(Button.TextProperty, text); - } - button.SetDynamicResource(StyleProperty, ThemeBase.TitleButton); - return button; - } - } -} - diff --git a/Pixiview/UI/StyleDefinition.cs b/Pixiview/UI/StyleDefinition.cs index bbd2b29..cb8e284 100644 --- a/Pixiview/UI/StyleDefinition.cs +++ b/Pixiview/UI/StyleDefinition.cs @@ -12,8 +12,10 @@ namespace Pixiview.UI public static readonly Thickness HorizonLeft10 = new Thickness(10, 0, 0, 0); public static readonly Thickness HorizonRight10 = new Thickness(0, 0, 10, 0); public static readonly Thickness LeftBottom10 = new Thickness(10, 0, 0, 10); + public static readonly GridLength TitleIconWidth = 40; public const string IconLayer = "\uf302"; + public const string IconOption = "\uf013"; private static bool? _isFullscreenDevice; public static bool IsFullscreenDevice diff --git a/Pixiview/UI/Theme/ThemeBase.cs b/Pixiview/UI/Theme/ThemeBase.cs index 3947caa..f6a0350 100644 --- a/Pixiview/UI/Theme/ThemeBase.cs +++ b/Pixiview/UI/Theme/ThemeBase.cs @@ -6,6 +6,7 @@ namespace Pixiview.UI.Theme { public const string TitleButton = nameof(TitleButton); public const string TitleLabel = nameof(TitleLabel); + public const string FontIconOption = nameof(FontIconOption); public const string StatusBarStyle = nameof(StatusBarStyle); public const string WindowColor = nameof(WindowColor); @@ -22,12 +23,14 @@ namespace Pixiview.UI.Theme public const string FontSizeTitle = nameof(FontSizeTitle); public const string FontSizeTitleIcon = nameof(FontSizeTitleIcon); //public const string Horizon10 = nameof(Horizon10); + public const string IconOption = nameof(IconOption); protected void InitResources() { Add(FontSizeTitle, StyleDefinition.FontSizeTitle); Add(FontSizeTitleIcon, StyleDefinition.FontSizeTitleIcon); //Add(Horizon10, StyleDefinition.Horizon10); + Add(IconOption, StyleDefinition.IconOption); if (App.ExtraResources != null) { @@ -59,6 +62,13 @@ namespace Pixiview.UI.Theme new Setter { Property = Button.TextColorProperty, Value = this[MainTextColor] } } }); + + Add(FontIconOption, new FontImageSource + { + FontFamily = (string)this[IconSolidFontFamily], + Glyph = StyleDefinition.IconOption, + Size = StyleDefinition.FontSizeTitle + }); } } } diff --git a/Pixiview/Utils/Extensions.cs b/Pixiview/Utils/Extensions.cs index 7e4a3ec..f97844a 100644 --- a/Pixiview/Utils/Extensions.cs +++ b/Pixiview/Utils/Extensions.cs @@ -2,9 +2,10 @@ namespace Pixiview.Utils { - public static class StatusBar + public static class Screen { private const string StatusBarStyle = nameof(StatusBarStyle); + private const string HomeIndicatorAutoHidden = nameof(HomeIndicatorAutoHidden); public static readonly BindableProperty StatusBarStyleProperty = BindableProperty.CreateAttached( StatusBarStyle, @@ -12,8 +13,17 @@ namespace Pixiview.Utils typeof(Page), StatusBarStyles.WhiteText); + public static readonly BindableProperty HomeIndicatorAutoHiddenProperty = BindableProperty.CreateAttached( + HomeIndicatorAutoHidden, + typeof(bool), + typeof(Page), + false); + public static StatusBarStyles GetStatusBarStyle(VisualElement page) => (StatusBarStyles)page.GetValue(StatusBarStyleProperty); public static void SetStatusBarStyle(VisualElement page, StatusBarStyles value) => page.SetValue(StatusBarStyleProperty, value); + + public static bool GetHomeIndicatorAutoHidden(VisualElement page) => (bool)page.GetValue(HomeIndicatorAutoHiddenProperty); + public static void SetHomeIndicatorAutoHidden(VisualElement page, bool value) => page.SetValue(HomeIndicatorAutoHiddenProperty, value); } public enum StatusBarStyles diff --git a/Pixiview/Utils/UIFactory.cs b/Pixiview/Utils/UIFactory.cs index d90e306..c66e38b 100644 --- a/Pixiview/Utils/UIFactory.cs +++ b/Pixiview/Utils/UIFactory.cs @@ -8,7 +8,7 @@ namespace Pixiview.Utils public static NavigationPage CreateNavigationPage(Page root) { var navigation = new NavigationPage(root); - navigation.SetDynamicResource(NavigationPage.BarBackgroundColorProperty, ThemeBase.MainColor); + //navigation.SetDynamicResource(NavigationPage.BarBackgroundColorProperty, ThemeBase.MainColor); navigation.SetDynamicResource(NavigationPage.BarTextColorProperty, ThemeBase.MainTextColor); navigation.SetDynamicResource(VisualElement.BackgroundColorProperty, ThemeBase.WindowColor); return navigation; diff --git a/Pixiview/ViewIllustPage.xaml b/Pixiview/ViewIllustPage.xaml new file mode 100644 index 0000000..f9932c8 --- /dev/null +++ b/Pixiview/ViewIllustPage.xaml @@ -0,0 +1,12 @@ + + + diff --git a/Pixiview/ViewIllustPage.xaml.cs b/Pixiview/ViewIllustPage.xaml.cs new file mode 100644 index 0000000..2ef1772 --- /dev/null +++ b/Pixiview/ViewIllustPage.xaml.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using Pixiview.UI; +using Xamarin.Forms; + +namespace Pixiview +{ + public partial class ViewIllustPage : AdaptedPage + { + private readonly IllustItem illust; + + public ViewIllustPage(IllustItem illust) + { + this.illust = illust; + InitializeComponent(); + } + } +}