ui adjustment

This commit is contained in:
Tsanie Lily 2020-05-05 12:13:50 +08:00
parent 0ce7757ec4
commit fdf4c128af
18 changed files with 583 additions and 84 deletions

View File

@ -72,6 +72,8 @@
<Compile Include="Services\EnvironmentService.cs" />
<Compile Include="Renderers\CircleImageRenderer.cs" />
<Compile Include="Renderers\RoundLabelRenderer.cs" />
<Compile Include="Renderers\CardViewRenderer.cs" />
<Compile Include="Renderers\RoundImageRenderer.cs" />
</ItemGroup>
<ItemGroup>
<InterfaceDefinition Include="Resources\LaunchScreen.storyboard" />

View File

@ -0,0 +1,53 @@
using CoreGraphics;
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(CardView), typeof(CardViewRenderer))]
namespace Pixiview.iOS.Renderers
{
public class CardViewRenderer : VisualElementRenderer<CardView>
{
protected override void OnElementChanged(ElementChangedEventArgs<CardView> e)
{
base.OnElementChanged(e);
var layer = Layer;
var element = e.NewElement;
if (layer != null && element != null)
{
var cornerRadius = element.CornerRadius;
if (cornerRadius > 0)
{
layer.CornerRadius = cornerRadius;
}
//if (element.BackgroundColor != default)
//{
// layer.BackgroundColor = element.BackgroundColor.ToCGColor();
//}
var shadowColor = element.ShadowColor;
if (shadowColor != default)
{
layer.ShadowColor = shadowColor.ToCGColor();
layer.ShadowOpacity = 1f;
var radius = element.ShadowRadius;
if (radius > 0)
{
layer.ShadowRadius = radius;
}
layer.ShadowOffset = element.ShadowOffset.ToSizeF();
}
else
{
layer.ShadowOpacity = 0f;
}
}
}
}
}

View File

@ -12,9 +12,10 @@ namespace Pixiview.iOS.Renderers
{
base.OnElementChanged(e);
if (Control != null)
var layer = Layer;
if (layer != null)
{
Control.Layer.MasksToBounds = true;
layer.MasksToBounds = true;
}
}
@ -22,9 +23,10 @@ namespace Pixiview.iOS.Renderers
{
base.LayoutSubviews();
if (Control != null)
var control = Control;
if (control != null)
{
Control.Layer.CornerRadius = Control.Frame.Size.Width / 2;
control.Layer.CornerRadius = control.Frame.Size.Width / 2;
}
}
}

View File

@ -0,0 +1,56 @@
using CoreAnimation;
using Pixiview.iOS.Renderers;
using Pixiview.UI;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(RoundImage), typeof(RoundImageRenderer))]
namespace Pixiview.iOS.Renderers
{
public class RoundImageRenderer : ImageRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Image> e)
{
base.OnElementChanged(e);
var layer = Layer;
if (layer != null && e.NewElement is RoundImage image)
{
bool flag = false;
if (image.CornerRadius > 0)
{
layer.CornerRadius = image.CornerRadius;
flag = true;
}
var mask = image.CornerMasks;
if (mask != CornerMask.None)
{
var m = default(CACornerMask);
if ((mask & CornerMask.LeftTop) == CornerMask.LeftTop)
{
m |= CACornerMask.MinXMinYCorner;
}
if ((mask & CornerMask.RightTop) == CornerMask.RightTop)
{
m |= CACornerMask.MaxXMinYCorner;
}
if ((mask & CornerMask.LeftBottom) == CornerMask.LeftBottom)
{
m |= CACornerMask.MinXMaxYCorner;
}
if ((mask & CornerMask.RightBottom) == CornerMask.RightBottom)
{
m |= CACornerMask.MaxXMaxYCorner;
}
layer.MaskedCorners = m;
flag = true;
}
if (flag)
{
layer.MasksToBounds = true;
}
}
}
}
}

View File

@ -13,14 +13,22 @@ namespace Pixiview.iOS.Renderers
{
base.OnElementChanged(e);
if (Control != null && Element is RoundLabel label)
var layer = Layer;
if (layer != null && e.NewElement is RoundLabel label)
{
int radius = label.CornerRadius;
var radius = label.CornerRadius;
if (radius > 0)
{
Control.Layer.CornerRadius = radius;
Control.BackgroundColor = label.BackgroundColor.ToUIColor();
Control.Layer.MasksToBounds = true;
layer.CornerRadius = radius;
//layer.MasksToBounds = true;
}
else
{
layer.CornerRadius = 0;
}
if (layer.BackgroundColor != default)
{
layer.BackgroundColor = label.BackgroundColor.ToCGColor();
}
}
}
@ -31,14 +39,15 @@ namespace Pixiview.iOS.Renderers
if (e.PropertyName == RoundLabel.CornerRadiusProperty.PropertyName)
{
if (Control != null && Element is RoundLabel label)
var layer = Layer;
if (layer != null && Element is RoundLabel label)
{
int radius = label.CornerRadius;
var radius = label.CornerRadius;
if (radius > 0)
{
Control.Layer.CornerRadius = radius;
Control.BackgroundColor = label.BackgroundColor.ToUIColor();
Control.Layer.MasksToBounds = true;
layer.CornerRadius = radius;
layer.BackgroundColor = label.BackgroundColor.ToCGColor();
//layer.MasksToBounds = true;
}
}
}

View File

@ -1,5 +1,8 @@
using Pixiview.iOS.Services;
using System.Diagnostics.CodeAnalysis;
using Pixiview.iOS.Services;
using Pixiview.Utils;
using UIKit;
using Xamarin.Essentials;
using Xamarin.Forms;
[assembly: Dependency(typeof(EnvironmentService))]
@ -7,6 +10,32 @@ namespace Pixiview.iOS.Services
{
public class EnvironmentService : IEnvironmentService
{
[SuppressMessage("Code Notifications", "XI0002:Notifies you from using newer Apple APIs when targeting an older OS version", Justification = "<Pending>")]
public Theme GetApplicationTheme()
{
if (UIDevice.CurrentDevice.CheckSystemVersion(12, 0))
{
var currentController = Platform.GetCurrentUIViewController();
if (currentController == null)
{
return Theme.Light;
}
var style = currentController.TraitCollection.UserInterfaceStyle;
if (style == UIUserInterfaceStyle.Dark)
{
return Theme.Dark;
}
else
{
return Theme.Light;
}
}
else
{
return Theme.Light;
}
}
public EnvironmentParameter GetEnvironment()
{
return new EnvironmentParameter
@ -18,5 +47,10 @@ namespace Pixiview.iOS.Services
IconLeft = "\uf104" // for android, it's "\uf060"
};
}
public void SetStatusBarColor(Color color)
{
// nothing need to do
}
}
}

88
Pixiview/App.cs Normal file
View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using Pixiview.UI.Theme;
using Pixiview.Utils;
using Xamarin.Forms;
namespace Pixiview
{
public class App : Application
{
// public properties
public static Theme CurrentTheme { get; private set; }
public static Dictionary<string, object> ExtraResources { get; private set; }
public App()
{
InitResources();
}
private void InitResources()
{
var service = DependencyService.Get<IEnvironmentService>();
var p = service.GetEnvironment();
ExtraResources = new Dictionary<string, object>
{
{ ThemeBase.IconLightFontFamily, p.IconLightFontFamily },
{ ThemeBase.IconRegularFontFamily, p.IconRegularFontFamily },
{ ThemeBase.IconSolidFontFamily, p.IconSolidFontFamily },
{ ThemeBase.IconLeft, p.IconLeft }
};
var theme = service.GetApplicationTheme();
SetTheme(theme, true);
}
private void SetTheme(Theme theme, bool force = false)
{
if (force || theme != CurrentTheme)
{
CurrentTheme = theme;
}
else
{
return;
}
DebugPrint($"application theme: {theme}");
ThemeBase themeInstance;
if (theme == Theme.Dark)
{
themeInstance = DarkTheme.Instance;
}
else
{
themeInstance = LightTheme.Instance;
}
//DependencyService.Get<IEnvironmentService>().SetStatusBarColor
Resources = themeInstance;
}
protected override void OnStart()
{
MainPage = UIFactory.CreateNavigationPage(new MainPage());
}
protected override void OnSleep()
{
}
protected override void OnResume()
{
var theme = DependencyService.Get<IEnvironmentService>().GetApplicationTheme();
SetTheme(theme);
}
public static void DebugPrint(string message)
{
Debug.WriteLine("[{0:HH:mm:ss.ffff}] - {1}", DateTime.Now, message);
}
public static void DebugError(string category, string message)
{
Debug.Fail(string.Format("[{0:HH:mm:ss.ffff}] - {1} - {2}", DateTime.Now, category, message));
}
}
}

View File

@ -14,54 +14,64 @@
LeftButtonClicked="NavigationTitle_LeftButtonClicked"
RightButtonClicked="NavigationTitle_RightButtonClicked"/>
</NavigationPage.TitleView>
<ScrollView HorizontalOptions="Fill" Padding="{Binding StatusBarPadding}">
<u:FlowLayout ItemsSource="{Binding Illusts}"
HorizontalOptions="Fill" Column="{Binding Columns}"
Margin="16" RowSpacing="16" ColumnSpacing="16">
<u:FlowLayout.ItemTemplate>
<DataTemplate>
<Frame HasShadow="False" Padding="0" Margin="0" CornerRadius="10"
BackgroundColor="{DynamicResource MainColor}">
<Grid HorizontalOptions="Fill" Margin="0, -5, 0, 0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image BackgroundColor="LightGray"
Source="{Binding Image}"
HorizontalOptions="Fill"
Aspect="AspectFit"/>
<u:RoundLabel Text="R-18" BackgroundColor="#fd4363" Margin="6, 11, 0, 0"
Padding="6, 2" CornerRadius="4"
HorizontalOptions="Start" VerticalOptions="Start"
FontSize="Micro" TextColor="White"
IsVisible="{Binding IsRestrict}"/>
<u:RoundLabel Text="{Binding PageCountText}"
FontFamily="{DynamicResource IconSolidFontFamily}"
BackgroundColor="#50000000" Margin="0, 11, 6, 0"
Padding="6, 4" CornerRadius="6"
HorizontalOptions="End" VerticalOptions="Start"
FontSize="Micro" TextColor="White"
IsVisible="{Binding IsPageVisible}"/>
<Label Grid.Row="1" Text="{Binding Title}"
Padding="8, 2"
TextColor="{DynamicResource TextColor}"
LineBreakMode="TailTruncation"
FontSize="Small"/>
<StackLayout Grid.Row="2" Orientation="Horizontal" Padding="8, 0, 8, 8">
<u:CircleImage WidthRequest="30" HeightRequest="30" Aspect="AspectFill"
Source="{Binding ProfileImage}"/>
<Label Text="{Binding UserName}"
VerticalOptions="Center"
TextColor="{DynamicResource SubTextColor}"
<Grid>
<ScrollView HorizontalOptions="Fill" Padding="{Binding StatusBarPadding}">
<u:FlowLayout ItemsSource="{Binding Illusts}"
HorizontalOptions="Fill" Column="{Binding Columns}"
Margin="16" RowSpacing="16" ColumnSpacing="16">
<u:FlowLayout.ItemTemplate>
<DataTemplate>
<u:CardView Padding="0" Margin="0" CornerRadius="10"
ShadowColor="#20000000"
ShadowOffset="2, 2"
BackgroundColor="{DynamicResource SubColor}">
<Grid HorizontalOptions="Fill">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<u:RoundImage BackgroundColor="LightGray"
CornerRadius="10"
CornerMasks="Top"
Source="{Binding Image}"
HorizontalOptions="Fill"
Aspect="AspectFit"/>
<u:RoundLabel Text="R-18" BackgroundColor="#fd4363" Margin="6, 6, 0, 0"
Padding="6, 2" CornerRadius="4"
HorizontalOptions="Start" VerticalOptions="Start"
FontSize="Micro" TextColor="White"
IsVisible="{Binding IsRestrict}"/>
<u:RoundLabel Text="{Binding PageCountText}"
FontFamily="{DynamicResource IconSolidFontFamily}"
BackgroundColor="#50000000" Margin="0, 6, 6, 0"
Padding="6, 4" CornerRadius="6"
HorizontalOptions="End" VerticalOptions="Start"
FontSize="Micro" TextColor="White"
IsVisible="{Binding IsPageVisible}"/>
<Label Grid.Row="1" Text="{Binding Title}"
Padding="8, 2"
TextColor="{DynamicResource TextColor}"
HorizontalOptions="Start"
LineBreakMode="TailTruncation"
FontSize="Micro"/>
</StackLayout>
</Grid>
</Frame>
</DataTemplate>
</u:FlowLayout.ItemTemplate>
</u:FlowLayout>
</ScrollView>
FontSize="Small"/>
<StackLayout Grid.Row="2" Orientation="Horizontal" Padding="8, 0, 8, 8">
<u:CircleImage WidthRequest="30" HeightRequest="30" Aspect="AspectFill"
Source="{Binding ProfileImage}"/>
<Label Text="{Binding UserName}"
VerticalOptions="Center"
TextColor="{DynamicResource SubTextColor}"
LineBreakMode="TailTruncation"
FontSize="Micro"/>
</StackLayout>
</Grid>
</u:CardView>
</DataTemplate>
</u:FlowLayout.ItemTemplate>
</u:FlowLayout>
</ScrollView>
<ActivityIndicator IsRunning="True" IsEnabled="True" IsVisible="{Binding Loading}"
Margin="20"
HorizontalOptions="Center" VerticalOptions="Start"/>
</Grid>
</u:AdaptedPage>

View File

@ -20,6 +20,20 @@ namespace Pixiview
nameof(Illusts), typeof(IllustCollection), typeof(MainPage));
public static readonly BindableProperty ColumnsProperty = BindableProperty.Create(
nameof(Columns), typeof(int), typeof(MainPage), 2);
public static readonly BindableProperty LoadingProperty = BindableProperty.Create(
nameof(Loading), typeof(bool), typeof(MainPage), propertyChanged: OnLoadingPropertyChanged);
private static void OnLoadingPropertyChanged(BindableObject obj, object oldValue, object newValue)
{
var page = (MainPage)obj;
var before = (bool)oldValue;
var now = (bool)newValue;
if (!page.loaded && now && Stores.NetworkAvailable)
{
page.loaded = true;
Task.Run(page.DoLoadIllusts);
}
}
public IllustCollection Illusts
{
@ -31,6 +45,11 @@ namespace Pixiview
get => (int)GetValue(ColumnsProperty);
set => SetValue(ColumnsProperty, value);
}
public bool Loading
{
get => (bool)GetValue(LoadingProperty);
set => SetValue(LoadingProperty, value);
}
private readonly ParallelOptions parallelOptions = new ParallelOptions { MaxDegreeOfParallelism = Configs.MaxThreads };
@ -54,11 +73,7 @@ namespace Pixiview
base.OnAppearing();
Connectivity.ConnectivityChanged += Connectivity_ConnectivityChanged;
if (!loaded && Stores.NetworkAvailable)
{
loaded = true;
Task.Run(DoLoadIllusts);
}
Loading = true;
}
protected override void OnDisappearing()
@ -70,10 +85,9 @@ namespace Pixiview
private void Connectivity_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
{
if (!loaded && (e.NetworkAccess == NetworkAccess.Internet || e.NetworkAccess == NetworkAccess.ConstrainedInternet))
if (e.NetworkAccess == NetworkAccess.Internet || e.NetworkAccess == NetworkAccess.ConstrainedInternet)
{
loaded = true;
Task.Run(DoLoadIllusts);
Loading = true;
}
}
@ -108,6 +122,7 @@ namespace Pixiview
var collection = new IllustCollection(data);
Illusts = collection;
Loading = false;
DoLoadImages(collection);
}

View File

@ -18,5 +18,6 @@
<ItemGroup>
<Folder Include="UI\" />
<Folder Include="Utils\" />
<Folder Include="UI\Theme\" />
</ItemGroup>
</Project>

38
Pixiview/UI/CardView.cs Normal file
View File

@ -0,0 +1,38 @@
using Xamarin.Forms;
namespace Pixiview.UI
{
public class CardView : ContentView
{
public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(
nameof(CornerRadius), typeof(float), typeof(CardView));
public static readonly BindableProperty ShadowColorProperty = BindableProperty.Create(
nameof(ShadowColor), typeof(Color), typeof(CardView));
public static readonly BindableProperty ShadowRadiusProperty = BindableProperty.Create(
nameof(ShadowRadius), typeof(float), typeof(CardView), 5f);
public static readonly BindableProperty ShadowOffsetProperty = BindableProperty.Create(
nameof(ShadowOffset), typeof(Size), typeof(CardView));
public float CornerRadius
{
get => (float)GetValue(CornerRadiusProperty);
set => SetValue(CornerRadiusProperty, value);
}
public Color ShadowColor
{
get => (Color)GetValue(ShadowColorProperty);
set => SetValue(ShadowColorProperty, value);
}
public float ShadowRadius
{
get => (float)GetValue(ShadowRadiusProperty);
set => SetValue(ShadowRadiusProperty, value);
}
public Size ShadowOffset
{
get => (Size)GetValue(ShadowOffsetProperty);
set => SetValue(ShadowOffsetProperty, value);
}
}
}

View File

@ -4,16 +4,59 @@ namespace Pixiview.UI
{
public class CircleImage : Image { }
public class RoundImage : Image
{
public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(
nameof(CornerRadius), typeof(float), typeof(RoundImage));
public static readonly BindableProperty CornerMasksProperty = BindableProperty.Create(
nameof(CornerMasks), typeof(CornerMask), typeof(RoundImage));
public float CornerRadius
{
get => (float)GetValue(CornerRadiusProperty);
set => SetValue(CornerRadiusProperty, value);
}
public CornerMask CornerMasks
{
get => (CornerMask)GetValue(CornerMasksProperty);
set => SetValue(CornerMasksProperty, value);
}
}
public enum CornerMask
{
None = 0,
LeftTop = 1,
RightTop = 2,
LeftBottom = 4,
RightBottom = 8,
Top = LeftTop | RightTop, // 3
Left = LeftTop | LeftBottom, // 5
Slash = RightTop | LeftBottom, // 6
BackSlash = LeftTop | RightBottom, // 9
Right = RightTop | RightBottom, // 10
Bottom = LeftBottom | RightBottom, // 12
ExceptRightBottom = LeftTop | RightTop | LeftBottom, // 7
ExceptLeftBottom = LeftTop | RightTop | RightBottom, // 11
ExceptRightTop = LeftTop | LeftBottom | RightBottom, // 13
ExceptLeftTop = RightTop | LeftBottom | RightBottom, // 14
All = LeftTop | RightTop | LeftBottom | RightBottom // 15
}
public class RoundLabel : Label
{
public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(
nameof(CornerRadius), typeof(int), typeof(RoundLabel));
nameof(CornerRadius), typeof(float), typeof(RoundLabel));
public static new readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(
nameof(BackgroundColor), typeof(Color), typeof(RoundLabel), Color.Transparent);
public int CornerRadius
public float CornerRadius
{
get => (int)GetValue(CornerRadiusProperty);
get => (float)GetValue(CornerRadiusProperty);
set => SetValue(CornerRadiusProperty, value);
}
public new Color BackgroundColor

View File

@ -1,4 +1,5 @@
using System;
using Pixiview.UI.Theme;
using Xamarin.Forms;
namespace Pixiview.UI
@ -44,12 +45,12 @@ namespace Pixiview.UI
var left = GetLinkButton(nameof(IsLeftButtonVisible),
padding: StyleDefinition.HorizonRight10);
left.SetDynamicResource(Button.FontFamilyProperty, App.IconRegularFontFamily);
left.SetDynamicResource(Button.TextProperty, App.IconLeft);
left.SetDynamicResource(Button.FontFamilyProperty, ThemeBase.IconRegularFontFamily);
left.SetDynamicResource(Button.TextProperty, ThemeBase.IconLeft);
left.Clicked += Left_Clicked;
var title = new Label();
title.SetDynamicResource(StyleProperty, App.TitleLabel);
title.SetDynamicResource(StyleProperty, ThemeBase.TitleLabel);
title.SetBinding(Label.TextProperty, nameof(Title));
Grid.SetColumnSpan(title, 3);
@ -96,7 +97,7 @@ namespace Pixiview.UI
{
button.SetBinding(Button.TextProperty, text);
}
button.SetDynamicResource(StyleProperty, App.TitleButton);
button.SetDynamicResource(StyleProperty, ThemeBase.TitleButton);
return button;
}
}

View File

@ -0,0 +1,37 @@
using Xamarin.Forms;
namespace Pixiview.UI.Theme
{
public partial class DarkTheme : ThemeBase
{
private static DarkTheme _instance;
public static DarkTheme Instance
{
get
{
if (_instance == null)
{
_instance = new DarkTheme();
}
return _instance;
}
}
public DarkTheme()
{
InitColors();
InitResources();
}
private void InitColors()
{
Add(WindowColor, Color.Black);
Add(TextColor, Color.White);
Add(SubTextColor, Color.LightGray);
Add(MainColor, Color.FromRgb(0x33, 0x33, 0x33));
Add(MainTextColor, Color.White);
Add(SubColor, Color.FromRgb(0x33, 0x33, 0x33));
}
}
}

View File

@ -0,0 +1,37 @@
using Xamarin.Forms;
namespace Pixiview.UI.Theme
{
public partial class LightTheme : ThemeBase
{
private static LightTheme _instance;
public static LightTheme Instance
{
get
{
if (_instance == null)
{
_instance = new LightTheme();
}
return _instance;
}
}
public LightTheme()
{
InitColors();
InitResources();
}
private void InitColors()
{
Add(WindowColor, Color.White);
Add(TextColor, Color.Black);
Add(SubTextColor, Color.DimGray);
Add(MainColor, Color.FromRgb(0x7f, 0x99, 0xc6));
Add(MainTextColor, Color.White);
Add(SubColor, Color.FromRgb(0xfa, 0xfa, 0xf0));
}
}
}

View File

@ -0,0 +1,63 @@
using Xamarin.Forms;
namespace Pixiview.UI.Theme
{
public class ThemeBase : ResourceDictionary
{
public const string TitleButton = nameof(TitleButton);
public const string TitleLabel = nameof(TitleLabel);
public const string WindowColor = nameof(WindowColor);
public const string TextColor = nameof(TextColor);
public const string SubTextColor = nameof(SubTextColor);
public const string MainColor = nameof(MainColor);
public const string MainTextColor = nameof(MainTextColor);
public const string SubColor = nameof(SubColor);
public const string IconLightFontFamily = nameof(IconLightFontFamily);
public const string IconRegularFontFamily = nameof(IconRegularFontFamily);
public const string IconSolidFontFamily = nameof(IconSolidFontFamily);
public const string IconLeft = nameof(IconLeft);
public const string FontSizeTitle = nameof(FontSizeTitle);
public const string FontSizeTitleIcon = nameof(FontSizeTitleIcon);
//public const string Horizon10 = nameof(Horizon10);
protected void InitResources()
{
Add(FontSizeTitle, StyleDefinition.FontSizeTitle);
Add(FontSizeTitleIcon, StyleDefinition.FontSizeTitleIcon);
//Add(Horizon10, StyleDefinition.Horizon10);
if (App.ExtraResources != null)
{
foreach (var kv in App.ExtraResources)
{
Add(kv.Key, kv.Value);
}
}
Add(TitleLabel, new Style(typeof(Label))
{
Setters =
{
new Setter { Property = View.VerticalOptionsProperty, Value = LayoutOptions.Center },
new Setter { Property = View.HorizontalOptionsProperty, Value = LayoutOptions.Fill },
new Setter { Property = Label.HorizontalTextAlignmentProperty, Value = TextAlignment.Center },
new Setter { Property = Label.FontSizeProperty, Value = StyleDefinition.FontSizeTitle },
new Setter { Property = Label.TextColorProperty, Value = this[MainTextColor] }
}
});
Add(TitleButton, new Style(typeof(Button))
{
Setters =
{
new Setter { Property = Button.BorderWidthProperty, Value = 0.0 },
new Setter { Property = VisualElement.BackgroundColorProperty, Value = Color.Transparent },
new Setter { Property = Button.FontFamilyProperty, Value = this[IconSolidFontFamily] },
new Setter { Property = Button.FontSizeProperty, Value = StyleDefinition.FontSizeTitleIcon },
new Setter { Property = Button.TextColorProperty, Value = this[MainTextColor] }
}
});
}
}
}

View File

@ -1,9 +1,12 @@

using Xamarin.Forms;
namespace Pixiview.Utils
{
public interface IEnvironmentService
{
EnvironmentParameter GetEnvironment();
Theme GetApplicationTheme();
void SetStatusBarColor(Color color);
}
public class EnvironmentParameter
@ -13,4 +16,10 @@ namespace Pixiview.Utils
public string IconSolidFontFamily { get; set; }
public string IconLeft { get; set; }
}
public enum Theme
{
Light,
Dark
}
}

View File

@ -1,4 +1,5 @@
using Xamarin.Forms;
using Pixiview.UI.Theme;
using Xamarin.Forms;
namespace Pixiview.Utils
{
@ -7,9 +8,9 @@ namespace Pixiview.Utils
public static NavigationPage CreateNavigationPage(Page root)
{
var navigation = new NavigationPage(root);
navigation.SetDynamicResource(NavigationPage.BarBackgroundColorProperty, App.MainColor);
navigation.SetDynamicResource(NavigationPage.BarTextColorProperty, App.MainTextColor);
navigation.SetDynamicResource(VisualElement.BackgroundColorProperty, App.WindowColor);
navigation.SetDynamicResource(NavigationPage.BarBackgroundColorProperty, ThemeBase.MainColor);
navigation.SetDynamicResource(NavigationPage.BarTextColorProperty, ThemeBase.MainTextColor);
navigation.SetDynamicResource(VisualElement.BackgroundColorProperty, ThemeBase.WindowColor);
return navigation;
}
}