This repository was archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathNoDualScreenServiceImpl.shared.cs
75 lines (59 loc) · 2.01 KB
/
NoDualScreenServiceImpl.shared.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
67
68
69
70
71
72
73
74
75
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms.Internals;
namespace Xamarin.Forms.DualScreen
{
internal class NoDualScreenServiceImpl : IDualScreenService
{
static Lazy<NoDualScreenServiceImpl> _Instance = new Lazy<NoDualScreenServiceImpl>(() => new NoDualScreenServiceImpl());
public static NoDualScreenServiceImpl Instance => _Instance.Value;
readonly WeakEventManager _onScreenChangedEventManager = new WeakEventManager();
public NoDualScreenServiceImpl()
{
Device.info.PropertyChanged += OnDeviceInfoChanged;
}
public Task<int> GetHingeAngleAsync() => Task.FromResult(0);
public bool IsSpanned => false;
public bool IsLandscape => Device.info.CurrentOrientation.IsLandscape();
public DeviceInfo DeviceInfo => Device.info;
public event EventHandler OnScreenChanged
{
add { _onScreenChangedEventManager.AddEventHandler(value); }
remove { _onScreenChangedEventManager.RemoveEventHandler(value); }
}
public void Dispose()
{
}
public Size ScaledScreenSize => Device.info.ScaledScreenSize;
public Rectangle GetHinge()
{
return Rectangle.Zero;
}
public Point? GetLocationOnScreen(VisualElement visualElement)
{
return null;
}
public object WatchForChangesOnLayout(VisualElement visualElement, Action action)
{
if (action == null)
return null;
EventHandler<EventArg<VisualElement>> layoutUpdated = (_, __) =>
{
action();
};
visualElement.BatchCommitted += layoutUpdated;
return layoutUpdated;
}
public void StopWatchingForChangesOnLayout(VisualElement visualElement, object handle)
{
if (handle is EventHandler<EventArg<VisualElement>> handler)
visualElement.BatchCommitted -= handler;
}
void OnDeviceInfoChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
_onScreenChangedEventManager.HandleEvent(this, e, nameof(OnScreenChanged));
}
}
}