You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(react-native-example): wire Knock SDK and align screens with Android/iOS demos
Adds @knocklabs/react-native as a workspace dependency along with the required peer (react-native-gesture-handler). Wraps the authed stack in KnockProvider + KnockPushNotificationProvider + KnockFeedProvider, gated by a small AuthContext that lifts user identity and tenant scope to the app root. Pre-auth screens (Startup, SignIn) live in a separate stack so the navigator structure makes the auth boundary obvious.
Realigns each screen against the Android (knocklabs/knock-android/knock-example-app) and iOS (knocklabs/ios-example-app) demos for parity:
- Config exports six flat KNOCK_* constants matching Android's Utils.kt shape, plus KNOCK_TENANT_A and KNOCK_TENANT_B for the iOS-style tenant switcher.
- Main embeds the prebuilt <NotificationFeed /> component so the in-app feed renders in real time.
- Compose shows the workflow trigger form and clears the field on send. The server-side trigger pattern is documented inline; clients can't trigger workflows directly because that requires the secret API key.
- Preferences uses usePreferences for live read/write of channel-type preferences and hosts the sign-out action.
- TenantSwitcher offers None / Tenant A / Tenant B; selecting one updates auth state and re-mounts KnockFeedProvider with the new tenant scope.
Knock packages must be built once (`yarn build:packages`) before type-checking or bundling, since the SDK exposes types from dist/.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Demonstrates [`@knocklabs/react-native`](../../packages/react-native) in a bare React Native app. For an Expo-managed example, see [`expo-example`](../expo-example).
3
+
Demonstrates [`@knocklabs/react-native`](../../packages/react-native) in a bare React Native app. Mirrors the structure of the [Android](https://github.com/knocklabs/knock-android/tree/main/knock-example-app) and [iOS](https://github.com/knocklabs/ios-example-app) demos. For an Expo-managed example, see [`expo-example`](../expo-example).
4
+
5
+
## What this demo shows
6
+
7
+
Six screens, each demonstrating one piece of the SDK:
8
+
9
+
-**Startup** — splash before sign-in
10
+
-**Sign in** — identifies the user with `KnockProvider`
11
+
-**Main** — the in-app feed via the prebuilt `<NotificationFeed />` component
12
+
-**Compose message** — the shape of a workflow trigger payload
13
+
-**Preferences** — read and write the user's channel-type preferences via `usePreferences`
14
+
-**Switch tenant** — scope the feed and preferences to a tenant
4
15
5
16
## Running locally
6
17
7
18
1. Install dependencies from the root of the monorepo.
8
19
9
-
```sh
10
-
yarn
11
-
```
20
+
```sh
21
+
yarn
22
+
```
12
23
13
24
2. Build the Knock packages.
14
25
15
-
```sh
16
-
yarn build:packages
17
-
```
26
+
```sh
27
+
yarn build:packages
28
+
```
18
29
19
-
3. Configure the app. Open [`src/config.ts`](./src/config.ts) and replace the placeholder values with your Knock public API key, a test user ID, and your in-app feed channel ID.
30
+
3. Configure the app. Open [`src/config.ts`](./src/config.ts) and replace the `KNOCK_*` placeholders with values from your [Knock dashboard](https://dashboard.knock.app).
20
31
21
32
4. Set up your React Native development environment. See the [React Native environment setup guide](https://reactnative.dev/docs/set-up-your-environment).
22
33
23
34
5. For iOS, install the CocoaPods dependencies once.
24
35
25
-
```sh
26
-
cd ios && bundle install && bundle exec pod install &&cd ..
27
-
```
36
+
```sh
37
+
cd ios && bundle install && bundle exec pod install &&cd ..
38
+
```
28
39
29
40
6. Start Metro and launch on a simulator or device.
30
41
31
-
```sh
32
-
yarn start
42
+
```sh
43
+
yarn start
33
44
34
-
# In another terminal:
35
-
yarn ios
36
-
# or
37
-
yarn android
38
-
```
45
+
# In another terminal:
46
+
yarn ios
47
+
# or
48
+
yarn android
49
+
```
39
50
40
51
## Configuration
41
52
42
-
All runtime configuration lives in [`src/config.ts`](./src/config.ts). It's a single exported object with a `publicApiKey`, `userId`, optional `tenantId`, and `feedChannelId`. Values come from the [Knock dashboard](https://dashboard.knock.app).
53
+
All runtime configuration lives as flat constants in [`src/config.ts`](./src/config.ts):
54
+
55
+
| Constant | What it is |
56
+
| --- | --- |
57
+
|`KNOCK_API_KEY`| Public API key. Dashboard → Developers → API keys. |
58
+
|`KNOCK_USER_ID`| A test user's ID. Comes from your auth system in production. |
|`KNOCK_HOSTNAME`| Override for self-hosted or sandbox Knock. |
62
+
|`KNOCK_TENANT_A`, `KNOCK_TENANT_B`| Tenant IDs used by the tenant switcher. |
63
+
64
+
## Workflow triggers
65
+
66
+
The Compose screen shows the *shape* of a workflow trigger payload but does not call Knock directly. Triggers require your secret API key, which must not live in a mobile app — POST the payload to a trusted backend that calls `knock.workflows.trigger` on your behalf.
67
+
68
+
## Push notifications
43
69
44
-
In a production app these would come from your backend (for `userId`) and your environment (for the channel and tenant IDs). For this example they're hardcoded so you can get running quickly.
70
+
The app wires `KnockPushNotificationProvider` so the SDK is ready to register device tokens, but the device-token registration code itself is not in this example. APNs and FCM setup require account-level configuration (certificates, Firebase project) that's out of scope here.
0 commit comments