react-native-hyperlink icon indicating copy to clipboard operation
react-native-hyperlink copied to clipboard

hyperlink on press doesn't work on Android 12 but long press work

Open asma-omar opened this issue 3 years ago • 4 comments

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

asma-omar avatar Feb 13 '22 15:02 asma-omar

Possible solution https://stackoverflow.com/a/70672054/65694

Nolascoin avatar Mar 21 '22 21:03 Nolascoin

Possible solution https://stackoverflow.com/a/70672054/65694

Works great, Thank you.

umangloria avatar Oct 13 '22 05:10 umangloria

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>

ugglr avatar Nov 30 '22 03:11 ugglr

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 } />
  }
}

Charles-Johnson avatar May 19 '23 03:05 Charles-Johnson