react-native-simple-auth icon indicating copy to clipboard operation
react-native-simple-auth copied to clipboard

Upon launching the app, a web page in mobile Safari opens firs

Open bashen1 opened this issue 6 years ago • 5 comments

We noticed an issue in your app that contributes to a lower quality user experience than Apple users expect:

 - Upon launching the app, a web page in mobile Safari opens first, then returns to the app. The user should be able to use the app immediately upon launch.

Next Steps

To resolve this issue, please revise your app to address all instances of this type of issue.

bashen1 avatar May 16 '18 00:05 bashen1

已经用react-native-safari-view配合解决 react-native.js

import {
  Linking,
  Platform
} from 'react-native'; // eslint-disable-line import/no-unresolved, max-len
import SafariView from 'react-native-safari-view';

let previousOnLinkChange;

export const dance = (authUrl) => {
  // Use SafariView on iOS
  if (Platform.OS === 'ios') {
    if (previousOnLinkChange) {
      Linking.removeEventListener('url', previousOnLinkChange);
    }
    return SafariView.show({
      url: authUrl,
      readerMode: false,
      fromBottom: true,
      tintColor: '#000',
      barTintColor: '#fff'
    }).then(() => new Promise((resolve, reject) => {
      const handleUrl = (url) => {
        if (!url || url.indexOf('fail') > -1) {
          reject(url);
        } else {
          resolve(url);
        }
        SafariView.dismiss();
      };

      const onLinkChange = ({url}) => {
        Linking.removeEventListener('url', onLinkChange);
        previousOnLinkChange = undefined;
        handleUrl(url);
      };

      Linking.addEventListener('url', onLinkChange);

      previousOnLinkChange = onLinkChange;
    }));
  }
  // Or Linking.openURL on Android
  else {
    if (previousOnLinkChange) {
      Linking.removeEventListener('url', previousOnLinkChange);
    }
    return Linking.openURL(authUrl)
      .then(() => new Promise((resolve, reject) => {
        const handleUrl = (url) => {
          if (!url || url.indexOf('fail') > -1) {
            reject(url);
          } else {
            resolve(url);
          }
        };

        const onLinkChange = ({url}) => {
          Linking.removeEventListener('url', onLinkChange);
          previousOnLinkChange = undefined;
          handleUrl(url);
        };

        Linking.addEventListener('url', onLinkChange);

        previousOnLinkChange = onLinkChange;
      }));
  }
};

export const request = fetch;

bashen1 avatar May 17 '18 13:05 bashen1

@bashen1 same message came for me also. did the above solution worked for you ?

ayushnawani avatar May 18 '18 05:05 ayushnawani

@ayushnawani Yes

bashen1 avatar May 19 '18 05:05 bashen1

@bashen1 you should create one pull request so it can be merged. @adamjmcgrath is it possible?

ayushnawani avatar May 25 '18 08:05 ayushnawani

Sure, happy to look at a PR. Although see my comment https://github.com/adamjmcgrath/react-native-simple-auth/pull/86#issuecomment-352185403 about including react-native-safari-view

adamjmcgrath avatar May 27 '18 08:05 adamjmcgrath