jazz-react-native 0.8.8 β 0.8.12
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +18 -0
- package/README.md +229 -6
- package/package.json +4 -4
- package/.turbo/turbo-build.log +0 -8
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# jazz-browser
|
2
2
|
|
3
|
+
## 0.8.12
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- Updated dependencies [6ed75eb]
|
8
|
+
- cojson@0.8.12
|
9
|
+
- cojson-transport-ws@0.8.12
|
10
|
+
- jazz-tools@0.8.12
|
11
|
+
|
12
|
+
## 0.8.11
|
13
|
+
|
14
|
+
### Patch Changes
|
15
|
+
|
16
|
+
- Updated dependencies [1ed4ab5]
|
17
|
+
- cojson@0.8.11
|
18
|
+
- cojson-transport-ws@0.8.11
|
19
|
+
- jazz-tools@0.8.11
|
20
|
+
|
3
21
|
## 0.8.8
|
4
22
|
|
5
23
|
### Patch Changes
|
package/README.md
CHANGED
@@ -1,10 +1,233 @@
|
|
1
|
-
#
|
1
|
+
# π· Jazz + React Native
|
2
2
|
|
3
|
-
|
3
|
+
Jazz requires an [Expo development build](https://docs.expo.dev/develop/development-builds/introduction/) using [Expo Prebuild](https://docs.expo.dev/workflow/prebuild/) for native code. It is **not compatible** with Expo Go. Jazz also supports the [New Architecture](https://docs.expo.dev/guides/new-architecture/).
|
4
4
|
|
5
|
-
|
6
|
-
or to build your framework bindings for Jazz.
|
5
|
+
Tested with:
|
7
6
|
|
8
|
-
|
7
|
+
```json
|
8
|
+
"expo": "~51.0.0",
|
9
|
+
"react-native": "~0.74.5",
|
10
|
+
"react": "^18.2.0",
|
11
|
+
```
|
9
12
|
|
10
|
-
|
13
|
+
## π Setup
|
14
|
+
|
15
|
+
### Create a New Project
|
16
|
+
|
17
|
+
(skip this step if you already have one)
|
18
|
+
|
19
|
+
```bash
|
20
|
+
npx create-expo-app -e with-router-tailwind my-jazz-app
|
21
|
+
cd my-jazz-app
|
22
|
+
npx expo prebuild
|
23
|
+
```
|
24
|
+
|
25
|
+
### Install dependencies
|
26
|
+
|
27
|
+
```bash
|
28
|
+
npx expo install expo-linking expo-secure-store expo-file-system @react-native-community/netinfo @bam.tech/react-native-image-resizer
|
29
|
+
|
30
|
+
npm i -S react-native-polyfill-globals react-native-url-polyfill web-streams-polyfill base-64 text-encoding react-native-fetch-api react-native-get-random-values buffer
|
31
|
+
|
32
|
+
npm i -D @babel/plugin-transform-class-static-block
|
33
|
+
|
34
|
+
npm i -S jazz-tools jazz-react-native jazz-react-native-media-images
|
35
|
+
|
36
|
+
```
|
37
|
+
|
38
|
+
### Fix Incompatible Dependencies
|
39
|
+
|
40
|
+
```bash
|
41
|
+
npx expo install --fix
|
42
|
+
```
|
43
|
+
|
44
|
+
### Install Pods
|
45
|
+
|
46
|
+
```bash
|
47
|
+
npx pod-install
|
48
|
+
```
|
49
|
+
|
50
|
+
### Configure Metro
|
51
|
+
|
52
|
+
#### Regular Repositories
|
53
|
+
|
54
|
+
If you are not working within a monorepo, create a new file metro.config.js in the root of your project with the following content:
|
55
|
+
|
56
|
+
```js
|
57
|
+
const { getDefaultConfig } = require("expo/metro-config");
|
58
|
+
const path = require("path");
|
59
|
+
const workspaceRoot = path.resolve(__dirname);
|
60
|
+
const config = getDefaultConfig(projectRoot);
|
61
|
+
config.resolver.unstable_enablePackageExports = true; // important setting
|
62
|
+
config.resolver.sourceExts = ["mjs", "js", "json", "ts", "tsx"];
|
63
|
+
config.resolver.requireCycleIgnorePatterns = [/(^|\/|\\)node_modules($|\/|\\)/];
|
64
|
+
module.exports = config;
|
65
|
+
```
|
66
|
+
|
67
|
+
If you created the project using the command npx create-expo-app -e with-router-tailwind my-jazz-app, then metro.config.js is already present. In that case, simply add this setting to the existing file:
|
68
|
+
|
69
|
+
```js
|
70
|
+
config.resolver.unstable_enablePackageExports = true
|
71
|
+
```
|
72
|
+
|
73
|
+
#### Monorepos
|
74
|
+
|
75
|
+
For monorepos, use the following metro.config.js:
|
76
|
+
|
77
|
+
```js
|
78
|
+
const { getDefaultConfig } = require("expo/metro-config");
|
79
|
+
const { FileStore } = require("metro-cache");
|
80
|
+
const path = require("path");
|
81
|
+
|
82
|
+
// eslint-disable-next-line no-undef
|
83
|
+
const projectRoot = __dirname;
|
84
|
+
const workspaceRoot = path.resolve(projectRoot, "../..");
|
85
|
+
|
86
|
+
const config = getDefaultConfig(projectRoot);
|
87
|
+
|
88
|
+
config.watchFolders = [workspaceRoot];
|
89
|
+
config.resolver.nodeModulesPaths = [
|
90
|
+
path.resolve(projectRoot, "node_modules"),
|
91
|
+
path.resolve(workspaceRoot, "node_modules"),
|
92
|
+
];
|
93
|
+
config.resolver.sourceExts = ["mjs", "js", "json", "ts", "tsx"];
|
94
|
+
config.resolver.unstable_enablePackageExports = true;
|
95
|
+
config.resolver.requireCycleIgnorePatterns = [/(^|\/|\\)node_modules($|\/|\\)/];
|
96
|
+
config.cacheStores = [
|
97
|
+
new FileStore({
|
98
|
+
root: path.join(projectRoot, "node_modules", ".cache", "metro"),
|
99
|
+
}),
|
100
|
+
];
|
101
|
+
|
102
|
+
module.exports = config;
|
103
|
+
```
|
104
|
+
|
105
|
+
### Additional Monorepo Configuration (for pnpm users)
|
106
|
+
|
107
|
+
- Add node-linker=hoisted to the root .npmrc (create this file if it doesnβt exist).
|
108
|
+
- Add the following to the root package.json:
|
109
|
+
|
110
|
+
```json
|
111
|
+
"pnpm": {
|
112
|
+
"peerDependencyRules": {
|
113
|
+
"ignoreMissing": [
|
114
|
+
"@babel/*",
|
115
|
+
"expo-modules-*",
|
116
|
+
"typescript"
|
117
|
+
]
|
118
|
+
}
|
119
|
+
}
|
120
|
+
```
|
121
|
+
|
122
|
+
For more information, refer to [this](https://github.com/byCedric/expo-monorepo-example#pnpm-workarounds) Expo monorepo example.
|
123
|
+
|
124
|
+
### Configure Babel
|
125
|
+
|
126
|
+
Add `@babel/plugin-transform-class-static-block` to the array of Babel plugins inside `babel.config.js`:
|
127
|
+
|
128
|
+
```js
|
129
|
+
module.exports = function (api) {
|
130
|
+
api.cache(true);
|
131
|
+
return {
|
132
|
+
presets: ["babel-preset-expo"],
|
133
|
+
plugins: [
|
134
|
+
"nativewind/babel",
|
135
|
+
"@babel/plugin-transform-class-static-block",
|
136
|
+
],
|
137
|
+
};
|
138
|
+
};
|
139
|
+
```
|
140
|
+
|
141
|
+
### Add Polyfills
|
142
|
+
|
143
|
+
Create a file `polyfills.js` at the project root with the following content:
|
144
|
+
|
145
|
+
```js
|
146
|
+
import "react-native-polyfill-globals/auto";
|
147
|
+
import "@azure/core-asynciterator-polyfill";
|
148
|
+
import { ReadableStream } from "web-streams-polyfill/ponyfill/es6";
|
149
|
+
import { polyfillGlobal } from "react-native/Libraries/Utilities/PolyfillFunctions";
|
150
|
+
import { Buffer } from "buffer";
|
151
|
+
|
152
|
+
polyfillGlobal("Buffer", () => Buffer);
|
153
|
+
polyfillGlobal("ReadableStream", () => ReadableStream);
|
154
|
+
```
|
155
|
+
|
156
|
+
Update `index.js` based on whether you are using expo-router or not:
|
157
|
+
|
158
|
+
#### If using `expo-router`
|
159
|
+
|
160
|
+
```js
|
161
|
+
import "./polyfills";
|
162
|
+
import "expo-router/entry";
|
163
|
+
```
|
164
|
+
|
165
|
+
#### Without `expo-router`
|
166
|
+
|
167
|
+
```js
|
168
|
+
import "./polyfills";
|
169
|
+
import { registerRootComponent } from "expo";
|
170
|
+
import App from "./src/App";
|
171
|
+
registerRootComponent(App);
|
172
|
+
```
|
173
|
+
|
174
|
+
Lastly, ensure that the `"main"` field in your `package.json` points to `index.js`:
|
175
|
+
|
176
|
+
```js
|
177
|
+
"main": "index.js",
|
178
|
+
```
|
179
|
+
|
180
|
+
## π How to Use Jazz
|
181
|
+
|
182
|
+
### `createJazzRNApp()`
|
183
|
+
|
184
|
+
Create a file `jazz.tsx` with the following contents:
|
185
|
+
|
186
|
+
```js
|
187
|
+
import { createJazzRNApp } from "jazz-react-native";
|
188
|
+
|
189
|
+
export const Jazz = createJazzRNApp();
|
190
|
+
export const { useAccount, useCoState, useAcceptInvite } = Jazz;
|
191
|
+
```
|
192
|
+
|
193
|
+
You can optionally pass a custom `kvStore` and `AccountSchema` to `createJazzRNApp()`, otherwise, it defaults to `ExpoSecureStoreAdapter` and `Account`.
|
194
|
+
|
195
|
+
### Choosing an Auth Method
|
196
|
+
|
197
|
+
Refer to the Jazz + React Native demo projects for implementing authentication:
|
198
|
+
|
199
|
+
- [DemoAuth Example](https://github.com/gardencmp/jazz/tree/main/examples/chat-rn)
|
200
|
+
- [ClerkAuth Example](https://github.com/gardencmp/jazz/tree/main/examples/chat-rn-clerk)
|
201
|
+
|
202
|
+
In the demos, you'll find details on:
|
203
|
+
|
204
|
+
- Using Jazz.Provider with your chosen authentication method
|
205
|
+
- Defining a Jazz schema
|
206
|
+
- Creating and subscribing to covalues
|
207
|
+
- Handling invites
|
208
|
+
|
209
|
+
### πΌοΈ Working with Images
|
210
|
+
|
211
|
+
To work with images in Jazz, import the `createImage` function from [`jazz-react-native-media-images`](https://github.com/gardencmp/jazz/tree/main/packages/jazz-react-native-media-images).
|
212
|
+
|
213
|
+
```js
|
214
|
+
import { createImage } from "jazz-react-native-media-images";
|
215
|
+
|
216
|
+
const base64ImageDataURI = "data:image/png;base64,...";
|
217
|
+
|
218
|
+
const image = await createImage(base64ImageDataURI, {
|
219
|
+
owner: newPetPost._owner,
|
220
|
+
maxSize: 2048, // optional: specify maximum image size
|
221
|
+
});
|
222
|
+
|
223
|
+
someCovalue.image = image;
|
224
|
+
```
|
225
|
+
|
226
|
+
For a complete implementation, please refer to [this](https://github.com/gardencmp/jazz/blob/main/examples/pets/src/3_NewPetPostForm.tsx) demo.
|
227
|
+
|
228
|
+
### π± Running Your App
|
229
|
+
|
230
|
+
```bash
|
231
|
+
npx expo run:ios
|
232
|
+
npx expo run:android
|
233
|
+
```
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jazz-react-native",
|
3
|
-
"version": "0.8.
|
3
|
+
"version": "0.8.12",
|
4
4
|
"type": "module",
|
5
5
|
"main": "./dist/index.js",
|
6
6
|
"module": "./dist/index.js",
|
@@ -17,9 +17,9 @@
|
|
17
17
|
"dependencies": {
|
18
18
|
"@scure/bip39": "^1.3.0",
|
19
19
|
"typescript": "^5.3.3",
|
20
|
-
"cojson": "0.8.
|
21
|
-
"cojson-transport-ws": "0.8.
|
22
|
-
"jazz-tools": "0.8.
|
20
|
+
"cojson": "0.8.12",
|
21
|
+
"cojson-transport-ws": "0.8.12",
|
22
|
+
"jazz-tools": "0.8.12"
|
23
23
|
},
|
24
24
|
"peerDependencies": {
|
25
25
|
"@react-native-community/netinfo": "*",
|