mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-10 21:12:08 +00:00
84723245ce
Linking.removeEventListener() was deprecated in react-native@0.65 Fix #2507
57 lines
1.3 KiB
JavaScript
57 lines
1.3 KiB
JavaScript
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
|
|
}
|
|
});
|