-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContactsModule.uno
55 lines (43 loc) · 1.24 KB
/
ContactsModule.uno
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
using Fuse;
using Fuse.Scripting;
using Uno;
using Uno.UX;
using Uno.Threading;
[UXGlobalModule]
partial class ContactsModule : NativeModule
{
static bool _inited;
public ContactsModule()
{
if (_inited)
return;
_inited = true;
Resource.SetGlobalKey(this, "FuseJS/Contacts");
AddMember(new NativeFunction("hasPermission", (context, args) => {
if defined(ANDROID)
return HasPermissionJava();
return true;
}));
AddMember(new NativePromise<bool, bool>("requestPermission", RequestPermission, null));
AddMember(new NativeFunction("addContact", (context, args) => {
if (args.Length > 0)
{
var contact = context.Stringify(args[0]);
if defined(ANDROID)
return AddContactJava(contact);
else if defined(IOS)
return AddContactObjC(self, contact);
}
return null;
}));
}
Future<bool> RequestPermission(object[] args)
{
var p = new Promise<bool>();
if defined(ANDROID)
RequestPermissionJava(p);
else
p.Resolve(true);
return p;
}
}