|
1 | | -# react-native-nitro-version-check |
| 1 | +<h1 align="center"> |
| 2 | + react-native-nitro-version-check |
| 3 | +</h1> |
2 | 4 |
|
3 | | -A React Native module to check app version info, built with [Nitro Modules](https://github.com/mrousavy/nitro). |
| 5 | +<p align="center"> |
| 6 | + <b>A fast, modern version-checking library for React Native, powered by <a href="https://github.com/mrousavy/nitro">Nitro Modules</a>.</b> |
| 7 | +</p> |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + A drop-in replacement for the unmaintained <a href="https://github.com/kimxogus/react-native-version-check"><code>react-native-version-check</code></a> — rewritten from scratch with <a href="https://github.com/mrousavy/nitro">Nitro Modules</a>. |
| 11 | +</p> |
| 12 | + |
| 13 | +<br /> |
| 14 | + |
| 15 | +## Features |
| 16 | + |
| 17 | +- ⚡ **Synchronous access** to version, build number, package name, and country |
| 18 | +- 🏪 **Store version lookup** from the App Store or Play Store |
| 19 | +- 🔍 **Granular update checks** — major, minor, or patch |
| 20 | +- 📦 **Install source detection** — TestFlight, App Store, Play Store, or sideloaded |
| 21 | +- 🪶 **Tiny footprint** — pure Swift on iOS, Kotlin on Android |
| 22 | + |
| 23 | +## Performance |
| 24 | + |
| 25 | +Benchmarked against [`react-native-version-check`](https://github.com/kimxogus/react-native-version-check). 100,000 iterations averaged over 5 runs on an iPhone 12: |
| 26 | + |
| 27 | +| Method | Speedup | |
| 28 | +|--------|---------| |
| 29 | +| `getAllInfo` | **~3.1x faster** | |
| 30 | +| `packageName` | **~1.6x faster** | |
| 31 | +| `version` | **~1.6x faster** | |
| 32 | +| `buildNumber` | **~1.6x faster** | |
| 33 | +| `getCountry` | **~3.1x faster** | |
4 | 34 |
|
5 | 35 | ## Installation |
6 | 36 |
|
7 | 37 | ```sh |
8 | | -bun add react-native-nitro-version-check react-native-nitro-modules |
| 38 | +npm i react-native-nitro-version-check react-native-nitro-modules |
| 39 | +``` |
| 40 | + |
| 41 | +For Expo projects, run prebuild: |
| 42 | +```sh |
| 43 | +npx expo prebuild |
| 44 | +``` |
| 45 | + |
| 46 | +For bare React Native projects: |
| 47 | +```sh |
| 48 | +cd ios && pod install |
9 | 49 | ``` |
10 | 50 |
|
11 | 51 | ## Usage |
12 | 52 |
|
13 | | -```tsx |
14 | | -import { VersionCheck } from "react-native-nitro-version-check"; |
| 53 | +```ts |
| 54 | +import { VersionCheck, getCountry, getStoreUrl, getLatestVersion, needsUpdate } from 'react-native-nitro-version-check' |
15 | 55 |
|
16 | | -// Static properties |
17 | | -VersionCheck.version; // "1.0.0" |
18 | | -VersionCheck.buildNumber; // "42" |
19 | | -VersionCheck.packageName; // "com.example.app" |
20 | | -VersionCheck.getCountry(); // "US" |
| 56 | +// Sync properties |
| 57 | +VersionCheck.version // "1.2.0" |
| 58 | +VersionCheck.buildNumber // "42" |
| 59 | +VersionCheck.packageName // "com.example.app" |
| 60 | +VersionCheck.installSource // "appstore" | "testflight" | "playstore" | undefined |
| 61 | +getCountry() // "US" |
21 | 62 |
|
22 | | -// Async methods |
23 | | -const storeUrl = await VersionCheck.getStoreUrl(); |
24 | | -const latest = await VersionCheck.getLatestVersion(); |
| 63 | +// Async |
| 64 | +const url = await getStoreUrl() // App Store / Play Store URL |
| 65 | +const latest = await getLatestVersion() // "1.3.0" |
25 | 66 |
|
26 | | -if (await VersionCheck.needsUpdate()) { |
27 | | - Linking.openURL(await VersionCheck.getStoreUrl()); |
| 67 | +if (await needsUpdate()) { |
| 68 | + Linking.openURL(await getStoreUrl()) |
28 | 69 | } |
29 | | -``` |
30 | | - |
31 | | -Or import individually: |
32 | 70 |
|
33 | | -```tsx |
34 | | -import { version, buildNumber, getCountry, needsUpdate } from "react-native-nitro-version-check"; |
| 71 | +// Only prompt for major updates |
| 72 | +if (await needsUpdate({ level: 'major' })) { |
| 73 | + // 1.x → 2.x |
| 74 | +} |
35 | 75 | ``` |
36 | 76 |
|
37 | 77 | ## API |
38 | 78 |
|
39 | | -### Properties |
| 79 | +### `VersionCheck` |
40 | 80 |
|
41 | | -| API | Type | Description | |
42 | | -|-----|------|-------------| |
| 81 | +| Property | Type | Description | |
| 82 | +|----------|------|-------------| |
43 | 83 | | `version` | `string` | App version | |
44 | 84 | | `buildNumber` | `string` | Build number | |
45 | | -| `packageName` | `string` | Bundle ID / package name | |
| 85 | +| `packageName` | `string` | Bundle ID / Application ID | |
| 86 | +| `installSource` | `string \| undefined` | `"appstore"` `"testflight"` `"playstore"` or `undefined` | |
| 87 | +| `getCountry()` | `string` | Device's 2-letter ISO country code | |
| 88 | +| `getStoreUrl()` | `Promise<string>` | App Store / Play Store URL | |
| 89 | +| `getLatestVersion()` | `Promise<string>` | Latest version in the store | |
| 90 | +| `needsUpdate()` | `Promise<boolean>` | Whether an update is available | |
46 | 91 |
|
47 | | -### Methods |
| 92 | +### Standalone exports |
48 | 93 |
|
49 | | -| API | Returns | Description | |
50 | | -|-----|---------|-------------| |
51 | | -| `getCountry()` | `string` | Current device country code | |
| 94 | +Also available as individual named exports: |
| 95 | + |
| 96 | +| Export | Returns | Description | |
| 97 | +|--------|---------|-------------| |
| 98 | +| `getCountry()` | `string` | Device's 2-letter ISO country code | |
52 | 99 | | `getStoreUrl()` | `Promise<string>` | App Store / Play Store URL | |
53 | | -| `getLatestVersion()` | `Promise<string>` | Latest version from the store | |
54 | | -| `needsUpdate()` | `Promise<boolean>` | Whether an update is available | |
| 100 | +| `getLatestVersion()` | `Promise<string>` | Latest version in the store | |
| 101 | +| `needsUpdate(options?)` | `Promise<boolean>` | Whether an update is available | |
| 102 | + |
| 103 | +#### `needsUpdate` options |
| 104 | + |
| 105 | +| Option | Type | Default | Description | |
| 106 | +|--------|------|---------|-------------| |
| 107 | +| `level` | `"major" \| "minor" \| "patch"` | `"patch"` | Minimum version bump to trigger `true` | |
| 108 | + |
| 109 | +### Utilities |
| 110 | + |
| 111 | +| Function | Returns | Description | |
| 112 | +|----------|---------|-------------| |
| 113 | +| `compareVersions(v1, v2)` | `-1 \| 0 \| 1` | Compare two semver strings | |
55 | 114 |
|
56 | 115 | ## License |
57 | 116 |
|
|
0 commit comments