Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ef352b7
Add new package directory for expo SDK
mattmikolay Oct 11, 2024
7f2d7f8
Add tooling config
mattmikolay Oct 11, 2024
8d205bc
Copy KnockExpoPushNotificationProvider to expo package
mattmikolay Oct 11, 2024
8c6313f
Add root index.ts to expo package
mattmikolay Oct 11, 2024
4bbf3dc
Re-export everything from react native package
mattmikolay Oct 11, 2024
4c221de
Remove push code from react native SDK
mattmikolay Oct 11, 2024
6c550a5
Remove peerDependenciesMeta from expo package.json
mattmikolay Oct 11, 2024
1b6575f
Remove expo dependencies from react native sdk
mattmikolay Oct 11, 2024
7a3947b
Remove unnecessary export
mattmikolay Oct 11, 2024
286aaa6
Update sample expo app to use expo sdk
mattmikolay Oct 11, 2024
228290a
Update more sample app imports
mattmikolay Oct 11, 2024
b891b4c
Use a type import in sample app
mattmikolay Oct 11, 2024
badb827
Add expo README
mattmikolay Oct 11, 2024
eef5435
Update rn sdk README
mattmikolay Oct 11, 2024
94952fb
Update rn sdk vite config
mattmikolay Oct 11, 2024
1eef956
Update README
mattmikolay Oct 11, 2024
ec11e9f
Merge branch 'main' into mattmik-kno-6559-react-native-sdk-ensure-exp…
mattmikolay Oct 14, 2024
02bfff7
Update @typescript-eslint/parser
mattmikolay Oct 14, 2024
6adc41d
Update version of expo package
mattmikolay Oct 14, 2024
f8fc1de
Add changeset
mattmikolay Oct 14, 2024
f13bde3
Update Expo README
mattmikolay Oct 14, 2024
69c414d
Update RN SDK README
mattmikolay Oct 14, 2024
a652c6a
Update expo SDK README
mattmikolay Oct 14, 2024
30f6c35
Set @knocklabs/expo version to 0.0.0
mattmikolay Oct 14, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/clean-singers-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@knocklabs/react-native-example": minor
"@knocklabs/react-native": minor
"@knocklabs/expo": minor
---

Move KnockExpoPushNotificationProvider to @knocklabs/expo
2 changes: 1 addition & 1 deletion examples/react-native-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check"
},
"dependencies": {
"@knocklabs/react-native": "workspace:^",
"@knocklabs/expo": "workspace:^",
"expo": ">=51.0.24",
"expo-constants": ">=16.0.2",
"expo-device": ">=6.0.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/react-native-example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
KnockFeedProvider,
KnockProvider,
NotificationIconButton,
} from "@knocklabs/react-native";
} from "@knocklabs/expo";
import { StatusBar } from "expo-status-bar";
import React, { useCallback, useState } from "react";
import { StyleSheet, View } from "react-native";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ActionButton, FeedItem } from "@knocklabs/client";
import { NotificationFeed } from "@knocklabs/react-native";
import type { ActionButton, FeedItem } from "@knocklabs/client";
import { NotificationFeed } from "@knocklabs/expo";
import React, { useCallback } from "react";
import { StyleSheet, Text, TouchableOpacity, View } from "react-native";

Expand Down
11 changes: 11 additions & 0 deletions packages/expo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: [
"@knocklabs/eslint-config/library.js",
"plugin:react-hooks/recommended",
],
parserOptions: {
projects: ["tsconfig.json", "tsconfig.node.json"],
},
};
17 changes: 17 additions & 0 deletions packages/expo/Babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"presets": [
[
"@nx/react/babel",
{
"runtime": "automatic",
"useBuiltIns": "usage"
}
]
],
"plugins": ["module:react-native-dotenv"],
"env": {
"test": {
"presets": ["module:metro-react-native-babel-preset"]
}
}
}
146 changes: 146 additions & 0 deletions packages/expo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# Knock Expo SDK

A set of components for integrating [Knock](https://knock.app) in-app notifications into an Expo + React Native application.

> Not using Expo? See our vanilla [React Native SDK](../react-native/README.md).

## Installation

Via NPM:

```
npm install @knocklabs/expo
```

Via Yarn:

```
yarn add @knocklabs/expo
```

## Migrating from `@knocklabs/react-native`

As of `@knocklabs/react-native` v0.4.0, `KnockExpoPushNotificationProvider` has moved to our Expo SDK. To migrate:

1. Remove `@knocklabs/react-native` from your project

NPM:

```bash
npm uninstall @knocklabs/react-native
```

Yarn:

```bash
yarn remove @knocklabs/react-native
```

1. Install `@knocklabs/expo`

NPM:

```bash
npm install @knocklabs/expo
```

Yarn:

```bash
yarn add @knocklabs/expo
```

1. Update any import statements from `@knocklabs/react-native` to `@knocklabs/expo`

From:

```js
import {
KnockExpoPushNotificationProvider,
KnockFeedProvider,
KnockProvider,
NotificationIconButton,
} from "@knocklabs/react-native";
```

To:

```js
import {
KnockExpoPushNotificationProvider,
KnockFeedProvider,
KnockProvider,
NotificationIconButton,
} from "@knocklabs/expo";
```

## Configuration

To configure the feed you will need:

1. A public API key (found in the Knock dashboard)
1. A user ID, and optionally an auth token for production environments
1. If integrating an in-app feed, a feed channel ID (found in the Knock dashboard)

## Usage

You can integrate the feed into your app as follows:

```jsx
import {
KnockFeedProvider,
KnockProvider,
NotificationFeedContainer,
} from "@knocklabs/expo";

const YourAppLayout = () => {
const [isVisible, setIsVisible] = useState(false);
const notifButtonRef = useRef(null);

return (
<KnockProvider apiKey={process.env.KNOCK_PUBLIC_API_KEY} userId={userId}>
<KnockFeedProvider feedId={process.env.KNOCK_FEED_ID}>
<NotificationFeedContainer>
<Text>Notifications go in here!</Text>
</NotificationFeedContainer>
</KnockFeedProvider>
</KnockProvider>
);
};
```

## Headless usage

Alternatively, if you don't want to use our components you can render the feed in a headless mode using our hooks:

```jsx
import { useAuthenticatedKnockClient, useNotifications } from "@knocklabs/expo";
import create from "zustand";

const YourAppLayout = () => {
const knockClient = useAuthenticatedKnockClient(
process.env.KNOCK_PUBLIC_API_KEY,
currentUser.id,
);

const notificationFeed = useNotifications(
knockClient,
process.env.KNOCK_FEED_ID,
);

const useNotificationStore = create(notificationFeed.store);
const { metadata } = useNotificationStore();

useEffect(() => {
notificationFeed.fetch();
}, [notificationFeed]);

return <Text>Total unread: {metadata.unread_count}</Text>;
};
```

## Related links

- [Signup for Knock](https://knock.app)
- [Knock documentation](https://docs.knock.app)
- [Knock dashboard](https://dashboard.knock.app)
80 changes: 80 additions & 0 deletions packages/expo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
{
"name": "@knocklabs/expo",
"version": "0.0.0",
"author": "@knocklabs",
"license": "MIT",
"main": "dist/cjs/index.js",
"module": "dist/esm/index.mjs",
"types": "dist/types/index.d.ts",
"typings": "dist/types/index.d.ts",
"react-native": "./src/index.ts",
"exports": {
".": {
"require": "./dist/cjs/index.js",
"types": "./dist/types/index.d.ts",
"react-native": "./src/index.ts",
"default": "./dist/esm/index.mjs"
}
},
"files": [
"dist",
"src",
"README.md"
],
"scripts": {
"clean": "rimraf dist",
"dev": "tsc && vite build --watch",
"build": "yarn clean && yarn build:esm && yarn build:cjs",
"build:esm": "BUILD_TARGET=esm; tsc && vite build",
"build:cjs": "BUILD_TARGET=cjs; tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"format": "prettier \"src/**/*.{js,ts,tsx}\" --write",
"format:check": "prettier \"src/**/*.{js,ts,tsx}\" --check",
"type:check": "tsc --noEmit",
"preview": "vite preview"
},
"repository": {
"type": "git",
"url": "git+https://github.com/knocklabs/javascript.git"
},
"bugs": {
"url": "https://github.com/knocklabs/javascript/issues"
},
"peerDependencies": {
"expo": "*",
"expo-constants": "*",
"expo-device": "*",
"expo-notifications": "*",
"react": "*",
"react-native": "*"
},
"dependencies": {
"@knocklabs/client": "workspace:^",
"@knocklabs/react-core": "workspace:^",
"@knocklabs/react-native": "workspace:^",
"react-native-gesture-handler": "^2.19.0",
"react-native-render-html": "^6.3.4",
"react-native-svg": "^15.6.0"
},
"devDependencies": {
"@types/react": "^18.3.6",
"@types/react-native-htmlview": "^0.16.5",
"@typescript-eslint/eslint-plugin": "^6.20.0",
"@typescript-eslint/parser": "^8.8.1",
"@vitejs/plugin-react": "^4.3.2",
"eslint": "^8.56.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.4",
"expo": ">=51.0.24",
"expo-constants": ">=16.0.2",
"expo-device": ">=6.0.2",
"expo-notifications": ">=0.28.16",
"react": "^18.2.0",
"react-native": "^0.73.4",
"rimraf": "^6.0.1",
"typescript": "^5.6.2",
"vite": "^5.0.0",
"vite-plugin-dts": "^3.6.3",
"vite-plugin-no-bundle": "^4.0.0"
}
}
2 changes: 2 additions & 0 deletions packages/expo/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./modules/push";
export * from "@knocklabs/react-native";
5 changes: 5 additions & 0 deletions packages/expo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"extends": "@knocklabs/typescript-config/react-library.json",
"include": ["src"],
"exclude": ["node_modules", "dist"]
}
4 changes: 4 additions & 0 deletions packages/expo/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@knocklabs/typescript-config/node.json",
"include": ["vite.config.ts"]
}
48 changes: 48 additions & 0 deletions packages/expo/vite.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import { LibraryFormats, defineConfig, loadEnv } from "vite";
import dts from "vite-plugin-dts";
import noBundlePlugin from "vite-plugin-no-bundle";

export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), "");
const CJS = env.BUILD_TARGET?.toLocaleLowerCase()?.match("cjs");
const formats: LibraryFormats[] = CJS ? ["cjs"] : ["es"];

return {
plugins: [
dts({
outDir: "dist/types",
}),
react(),
noBundlePlugin({ copy: "**/*.css", root: "./src" }),
],
build: {
outDir: CJS ? "dist/cjs" : "dist/esm",
sourcemap: true,
lib: {
entry: resolve(__dirname, "src/index.ts"),
name: "expo",
formats,
},
rollupOptions: {
// External packages that should not be bundled into your library.
external: [
"react",
"react-native",
"expo",
"expo-constants",
"expo-device",
"expo-notifications",
],
output: {
interop: "compat",
format: formats[0],
globals: {
react: "React",
},
},
},
},
};
});
2 changes: 2 additions & 0 deletions packages/react-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ A set of components for integrating [Knock](https://knock.app) in-app notificati

[Full documentation](https://docs.knock.app/in-app-ui/react-native/overview)

> Using Expo? See our [Expo SDK](../expo/README.md) and our [migration guide](../expo/README.md#migrating-from-knocklabsreact-native).

## Installation

Via NPM:
Expand Down
Loading