forked from necolas/react-native-web
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (50 loc) · 1.26 KB
/
index.js
File metadata and controls
56 lines (50 loc) · 1.26 KB
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
import { Linking, StyleSheet, Text } from 'react-native';
import React from 'react';
import Example from '../../shared/example';
const url = 'https://mathiasbynens.github.io/rel-noopener/malicious.html';
export default function LinkingPage(props) {
const [, setCount] = React.useState(0);
React.useEffect(() => {
console.log('adding listener');
const listener = Linking.addEventListener('onOpen', () => {
console.log('onOpen event');
});
return () => {
console.log('removing listener');
listener.remove();
};
});
function handlePress() {
Linking.canOpenURL(url).then((supported) => {
setCount((x) => x + 1);
const v = Linking.openURL(url);
return v;
});
}
return (
<Example title="Linking">
<Text onPress={handlePress} style={styles.text}>
Linking.openURL
</Text>
<Text
href="https://mathiasbynens.github.io/rel-noopener/malicious.html"
hrefAttrs={{
target: '_blank'
}}
role="link"
style={styles.text}
>
target="_blank"
</Text>
</Example>
);
}
const styles = StyleSheet.create({
text: {
borderRadius: 5,
borderStyle: 'solid',
borderWidth: 1,
marginVertical: 10,
padding: 10
}
});