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

Link on Android not work #546

Closed
9 of 15 tasks
dkjeune opened this issue Jan 20, 2022 · 11 comments
Closed
9 of 15 tasks

Link on Android not work #546

dkjeune opened this issue Jan 20, 2022 · 11 comments
Labels
bug Crush'em all. is:missing reproduction We require a minimal reproduction to help you out!

Comments

@dkjeune
Copy link

dkjeune commented Jan 20, 2022

Decision Table

  • My issue does not look like “The HTML attribute 'xxx' is ignored” (unless we claim support for it)
  • My issue does not look like “The HTML element <yyy> is not rendered”

Good Faith Declaration

Description

When I click on a link on IOS, it open the browser.
On Android, nothing happen.
Any help ?

React Native Information

No browser open on android

RNRH Version

last version

Tested Platforms

  • Android
  • iOS
  • Web
  • MacOS
  • Windows

Reproduction Platforms

  • Android
  • iOS
  • Web
  • MacOS
  • Windows

Minimal, Reproducible Example

nope

Additional Notes

No response

@dkjeune dkjeune added the bug Crush'em all. label Jan 20, 2022
@jsamr jsamr added the is:missing reproduction We require a minimal reproduction to help you out! label Jan 20, 2022
@jsamr
Copy link
Collaborator

jsamr commented Jan 20, 2022

Thank you @dkjeune for taking time to fill this report. Unfortunately, the report doesn't provide the least minimal reproduction, not even the HTML that would produce the issue you are reporting. I am going to close the issue now as this is not actionable for us, but if a viable reproduction is to be provided, I will reopen.

@jsamr jsamr closed this as completed Jan 20, 2022
@eithe
Copy link

eithe commented Jan 24, 2022

Not that it helps, but I'm getting reports of the same (perhaps only some Android devices?), and I was finally able to reproduce it on a Pixel 2 API 30 emulator running Android 11.

I didn't have time to debug this further, but I have a common component that renders html in the app (that uses react-native-render-html) so what I did as a workaround was just to handle onPress manually like so:

<HTML
  ...
  renderersProps={{
    a: {
      onPress: (_, href) => {
        Linking.openURL(href);
      },
    },
  }}
  source={{ html }}
/>

@jsamr
Copy link
Collaborator

jsamr commented Jan 24, 2022

@eithe Would you mind providing the HTML code, React Native version and RNRH version that triggered this undesired behavior? I tried with the same emulator configuration as you did, and the link press worked (React Native 0.64). My code snippet looked like this:

<a href="https://google.com/">This is a test</a>

@eithe
Copy link

eithe commented Jan 24, 2022

Good point, @jsamr. I must admit I was running RNRH 6.1.0, but I upgraded to 6.3.3 now. RN 0.65.1.

This does not work:
test
This does:
test2

I get that this is quite hard for you to debug, it should be our responsibility to create a minimal example where it fails instead of you having to dig.

Edit: Please ignore the difference on defaultWebViewProps, just something that changed when I removed stuff to simplify the example. Have now tried with no defaultWebViewProps on both tests just to make sure.

@jsamr
Copy link
Collaborator

jsamr commented Jan 24, 2022

Thanks @eithe for providing this additional information. I managed to reproduce the issue by upgrading from RN 0.64 to RN 0.67 on my "sandbox" project that I use for testing! Now I can investigate...

@jsamr jsamr reopened this Jan 24, 2022
@jsamr
Copy link
Collaborator

jsamr commented Jan 24, 2022

I found the issue. Check the implementation of the default A press handler:

export async function defaultAOnPress(_e: any, href: string): Promise<unknown> {
if (await Linking.canOpenURL(href)) {
return Linking.openURL(href);
}
}

For a reason yet to determine, await Linking.canOpenURL(href) ceased returning true for HTTP(S) URIs on Android. This is obviously a bug on React Native side, but I will have to take it into account and provide a fix.

@eithe
Copy link

eithe commented Jan 24, 2022

Nice find, @jsamr! Thanks for investigating and thanks again for your efforts on this project, greatly appreciated.

@jsamr
Copy link
Collaborator

jsamr commented Jan 24, 2022

I've opened a ticket on React Native issue tracker facebook/react-native#32960

@jsamr jsamr closed this as completed in 1a429f4 Jan 24, 2022
@jsamr
Copy link
Collaborator

jsamr commented Jan 24, 2022

@jsamr
Copy link
Collaborator

jsamr commented Jan 24, 2022

@eithe Thanks for the sponsor and kind feedback, it always lifts one's spirit!

@iphonic
Copy link

iphonic commented May 13, 2022

@jsamr How do you access this.state inside onPress?

const renderersProps = {
    a: {
      onPress(event, url, htmlAttribs, target) {
        if (url.includes('tc')) {
            this.setState({showTerms:true,showPrivacy:false})
        }else if (url.includes('pv')) {
            this.setState({showTerms:false,showPrivacy:true})
        }
      }
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Crush'em all. is:missing reproduction We require a minimal reproduction to help you out!
Projects
None yet
Development

No branches or pull requests

4 participants