/* @flow strict-local */
import { NativeModules, Platform } from 'react-native';
import SafariView from 'react-native-safari-view';

export default (url: string): void => {
  if (Platform.OS === 'ios') {
    SafariView.show({ url });
  } else {
    NativeModules.CustomTabsAndroid.openURL(url);
  }
};

/* @flow strict-local */
import { NativeModules, Platform } from 'react-native';
import SafariView from 'react-native-safari-view';

export default (url: string): void => {
  if (Platform.OS === 'ios') {
    SafariView.show({ url: encodeURI(url) });
  } else {
    NativeModules.CustomTabsAndroid.openURL(url);
  }
};

Fix crash on following a link with non-ASCII characters.
iOS: Fix crash on following a link with non-ASCII characters.

The `SafariView` library apparently crashes when passed a `url`
parameter that isn't all ASCII.  Strictly such a thing isn't
a URL (or URI), in fact, but rather an "IRI":
  https://en.wikipedia.org/wiki/Internationalized_Resource_Identifier

Fix the issue by encoding the IRI in ASCII as a proper URI/URL.
The standard JS function `encodeURI` does the job.

Fixes: #3315

[greg: expanded commit message]
