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

[expo-notifications] Add preliminary "support" for Web #8853

Merged
merged 17 commits into from Jun 19, 2020

Conversation

sjchmiela
Copy link
Contributor

@sjchmiela sjchmiela commented Jun 17, 2020

Why

Even though we don't support Web in expo-notifications, we don't want to be a pain to the users and throw errors just because of running the code on Web.

How

Added simple object fallbacks for missing modules on web so that they are queryable by

if (!Module.methodAsync) {
  throw new Unavailability…
}

Swapped .ts + .web.ts for .native.ts + .ts (or + .web.ts + .ts where it made sense, eg. if we would need to use localStorage inside the .ts file I renamed it to .web.ts and added an empty fallback in .ts).

Test Plan

  • Ran NCL in bare-expo on Web, clicked buttons around, noticed the error is readable and makes sense.
  • Ran expo-notifications test-suite on both iOS and Web. It seems iOS tests are a little bit flaky, unfortunately (the errors could also happen due to erroring Expo API, HTTP error 504 when fetching push token, but I was able to make all of the tests pass just refreshing).

@github-actions
Copy link
Contributor

Native Component List for this branch is ready

Copy link
Contributor

@esamelson esamelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great! thank you for standardizing this across the whole module 🙏

addListener: () => {
if (!warningHasBeenShown) {
console.warn(
'[expo-notifications] Notifications handling is not yet fully supported on web. Handling notifications will have no effect.'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe just addListener: () => {} for this one? this message seems specific to NotificationsHandlerModule.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the warning message to

[expo-notifications] Listening to push token changes is not yet fully supported on web. Adding a listener will have no effect.

👍 Thank you for noticing this! 👁️

import { NotificationChannelGroupManager } from './NotificationChannelGroupManager.types';

export default {
addListener: () => {},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lately we've been flipping the "web" and native extensions so empty shims like this are the default and things like .native, .web are used when a bundler that supports platform extensions is in use. In the future any other platform someone attempts to use would default to this empty unimplemented module as the default. Related #8502

@sjchmiela sjchmiela force-pushed the @sjchmiela/expo-notifications-web branch from 885daff to 066e841 Compare June 18, 2020 08:36
@esamelson esamelson merged commit db1c413 into master Jun 19, 2020
@esamelson esamelson deleted the @sjchmiela/expo-notifications-web branch June 19, 2020 00:29
tsapeta pushed a commit that referenced this pull request Jun 24, 2020
# Why

Even though we don't support Web in `expo-notifications`, we don't want to be a pain to the users and throw errors just because of running the code on Web.

# How

Added simple object fallbacks for missing modules on web so that they are queryable by
```ts
if (!Module.methodAsync) {
  throw new Unavailability…
}
```

Swapped `.ts` + `.web.ts` for `.native.ts` + `.ts` (or + `.web.ts` + `.ts` where it made sense, eg. if we would need to use `localStorage` inside the `.ts` file I renamed it to `.web.ts` and added an empty fallback in `.ts`).

# Test Plan

- [x] Ran NCL in `bare-expo` on Web, clicked buttons around, noticed the error is readable and makes sense.
- [x] Ran `expo-notifications` test-suite on both iOS and Web. It seems iOS tests are a little bit flaky, unfortunately (the errors could also happen due to erroring Expo API, HTTP error 504 when fetching push token, but I was able to make all of the tests pass just refreshing).
@szaboat
Copy link

szaboat commented Jul 1, 2020

Hi, what are the plans regarding web support for notifications? I haven't found anything on the roadmap on canny.io. Thanks!

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

Successfully merging this pull request may close these issues.

None yet

4 participants