ui fix, navigation bar adjust

This commit is contained in:
Tsanie Lily 2020-05-05 20:26:47 +08:00
parent d40dfccc07
commit 98833961a0
14 changed files with 158 additions and 121 deletions

View File

@ -75,6 +75,7 @@
<Compile Include="Renderers\CardViewRenderer.cs" />
<Compile Include="Renderers\RoundImageRenderer.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Renderers\NavigationPageRenderer.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Resources\LaunchScreen.storyboard" />

View File

@ -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);

View File

@ -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);
}
}
}

View File

@ -66,10 +66,10 @@ namespace Pixiview
protected override void OnStart()
{
var service = DependencyService.Get<IEnvironmentService>();
InitResources(service);
InitLanguage(service);
MainPage = UIFactory.CreateNavigationPage(new MainPage());
InitResources(service);
}
protected override void OnSleep()

View File

@ -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}">
<NavigationPage.TitleView>
Title="{r:Text Follow}"
OrientationChanged="Page_OrientationChanged">
<!--<NavigationPage.TitleView>
<u:NavigationTitle Title="{r:Text Follow}"
IsRightButtonVisible="True"
RightButtonText="{DynamicResource IconOption}"
RightButtonClicked="NavigationTitle_RightButtonClicked"/>
</NavigationPage.TitleView>
</NavigationPage.TitleView>-->
<ContentPage.ToolbarItems>
<ToolbarItem Order="Primary" Clicked="NavigationTitle_RightButtonClicked"
IconImageSource="{DynamicResource FontIconOption}"/>
</ContentPage.ToolbarItems>
<Grid>
<ScrollView HorizontalOptions="Fill" Padding="{Binding StatusBarPadding}">
<u:FlowLayout ItemsSource="{Binding Illusts}"
@ -39,7 +45,7 @@
CornerMasks="Top"
Source="{Binding Image}"
HorizontalOptions="Fill"
Aspect="AspectFit">
Aspect="AspectFill">
<u:RoundImage.GestureRecognizers>
<TapGestureRecognizer Command="{Binding IllustTapped}" CommandParameter="{Binding .}"/>
</u:RoundImage.GestureRecognizers>

View File

@ -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)

View File

@ -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

View File

@ -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;
}
}
}

View File

@ -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

View File

@ -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
});
}
}
}

View File

@ -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

View File

@ -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;

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<u:AdaptedPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:u="clr-namespace:Pixiview.UI"
xmlns:util="clr-namespace:Pixiview.Utils"
xmlns:r="clr-namespace:Pixiview.Resources"
x:Class="Pixiview.ViewIllustPage"
util:Screen.StatusBarStyle="{DynamicResource StatusBarStyle}"
util:Screen.HomeIndicatorAutoHidden="True"
BackgroundColor="{DynamicResource WindowColor}"
Title="{r:Text Preview}">
</u:AdaptedPage>

View File

@ -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();
}
}
}