react-native-hyperlink
react-native-hyperlink copied to clipboard
hyperlink on press doesn't work on Android 12 but long press work
Hello,
i'm using react native hyperlink to extract links from text and redirect to links on press using react native Linking.openUrl() it work fine on IOS & old android version but it seems that it is not pressed on Android version 12
this is my code
note that long press is work in all devices also android 12
<HyperLink linkDefault={true} onLongPress={url => { Linking.openURL(url) }} onPress={(url) => { Linking.openURL(url) }} >
@obipawan
Possible solution https://stackoverflow.com/a/70672054/65694
Possible solution https://stackoverflow.com/a/70672054/65694
Works great, Thank you.
Adding this to my AndroidManifest.xml fixed my problem
<manifest ... >
<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>
<application>...</application>
</manifest>
Looking at src/Hyperlink.js, the onPress prop is effectively ignored if the linkDefault prop is truthy
export default class extends Component {
constructor (props) {
super(props)
this.handleLink = this.handleLink.bind(this)
}
handleLink (url) {
const urlObject = mdurl.parse(url)
urlObject.protocol = urlObject.protocol.toLowerCase()
const normalizedURL = mdurl.format(urlObject)
Linking.canOpenURL(normalizedURL)
.then(supported => supported && Linking.openURL(normalizedURL))
}
render () {
const onPress = this.handleLink || this.props.onPress
if (this.props.linkDefault)
return <Hyperlink { ...this.props } onPress={ onPress }/>
return <Hyperlink { ...this.props } />
}
}