Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
asma-omar opened this issue Feb 13, 2022 · 4 comments
Open

Comments

@asma-omar
Copy link

asma-omar commented Feb 13, 2022

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 asma-omar changed the title hyperlink on press doesn't work on Android 12 hyperlink on press doesn't work on Android 12 but long press work Feb 13, 2022
@Nolascoin
Copy link

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

@umangloria
Copy link

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

Works great, Thank you.

@ugglr
Copy link

ugglr commented Nov 30, 2022

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>

@Charles-Johnson
Copy link

Charles-Johnson commented May 19, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants