EvanBacon / expo-quick-actions

Add home screen quick actions / shortcuts to your React Native app
MIT License
267 stars 6 forks source link

It is not clear what `params` does, or how to access to it #19

Open BrodaNoel opened 1 month ago

BrodaNoel commented 1 month ago

I don't use React Router, and I'm trying to use the params in order to show a modal.

But the url in Linking.getInitialURL is always null

const url = await Linking.getInitialURL();
checkUrl(url);

// ...

  const checkUrl = url => {
    try {
      if (!url) {
        return;
      }

      const { hostname, queryParams } = Linking.parse(url);

      if (queryParams && queryParams.href && queryParams.href.includes('about-to-remove')) {
        Alert.alert(
          i18n.t('Tell me what happened'),
          i18n.t('Send me an email to my personal account, and tell me what I can improve') +
            ': brodanoel@gmail.com',
          [
            {
              text: i18n.t('No'),
              onPress: () => {},
              style: 'cancel',
            },
            {
              text: i18n.t('Ok, sure'),
              onPress: () => {
                Linking.openURL('mailto:brodanoel@gmail.com?subject=NoFilter feedback');
              },
            },
          ],
          { cancelable: false }
        );
      }
    } catch (error) {
      Sentry.captureException(error);
    }
  };

I was expecting to access to params in hostname or queryParams, but nop... URL is always null (at least, in development build)

EvanBacon commented 1 month ago

Consider looking over how the Expo Router code works to better understand the params functionality https://github.com/EvanBacon/expo-quick-actions/blob/202b148a76c96b20292c3fc6ef7dde1bc7e6b655/src/router.ts#L28

Unlike Expo Router, standard native apps don't enforce that a URL be present at all times. This means you may need to add some state to account for the edge cases where the app was not launched from a URL.

BrodaNoel commented 1 month ago

@EvanBacon so, let me check if I understand it: you are telling me that when the app is launched from the Actions, it is not consider "from an URL", thus, I have to handle this other case.

Is there a name for this "other case"? So I can look for some documentation.