-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathMvxLayoutInflaterCompat.cs
65 lines (56 loc) · 2.09 KB
/
MvxLayoutInflaterCompat.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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MS-PL license.
// See the LICENSE file in the project root for more information.
using System;
using Android.Content;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Object = Java.Lang.Object;
namespace MvvmCross.Platforms.Android.Binding.Binders
{
#nullable enable
public static class MvxLayoutInflaterCompat
{
internal class FactoryWrapper : Object, LayoutInflater.IFactory
{
protected readonly IMvxLayoutInflaterFactory DelegateFactory;
[Preserve(Conditional = true)]
#pragma warning disable 8618
public FactoryWrapper(IntPtr handle, JniHandleOwnership ownership)
#pragma warning restore 8618
: base(handle, ownership)
{
}
public FactoryWrapper(IMvxLayoutInflaterFactory delegateFactory)
{
DelegateFactory = delegateFactory;
}
public View? OnCreateView(string name, Context context, IAttributeSet attrs)
{
return DelegateFactory.OnCreateView(null, name, context, attrs);
}
}
internal class FactoryWrapper2 : FactoryWrapper, LayoutInflater.IFactory2
{
[Preserve(Conditional = true)]
public FactoryWrapper2(IntPtr handle, JniHandleOwnership ownership)
: base(handle, ownership)
{
}
public FactoryWrapper2(IMvxLayoutInflaterFactory delegateFactory)
: base(delegateFactory)
{
}
public View? OnCreateView(View? parent, string name, Context context, IAttributeSet attrs)
{
return DelegateFactory.OnCreateView(parent, name, context, attrs);
}
}
public static void SetFactory(LayoutInflater layoutInflater, IMvxLayoutInflaterFactory? factory)
{
layoutInflater.Factory2 = factory != null ? new FactoryWrapper2(factory) : null;
}
}
#nullable restore
}