-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAppClip.tsx
65 lines (60 loc) · 1.53 KB
/
AppClip.tsx
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
import {NativeEventEmitter, NativeModules, Text, View} from 'react-native';
import React, {useEffect, useState} from 'react';
const AppClip = () => {
const {AppClipLinkingManager} = NativeModules;
// eslint-disable-next-line react-hooks/exhaustive-deps
const eventEmitter = new NativeEventEmitter(AppClipLinkingManager);
const [link, setLink] = useState('');
useEffect(() => {
const asyncEffect = async () => {
const initialLink = (await AppClipLinkingManager.getInitialLink()) || '';
setLink(initialLink);
};
void asyncEffect();
}, [AppClipLinkingManager]);
useEffect(() => {
const subscription = eventEmitter.addListener('onNewUrl', event => {
if (event && event.url) {
console.log('[LOG] link from event: ', event.url);
setLink(event.url);
}
});
return () => {
subscription.remove();
};
}, [eventEmitter]);
return (
<View
style={{
justifyContent: 'center',
alignItems: 'center',
marginTop: 50,
}}>
<Text
style={{
fontSize: 40,
margin: 10,
textAlign: 'center',
}}>
Hello,
</Text>
<Text
style={{
fontSize: 20,
margin: 10,
textAlign: 'center',
}}>
I'm your AppClip!
</Text>
<Text
style={{
textAlign: 'center',
margin: 14,
fontSize: 20,
}}>
{`Current invocation URL is: \n ${link}`}
</Text>
</View>
);
};
export default AppClip;