Pixiview/Pixiview/UI/StyleDefinition.cs

117 lines
4.6 KiB
C#

using System;
using Xamarin.Essentials;
using Xamarin.Forms;
namespace Pixiview.UI
{
public static class StyleDefinition
{
public const double FontSizeTitle = 18.0;
public const double FontSizeTitleIcon = 24.0;
public static readonly Thickness ScreenBottomPadding;
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 static readonly Color ColorLightShadow = Color.FromRgba(0, 0, 0, 0x20);
public static readonly Color ColorDeepShadow = Color.FromRgba(0, 0, 0, 0x50);
public static readonly Color ColorRedBackground = Color.FromRgb(0xfd, 0x43, 0x63);
public static readonly double FontSizeMicro = Device.GetNamedSize(NamedSize.Micro, typeof(Label));
public static readonly double FontSizeSmall = Device.GetNamedSize(NamedSize.Small, typeof(Label));
public const string IconUser = "\uf007";
public const string IconSparkles = "\uf890";
public const string IconOrder = "\uf88f";
public const string IconLayer = "\uf302";
public const string IconRefresh = "\uf2f1";
public const string IconLove = "\uf004";
public const string IconOption = "\uf013";
public const string IconDownload = "\uf019";
public const string IconFavorite = "\uf02e";
static StyleDefinition()
{
if (IsFullscreenDevice)
{
if (DeviceInfo.Idiom == DeviceIdiom.Phone)
{
ScreenBottomPadding = new Thickness(0, 0, 0, 26);
}
else
{
ScreenBottomPadding = new Thickness(0, 0, 0, 16);
}
}
}
private static bool? _isFullscreenDevice;
public static bool IsFullscreenDevice
{
get
{
if (_isFullscreenDevice != null)
{
return _isFullscreenDevice.Value;
}
if (Device.RuntimePlatform == Device.iOS)
{
try
{
var model = DeviceInfo.Model;
if (model == "iPhone10,3")
{
// iPhone X
_isFullscreenDevice = true;
}
else if (model.StartsWith("iPhone"))
{
var vs = model.Substring(6).Split(',');
if (vs.Length == 2 && int.TryParse(vs[0], out int main) && int.TryParse(vs[1], out int sub))
{
// iPhone X/XS/XR or iPhone 11
_isFullscreenDevice = (main == 10 && sub >= 6) || (main > 10);
}
else
{
_isFullscreenDevice = false;
}
}
else if (model.StartsWith("iPad8,"))
{
// iPad 11-inch or 12.9-inch (3rd+)
_isFullscreenDevice = true;
}
#if DEBUG
else
{
// iPad or Simulator
var name = DeviceInfo.Name;
_isFullscreenDevice = name.StartsWith("iPhone X")
|| name.StartsWith("iPhone 11")
|| name.StartsWith("iPad Pro (11-inch)")
|| name.StartsWith("iPad Pro (12.9-inch) (3rd generation)")
|| name.StartsWith("iPad Pro (12.9-inch) (4th generation)");
}
#endif
}
catch (Exception ex)
{
App.DebugError("device.get", $"failed to get the device model. {ex.Message}");
}
}
else
{
// TODO:
_isFullscreenDevice = false;
}
if (_isFullscreenDevice == null)
{
_isFullscreenDevice = false;
}
return _isFullscreenDevice.Value;
}
}
}
}