0.11.5 โ€ข Published 3 months ago

jazz-react-native v0.11.5

Weekly downloads
-
License
MIT
Repository
-
Last release
3 months ago

๐ŸŽท Jazz + React Native

Jazz requires an Expo development build using Expo Prebuild for native code. It is not compatible with Expo Go. Jazz also supports the New Architecture.

Tested with:

"expo": "~51.0.0",
"react-native": "~0.74.5",
"react": "^18.2.0",

๐Ÿš€ Setup

Create a New Project

(skip this step if you already have one)

npx create-expo-app -e with-router-tailwind my-jazz-app
cd my-jazz-app
npx expo prebuild

Install dependencies

npx expo install expo-linking expo-secure-store expo-file-system @react-native-community/netinfo @bam.tech/react-native-image-resizer

  npm i -S @azure/core-asynciterator-polyfill react-native-url-polyfill readable-stream react-native-get-random-values @craftzdog/react-native-buffer @op-engineering/op-sqlite


npm i -D @babel/plugin-transform-class-static-block

npm i -S jazz-tools jazz-react-native jazz-react-native-media-images

note: Hermes has added support for atob and btoa in React Native 0.74. If you are using earlier versions, you may also need to polyfill atob and btoa in your package.json . Packages to try include text-encoding and base-64, and you can drop @bacons/text-decoder.

Fix Incompatible Dependencies

npx expo install --fix

Install Pods

npx pod-install

Configure Metro

Regular Repositories

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:

const { getDefaultConfig } = require("expo/metro-config");
const path = require("path");
const workspaceRoot = path.resolve(__dirname);
const config = getDefaultConfig(projectRoot);
config.resolver.sourceExts = ["mjs", "js", "json", "ts", "tsx"];
config.resolver.requireCycleIgnorePatterns = [/(^|\/|\\)node_modules($|\/|\\)/];
module.exports = config;

Monorepos

For monorepos, use the following metro.config.js:

const { getDefaultConfig } = require("expo/metro-config");
const { FileStore } = require("metro-cache");
const path = require("path");

// eslint-disable-next-line no-undef
const projectRoot = __dirname;
const workspaceRoot = path.resolve(projectRoot, "../..");

const config = getDefaultConfig(projectRoot);

config.watchFolders = [workspaceRoot];
config.resolver.nodeModulesPaths = [
    path.resolve(projectRoot, "node_modules"),
    path.resolve(workspaceRoot, "node_modules"),
];
config.resolver.sourceExts = ["mjs", "js", "json", "ts", "tsx"];
config.resolver.requireCycleIgnorePatterns = [/(^|\/|\\)node_modules($|\/|\\)/];
config.cacheStores = [
    new FileStore({
        root: path.join(projectRoot, "node_modules", ".cache", "metro"),
    }),
];

module.exports = config;

Additional Monorepo Configuration (for pnpm users)

  • Add node-linker=hoisted to the root .npmrc (create this file if it doesnโ€™t exist).
  • Add the following to the root package.json:
"pnpm": {
    "peerDependencyRules": {
        "ignoreMissing": [
            "@babel/*",
            "expo-modules-*",
            "typescript"
        ]
    }
}

For more information, refer to this Expo monorepo example.

Configure Babel

Add @babel/plugin-transform-class-static-block to the array of Babel plugins inside babel.config.js:

module.exports = function (api) {
    api.cache(true);
    return {
        presets: ["babel-preset-expo"],
        plugins: [
            "nativewind/babel",
            "@babel/plugin-transform-class-static-block",
        ],
    };
};

Add Polyfills

Create a file polyfills.js at the project root with the following content:

import { polyfillGlobal } from 'react-native/Libraries/Utilities/PolyfillFunctions';

import { Buffer } from '@craftzdog/react-native-buffer';
polyfillGlobal('Buffer', () => Buffer);

import { ReadableStream } from 'readable-stream';
polyfillGlobal('ReadableStream', () => ReadableStream);

import '@azure/core-asynciterator-polyfill';

import '@bacons/text-decoder/install';

import 'react-native-get-random-values';

Update index.js based on whether you are using expo-router or not:

If using expo-router

import "./polyfills";
import "expo-router/entry";

Without expo-router

import "./polyfills";
import { registerRootComponent } from "expo";
import App from "./src/App";
registerRootComponent(App);

Lastly, ensure that the "main" field in your package.json points to index.js:

"main": "index.js",

๐ŸŽ‰ How to Use Jazz

createJazzRNApp()

Create a file jazz.tsx with the following contents:

import { createJazzRNApp } from "jazz-react-native";

export const Jazz = createJazzRNApp();
export const { useAccount, useCoState, useAcceptInvite } = Jazz;

You can optionally pass a custom kvStore and AccountSchema to createJazzRNApp(), otherwise, it defaults to ExpoSecureStoreAdapter and Account.

Choosing an Auth Method

Refer to the Jazz + React Native demo projects for implementing authentication:

In the demos, you'll find details on:

  • Using JazzProvider with your chosen authentication method
  • Defining a Jazz schema
  • Creating and subscribing to covalues
  • Handling invites

๐Ÿ–ผ๏ธ Working with Images

To work with images in Jazz, import the createImage function from jazz-react-native-media-images.

import { createImage } from "jazz-react-native-media-images";

const base64ImageDataURI = "data:image/png;base64,...";

const image = await createImage(base64ImageDataURI, {
    owner: newPetPost._owner,
    maxSize: 2048, // optional: specify maximum image size
});

someCovalue.image = image;

For a complete implementation, please refer to this demo.

๐Ÿ“ฑ Running Your App

npx expo run:ios
npx expo run:android
0.9.12

5 months ago

0.9.13

5 months ago

0.8.44

6 months ago

0.9.14

5 months ago

0.8.47

6 months ago

0.9.15

5 months ago

0.8.46

6 months ago

0.8.41

6 months ago

0.9.10

5 months ago

0.9.11

5 months ago

0.9.16

5 months ago

0.8.49

5 months ago

0.9.17

5 months ago

0.8.48

5 months ago

0.9.18

5 months ago

0.9.19

5 months ago

0.11.0

3 months ago

0.10.14

3 months ago

0.11.1

3 months ago

0.10.15

3 months ago

0.11.2

3 months ago

0.11.3

3 months ago

0.11.4

3 months ago

0.10.10

4 months ago

0.11.5

3 months ago

0.10.11

4 months ago

0.10.12

4 months ago

0.10.13

4 months ago

0.8.34

7 months ago

0.8.36

6 months ago

0.8.35

6 months ago

0.8.30

7 months ago

0.8.32

7 months ago

0.8.31

7 months ago

0.8.38

6 months ago

0.8.37

6 months ago

0.8.39

6 months ago

0.9.0

5 months ago

0.9.2

5 months ago

0.9.1

5 months ago

0.9.8

5 months ago

0.8.23

7 months ago

0.9.9

5 months ago

0.9.4

5 months ago

0.9.3

5 months ago

0.9.6

5 months ago

0.8.21

7 months ago

0.9.5

5 months ago

0.8.20

7 months ago

0.8.27

7 months ago

0.8.29

7 months ago

0.8.28

7 months ago

0.10.1

4 months ago

0.10.2

4 months ago

0.10.3

4 months ago

0.10.4

4 months ago

0.10.5

4 months ago

0.10.6

4 months ago

0.10.7

4 months ago

0.10.8

4 months ago

0.9.23

4 months ago

0.8.12

7 months ago

0.8.14

7 months ago

0.8.13

7 months ago

0.9.20

5 months ago

0.8.51

5 months ago

0.9.21

4 months ago

0.10.0

4 months ago

0.9.22

4 months ago

0.8.19

7 months ago

0.8.16

7 months ago

0.8.15

7 months ago

0.8.18

7 months ago

0.8.17

7 months ago

0.8.50

5 months ago

0.8.11

8 months ago

0.8.8

8 months ago

0.8.7

8 months ago

0.8.6

8 months ago

0.8.5

8 months ago

0.8.3

8 months ago