Skip to content

Commit

Permalink
[expo-notifications] Device push token fetching module (#6577)
Browse files Browse the repository at this point in the history
# Why

To eventually deprecate ExpoKit.

# How

- created a new unimodule, disabling autolinking in the root projects
- implemented `getDevicePushTokenAsync` method in TS, then in native (on iOS we rely on system framework, on Android we're using Firebase Cloud Messaging)
- implemented listening to token changes

### Notable changes to TS implementation

- I had to juggle around types a bit to achieve what I wanted — for TS to discriminate by `type: keyof Platform.OS` value what is the type of `data` field and at the same time to use `data: any` for unsupported platforms. Types are ready, but I needed to use [`@ts-ignore`](0bd4687#diff-66b6995155cd1e190f53b012f5c2a857R43-R44) to get away with it.

### Notable changes to native implementation

- we use singleton module for listening to token changes [android](69ee9ef#diff-5f9ef5ef7358f7a9c8cc386d42ee934f), [ios](0aa2b66#diff-f8332f28b28ad9a24e0af0cb435876c7)
- on Android there's a service subclassing `FirebaseMessagingService` to which the singleton above subscribes [link](69ee9ef#diff-b6817886a179022070e2417712503fa9)

### Notable changes to web implementation

- eventually, I guess, developers would want to customize how their app responds to notifications — for this I added a `serviceWorkerPath` manifest field [commit](82e54ae)

# Test Plan

- tests in `test-suite` are passing on **all three platforms** (on web puppeteer has to be run in head…ful (?) mode, otherwise overriding permissions doesn't work, which is a [known issue](puppeteer/puppeteer#3279))
- push notifications sent to device push tokens are received on **all three platforms**
  • Loading branch information
sjchmiela committed Jan 14, 2020
1 parent 470c2db commit cee2253
Show file tree
Hide file tree
Showing 81 changed files with 3,070 additions and 1,114 deletions.
1 change: 1 addition & 0 deletions android/app/build.gradle
Expand Up @@ -236,6 +236,7 @@ dependencies {
'expo-module-template',
'expo-bluetooth',
'expo-in-app-purchases',
'expo-notifications',
'expo-payments-stripe',
'expo-updates'
]
Expand Down
1 change: 1 addition & 0 deletions android/expoview/build.gradle
Expand Up @@ -170,6 +170,7 @@ dependencies {
exclude : [
'expo-module-template',
'expo-bluetooth',
'expo-notifications',
'expo-in-app-purchases',
'expo-updates',
]
Expand Down
1 change: 1 addition & 0 deletions android/settings.gradle
Expand Up @@ -33,6 +33,7 @@ includeUnimodulesProjects(
// FLAG_BEGIN_REMOVE__UPDATE_EXPOKIT - used during `et android-build-packages`
// section below previous line comment flag contains modules that need to be built for `expokit-npm-package`
'expo-bluetooth',
'expo-notifications',
'expo-in-app-purchases',
'expo-updates',
// FLAG_END_REMOVE__UPDATE_EXPOKIT
Expand Down
Expand Up @@ -39,6 +39,7 @@ public List<Package> getPackageList() {
new expo.modules.mailcomposer.MailComposerPackage(),
new expo.modules.medialibrary.MediaLibraryPackage(),
new expo.modules.network.NetworkPackage(),
new expo.modules.notifications.NotificationsPackage(),
new expo.modules.permissions.PermissionsPackage(),
new expo.modules.print.PrintPackage(),
new expo.modules.random.RandomPackage(),
Expand Down
4 changes: 4 additions & 0 deletions apps/bare-expo/app.json
Expand Up @@ -15,6 +15,10 @@
"include": ["test-suite", "bare-expo"]
}
}
},
"notification": {
"serviceWorkerPath": "/expo-service-worker.js",
"vapidPublicKey": "BNHvR05XkY5LH9GdN0GreLx2wZnK9IwNJGVmo3jujIkFni4of26E3U3fnt9nUrZfM7h0omdIHKM0eshkzTSFOWQ"
}
}
}
12 changes: 10 additions & 2 deletions apps/bare-expo/e2e/TestSuite-test.web.js
@@ -1,4 +1,4 @@
/* global page */
/* global page, browser */
import { setDefaultOptions } from 'expect-puppeteer';

import config from '../jest-puppeteer.config';
Expand All @@ -19,9 +19,12 @@ const TESTS = [
'Blur',
'LinearGradient',
'KeepAwake',
// Overridding permissions doesn't work in headless mode
// see https://github.com/puppeteer/puppeteer/issues/3279
!config.launch.headless && 'expo-notifications',
// 'Haptics',
// 'SecureStore',
];
].filter(t => t);

// This is how long we allocate for the actual tests to be run after the test screen has mounted.
const MIN_TIME = 50000;
Expand All @@ -31,6 +34,11 @@ setDefaultOptions({
timeout: MIN_TIME * 1.5,
});

beforeAll(async () => {
const context = browser.defaultBrowserContext();
await context.overridePermissions(config.url, ['notifications']);
});

function matchID(id, ...props) {
return expect(page).toMatchElement(`div[data-testid="${id}"]`, ...props);
}
Expand Down
4 changes: 4 additions & 0 deletions apps/bare-expo/ios/BareExpo.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions apps/bare-expo/ios/BareExpo/Bare Expo.entitlements
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>aps-environment</key>
<string>development</string>
</dict>
</plist>
7 changes: 7 additions & 0 deletions apps/bare-expo/ios/Podfile.lock
Expand Up @@ -102,6 +102,8 @@ PODS:
- UMPermissionsInterface
- EXNetwork (2.0.0):
- UMCore
- EXNotifications (1.0.0):
- UMCore
- EXPermissions (8.0.0):
- UMCore
- UMPermissionsInterface
Expand Down Expand Up @@ -426,6 +428,7 @@ DEPENDENCIES:
- EXMailComposer (from `../../../packages/expo-mail-composer/ios`)
- EXMediaLibrary (from `../../../packages/expo-media-library/ios`)
- EXNetwork (from `../../../packages/expo-network/ios`)
- EXNotifications (from `../../../packages/expo-notifications/ios`)
- EXPermissions (from `../../../packages/expo-permissions/ios`)
- EXPrint (from `../../../packages/expo-print/ios`)
- EXRandom (from `../../../packages/expo-random/ios`)
Expand Down Expand Up @@ -593,6 +596,9 @@ EXTERNAL SOURCES:
EXNetwork:
:path: !ruby/object:Pathname
path: "../../../packages/expo-network/ios"
EXNotifications:
:path: !ruby/object:Pathname
path: "../../../packages/expo-notifications/ios"
EXPermissions:
:path: !ruby/object:Pathname
path: "../../../packages/expo-permissions/ios"
Expand Down Expand Up @@ -756,6 +762,7 @@ SPEC CHECKSUMS:
EXMailComposer: b9be58adaabb860fc8b722204ce27b33c7da5aad
EXMediaLibrary: 9281707de8f95cc391d242b614f493ab781030fa
EXNetwork: a52f713ced4b05a2634eb88a1f1f8678fcb8b69c
EXNotifications: d654494e84df90927cca410ebac178c61553647b
EXPermissions: 9bc08859a675d291e89be9a0870155c27c16ac35
EXPrint: b20aef0e774d96e0ea6688b97d9e0c1d268b95ae
EXRandom: 3a6f6dce1997a40a7fc3bb00d18eabc380c51c2e
Expand Down
21 changes: 17 additions & 4 deletions apps/bare-expo/ios/Pods/.project_cache/installation_cache.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions apps/bare-expo/ios/Pods/.project_cache/metadata_cache.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cee2253

Please sign in to comment.