/
Forms.cs
66 lines (53 loc) · 1.65 KB
/
Forms.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Platform.GTK;
namespace Xamarin.Forms
{
public static class Forms
{
internal static string BarTextColor = "Xamarin.BarTextColor";
internal static string BarBackgroundColor = "Xamarin.BarBackgroundColor";
const string LogFormat = "[{0}] {1}";
public static bool IsInitialized { get; private set; }
static bool FlagsSet { get; set; }
static IReadOnlyList<string> s_flags;
public static IReadOnlyList<string> Flags => s_flags ?? (s_flags = new List<string>().AsReadOnly());
public static void Init(IEnumerable<Assembly> rendererAssemblies = null)
{
if (IsInitialized)
return;
Log.Listeners.Add(new DelegateLogListener((c, m) => Debug.WriteLine(LogFormat, c, m)));
Registrar.ExtraAssemblies = rendererAssemblies?.ToArray();
Device.SetIdiom(TargetIdiom.Desktop);
Device.SetFlags(s_flags);
Device.PlatformServices = new GtkPlatformServices();
Device.Info = new GtkDeviceInfo();
Color.SetAccent(Color.FromHex("#3498DB"));
ExpressionSearch.Default = new GtkExpressionSearch();
Registrar.RegisterAll(new[]
{
typeof(ExportCellAttribute),
typeof(ExportImageSourceHandlerAttribute),
typeof(ExportRendererAttribute)
});
IsInitialized = true;
}
public static void SetFlags(params string[] flags)
{
if (FlagsSet)
{
return;
}
if (IsInitialized)
{
throw new InvalidOperationException($"{nameof(SetFlags)} must be called before {nameof(Init)}");
}
s_flags = flags.ToList().AsReadOnly();
FlagsSet = true;
}
}
}