/
Elevation.cs
50 lines (41 loc) · 1.06 KB
/
Elevation.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
using Android.Content;
using Xamarin.Forms.PlatformConfiguration.AndroidSpecific;
namespace Xamarin.Forms.Platform.Android
{
public static class ElevationHelper
{
public static void SetElevation(global::Android.Views.View view, VisualElement element)
{
if (view == null || element == null || !Forms.IsLollipopOrNewer)
{
return;
}
var elevation = GetElevation(element, view.Context);
if (!elevation.HasValue)
{
return;
}
view.Elevation = elevation.Value;
}
internal static float? GetElevation(global::Android.Views.View view)
{
if (view == null || !Forms.IsLollipopOrNewer)
{
return null;
}
return view.Elevation;
}
internal static float? GetElevation(VisualElement element, Context context)
{
if (element == null || !Forms.IsLollipopOrNewer)
{
return null;
}
var iec = element as IElementConfiguration<VisualElement>;
var elevation = iec?.On<PlatformConfiguration.Android>().GetElevation();
if (elevation == null)
return elevation;
return context.ToPixels(elevation.Value);
}
}
}