@forthtilliath/expo-release-updates-ui 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +143 -0
- package/dist/ChangelogNotes.d.ts +22 -0
- package/dist/ChangelogNotes.d.ts.map +1 -0
- package/dist/ChangelogNotes.js +51 -0
- package/dist/UpdateAvailableBanner.d.ts +29 -0
- package/dist/UpdateAvailableBanner.d.ts.map +1 -0
- package/dist/UpdateAvailableBanner.js +63 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/useUpdateCheck.d.ts +35 -0
- package/dist/useUpdateCheck.d.ts.map +1 -0
- package/dist/useUpdateCheck.js +47 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Forthtilliath
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# @forthtilliath/expo-release-updates-ui
|
|
2
|
+
|
|
3
|
+
React Native UI for self-updating a sideloaded Android Expo app: release notes rendering, a dismissible "update available" banner, and a hook to check for updates once per mount. No opinion on your app's theme. Pairs with [`@forthtilliath/expo-release-updates`](../expo-release-updates#readme) (the framework-agnostic logic — checking GitHub releases, comparing versions, downloading the APK), kept in a separate package so that logic stays usable without pulling in React/React Native.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @forthtilliath/expo-release-updates-ui @forthtilliath/expo-release-updates react react-native
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Or, from within this monorepo, as a workspace dependency:
|
|
12
|
+
|
|
13
|
+
```json
|
|
14
|
+
{
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@forthtilliath/expo-release-updates-ui": "workspace:*"
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`react` and `react-native` are peer dependencies — install them in the consuming app if not already present.
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
Each export is its own module — import the file you need directly, or use the barrel to pull everything from a single import:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { ChangelogNotes } from "@forthtilliath/expo-release-updates-ui/ChangelogNotes";
|
|
29
|
+
import { UpdateAvailableBanner } from "@forthtilliath/expo-release-updates-ui/UpdateAvailableBanner";
|
|
30
|
+
import { useUpdateCheck } from "@forthtilliath/expo-release-updates-ui/useUpdateCheck";
|
|
31
|
+
|
|
32
|
+
// Or, everything at once:
|
|
33
|
+
import {
|
|
34
|
+
ChangelogNotes,
|
|
35
|
+
UpdateAvailableBanner,
|
|
36
|
+
useUpdateCheck,
|
|
37
|
+
} from "@forthtilliath/expo-release-updates-ui";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### `useUpdateCheck(options)`
|
|
41
|
+
|
|
42
|
+
Checks once per mount (e.g. app launch) whether a newer release is available, throttled to at most one real check per `minIntervalMs` (default 12h) and silent for a release the user already dismissed. Has no opinion on where "when did we last check" / "which version did the user dismiss" are persisted — both are read/written entirely through the options you pass in.
|
|
43
|
+
|
|
44
|
+
```tsx
|
|
45
|
+
import { useUpdateCheck } from "@forthtilliath/expo-release-updates-ui";
|
|
46
|
+
import {
|
|
47
|
+
compareVersions,
|
|
48
|
+
fetchLatestRelease,
|
|
49
|
+
} from "@forthtilliath/expo-release-updates";
|
|
50
|
+
|
|
51
|
+
const update = useUpdateCheck({
|
|
52
|
+
currentVersion: Constants.expoConfig?.version ?? "0.0.0",
|
|
53
|
+
checkForUpdate: fetchLatestRelease,
|
|
54
|
+
compareVersions,
|
|
55
|
+
getLastCheck: () => ({
|
|
56
|
+
lastCheckedAt: settings?.lastUpdateCheckAt ?? null,
|
|
57
|
+
dismissedVersion: settings?.dismissedUpdateVersion ?? null,
|
|
58
|
+
}),
|
|
59
|
+
onChecked: (lastCheckedAt) =>
|
|
60
|
+
updateSettings({ lastUpdateCheckAt: lastCheckedAt }),
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
if (update.status === "available") {
|
|
64
|
+
// update.release.version / .notes / .apkUrl
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### `<ChangelogNotes notes={...} styles={...} />`
|
|
69
|
+
|
|
70
|
+
Renders GitHub-style release notes — as produced by `@forthtilliath/expo-release-updates`'s `parseChangelogNotes` — as headings, bulleted items, and bold-aware text, instead of showing the raw Markdown syntax in a plain `Text`.
|
|
71
|
+
|
|
72
|
+
```tsx
|
|
73
|
+
<ChangelogNotes notes={release.notes} />
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
It understands the small subset of Markdown GitHub release notes actually use:
|
|
77
|
+
|
|
78
|
+
| `notes` input | Rendered as |
|
|
79
|
+
| ----------------------------------------- | --------------------------------------------------------------------------- |
|
|
80
|
+
| `### Added` | a heading `Text` — `"Added"` |
|
|
81
|
+
| `- Export history to CSV.` | a row (`View`) with a `•` bullet `Text` and an item `Text` |
|
|
82
|
+
| `**Auto-backup**: saves every 5 minutes.` | a plain `Text`, with the bold segment split into its own bold-styled `Text` |
|
|
83
|
+
|
|
84
|
+
A full example, mixing all three:
|
|
85
|
+
|
|
86
|
+
```tsx
|
|
87
|
+
<ChangelogNotes
|
|
88
|
+
notes={`### Added\n- **Auto-backup**: saves every 5 minutes.\n- Export history to CSV.\n\nSee the full changelog for details.`}
|
|
89
|
+
/>
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The component ships with neutral default styles and no opinion on your app's theme. Override any subset via the `styles` prop to match your colors/dark mode:
|
|
93
|
+
|
|
94
|
+
```tsx
|
|
95
|
+
<ChangelogNotes
|
|
96
|
+
notes={release.notes}
|
|
97
|
+
styles={{
|
|
98
|
+
heading: { color: colors.text, fontWeight: "700" },
|
|
99
|
+
itemRow: { gap: 8 },
|
|
100
|
+
bullet: { color: colors.primary },
|
|
101
|
+
itemText: { color: colors.textMuted },
|
|
102
|
+
text: { color: colors.textMuted },
|
|
103
|
+
bold: { color: colors.text, fontWeight: "700" },
|
|
104
|
+
}}
|
|
105
|
+
/>
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Every field of `styles` is optional — pass only the ones you want to override; the rest fall back to the defaults (`ChangelogNotesStyles` in `ChangelogNotes.tsx`).
|
|
109
|
+
|
|
110
|
+
### `<UpdateAvailableBanner version notes onPress onDismiss />`
|
|
111
|
+
|
|
112
|
+
Dismissible banner announcing an available update: version, release notes (rendered via `ChangelogNotes`), an action button and a dismiss button. Has no opinion on what the action does (e.g. navigate to an update screen) or on how/whether dismissal is persisted.
|
|
113
|
+
|
|
114
|
+
```tsx
|
|
115
|
+
import { UpdateAvailableBanner } from "@forthtilliath/expo-release-updates-ui";
|
|
116
|
+
|
|
117
|
+
{
|
|
118
|
+
update.status === "available" && (
|
|
119
|
+
<UpdateAvailableBanner
|
|
120
|
+
version={update.release.version}
|
|
121
|
+
notes={update.release.notes}
|
|
122
|
+
onPress={() => router.push("/settings/update")}
|
|
123
|
+
onDismiss={() => {
|
|
124
|
+
dismissUpdateVersion(update.release.version);
|
|
125
|
+
update.dismiss();
|
|
126
|
+
}}
|
|
127
|
+
/>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Scripts
|
|
133
|
+
|
|
134
|
+
```bash
|
|
135
|
+
pnpm run dev # tsc --watch -> dist/
|
|
136
|
+
pnpm run build # tsc -> dist/
|
|
137
|
+
pnpm run check-types # tsc --noEmit
|
|
138
|
+
pnpm run lint # eslint
|
|
139
|
+
pnpm run test # vitest run
|
|
140
|
+
pnpm run test:watch # vitest
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Built to `dist/` (see the `exports` field in `package.json`), so run `pnpm run build` (or `dev`) after source changes for consumers to see them.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
2
|
+
export interface ChangelogNotesStyles {
|
|
3
|
+
heading?: StyleProp<TextStyle>;
|
|
4
|
+
itemRow?: StyleProp<ViewStyle>;
|
|
5
|
+
bullet?: StyleProp<TextStyle>;
|
|
6
|
+
itemText?: StyleProp<TextStyle>;
|
|
7
|
+
text?: StyleProp<TextStyle>;
|
|
8
|
+
bold?: StyleProp<TextStyle>;
|
|
9
|
+
}
|
|
10
|
+
export interface ChangelogNotesProps {
|
|
11
|
+
/** Raw release notes, e.g. straight from a GitHub release body. */
|
|
12
|
+
notes: string;
|
|
13
|
+
/** Override any of the default styles to match your app's theme. */
|
|
14
|
+
styles?: ChangelogNotesStyles;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Renders GitHub-style release notes (parsed by `parseChangelogNotes`) as
|
|
18
|
+
* headings, bulleted items and bold-aware text, instead of showing the raw
|
|
19
|
+
* Markdown syntax in a plain `<Text>`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function ChangelogNotes({ notes, styles }: ChangelogNotesProps): import("react").JSX.Element;
|
|
22
|
+
//# sourceMappingURL=ChangelogNotes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChangelogNotes.d.ts","sourceRoot":"","sources":["../src/ChangelogNotes.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAMpE,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC/B,MAAM,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC5B,IAAI,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC7B;AAED,MAAM,WAAW,mBAAmB;IAClC,mEAAmE;IACnE,KAAK,EAAE,MAAM,CAAC;IACd,oEAAoE;IACpE,MAAM,CAAC,EAAE,oBAAoB,CAAC;CAC/B;AA0BD;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,mBAAmB,+BA+CpE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Text, View } from "react-native";
|
|
3
|
+
import { parseChangelogNotes } from "@forthtilliath/expo-release-updates/parseChangelogNotes";
|
|
4
|
+
// Reasonable, neutral defaults so the component works with zero
|
|
5
|
+
// configuration — most consumers will still want to pass `styles` to match
|
|
6
|
+
// their own theme (colors, dark mode, ...), which this package has no
|
|
7
|
+
// opinion on.
|
|
8
|
+
const defaultStyles = {
|
|
9
|
+
heading: { fontSize: 13, fontWeight: "700", color: "#111827", marginTop: 8 },
|
|
10
|
+
itemRow: { flexDirection: "row", gap: 6, marginTop: 4 },
|
|
11
|
+
bullet: { fontSize: 13, color: "#6b7280" },
|
|
12
|
+
itemText: { flex: 1, fontSize: 13, color: "#6b7280" },
|
|
13
|
+
text: { fontSize: 13, color: "#6b7280" },
|
|
14
|
+
bold: { fontWeight: "700", color: "#111827" },
|
|
15
|
+
};
|
|
16
|
+
function renderSegments(segments, boldStyle) {
|
|
17
|
+
return segments.map((segment) => (_jsx(Text, { style: segment.bold ? boldStyle : undefined, children: segment.text }, segment.text)));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Renders GitHub-style release notes (parsed by `parseChangelogNotes`) as
|
|
21
|
+
* headings, bulleted items and bold-aware text, instead of showing the raw
|
|
22
|
+
* Markdown syntax in a plain `<Text>`.
|
|
23
|
+
*/
|
|
24
|
+
export function ChangelogNotes({ notes, styles }) {
|
|
25
|
+
// Each field is merged as a style array (default, then override) rather
|
|
26
|
+
// than the override replacing the whole default outright — so passing e.g.
|
|
27
|
+
// `styles={{ heading: { color: "red" } }}` only changes the color instead
|
|
28
|
+
// of silently dropping the default's fontSize/fontWeight/marginTop too.
|
|
29
|
+
const merged = {
|
|
30
|
+
heading: [defaultStyles.heading, styles?.heading],
|
|
31
|
+
itemRow: [defaultStyles.itemRow, styles?.itemRow],
|
|
32
|
+
bullet: [defaultStyles.bullet, styles?.bullet],
|
|
33
|
+
itemText: [defaultStyles.itemText, styles?.itemText],
|
|
34
|
+
text: [defaultStyles.text, styles?.text],
|
|
35
|
+
bold: [defaultStyles.bold, styles?.bold],
|
|
36
|
+
};
|
|
37
|
+
const blocks = parseChangelogNotes(notes);
|
|
38
|
+
return (_jsx(_Fragment, { children: blocks.map((block, index) => {
|
|
39
|
+
// Blocks have no stable identity of their own (plain parsed lines),
|
|
40
|
+
// so the index is the only reasonable key — the list is never
|
|
41
|
+
// reordered or filtered after the initial parse.
|
|
42
|
+
const key = `${block.type}-${String(index)}`;
|
|
43
|
+
if (block.type === "heading") {
|
|
44
|
+
return (_jsx(Text, { style: merged.heading, children: block.text }, key));
|
|
45
|
+
}
|
|
46
|
+
if (block.type === "item") {
|
|
47
|
+
return (_jsxs(View, { style: merged.itemRow, children: [_jsx(Text, { style: merged.bullet, children: "\u2022" }), _jsx(Text, { style: merged.itemText, children: renderSegments(block.segments, merged.bold) })] }, key));
|
|
48
|
+
}
|
|
49
|
+
return (_jsx(Text, { style: merged.text, children: renderSegments(block.segments, merged.bold) }, key));
|
|
50
|
+
}) }));
|
|
51
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { StyleProp, TextStyle, ViewStyle } from "react-native";
|
|
2
|
+
import type { ChangelogNotesStyles } from "./ChangelogNotes.js";
|
|
3
|
+
export interface UpdateAvailableBannerStyles {
|
|
4
|
+
container?: StyleProp<ViewStyle>;
|
|
5
|
+
header?: StyleProp<ViewStyle>;
|
|
6
|
+
title?: StyleProp<TextStyle>;
|
|
7
|
+
notes?: ChangelogNotesStyles;
|
|
8
|
+
actionButton?: StyleProp<ViewStyle>;
|
|
9
|
+
actionButtonText?: StyleProp<TextStyle>;
|
|
10
|
+
dismissButton?: StyleProp<ViewStyle>;
|
|
11
|
+
dismissButtonText?: StyleProp<TextStyle>;
|
|
12
|
+
}
|
|
13
|
+
export interface UpdateAvailableBannerLabels {
|
|
14
|
+
title?: (version: string) => string;
|
|
15
|
+
action?: string;
|
|
16
|
+
dismiss?: string;
|
|
17
|
+
dismissAccessibilityLabel?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface UpdateAvailableBannerProps {
|
|
20
|
+
version: string;
|
|
21
|
+
/** Raw release notes, passed straight to `ChangelogNotes`. */
|
|
22
|
+
notes: string;
|
|
23
|
+
onPress: () => void;
|
|
24
|
+
onDismiss: () => void;
|
|
25
|
+
labels?: UpdateAvailableBannerLabels;
|
|
26
|
+
styles?: UpdateAvailableBannerStyles;
|
|
27
|
+
}
|
|
28
|
+
export declare function UpdateAvailableBanner({ version, notes, onPress, onDismiss, labels, styles, }: UpdateAvailableBannerProps): import("react").JSX.Element;
|
|
29
|
+
//# sourceMappingURL=UpdateAvailableBanner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UpdateAvailableBanner.d.ts","sourceRoot":"","sources":["../src/UpdateAvailableBanner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAGhE,MAAM,WAAW,2BAA2B;IAC1C,SAAS,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACjC,MAAM,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC9B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,KAAK,CAAC,EAAE,oBAAoB,CAAC;IAC7B,YAAY,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACpC,gBAAgB,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACxC,aAAa,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IACrC,iBAAiB,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC1C;AAED,MAAM,WAAW,2BAA2B;IAC1C,KAAK,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,CAAC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,yBAAyB,CAAC,EAAE,MAAM,CAAC;CACpC;AAED,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,8DAA8D;IAC9D,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,SAAS,EAAE,MAAM,IAAI,CAAC;IACtB,MAAM,CAAC,EAAE,2BAA2B,CAAC;IACrC,MAAM,CAAC,EAAE,2BAA2B,CAAC;CACtC;AAwCD,wBAAgB,qBAAqB,CAAC,EACpC,OAAO,EACP,KAAK,EACL,OAAO,EACP,SAAS,EACT,MAAM,EACN,MAAM,GACP,EAAE,0BAA0B,+BA+C5B"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Pressable, Text, View } from "react-native";
|
|
3
|
+
import { ChangelogNotes } from "./ChangelogNotes.js";
|
|
4
|
+
const defaultStyles = {
|
|
5
|
+
container: {
|
|
6
|
+
backgroundColor: "#ffffff",
|
|
7
|
+
borderWidth: 1,
|
|
8
|
+
borderColor: "#e5e7eb",
|
|
9
|
+
borderRadius: 10,
|
|
10
|
+
padding: 14,
|
|
11
|
+
gap: 8,
|
|
12
|
+
},
|
|
13
|
+
header: {
|
|
14
|
+
flexDirection: "row",
|
|
15
|
+
justifyContent: "space-between",
|
|
16
|
+
alignItems: "center",
|
|
17
|
+
},
|
|
18
|
+
title: { fontSize: 15, fontWeight: "700", color: "#111827" },
|
|
19
|
+
notes: {},
|
|
20
|
+
actionButton: {
|
|
21
|
+
backgroundColor: "#2563eb",
|
|
22
|
+
borderRadius: 10,
|
|
23
|
+
paddingVertical: 10,
|
|
24
|
+
alignItems: "center",
|
|
25
|
+
},
|
|
26
|
+
actionButtonText: { color: "#ffffff", fontSize: 14, fontWeight: "700" },
|
|
27
|
+
dismissButton: { padding: 4 },
|
|
28
|
+
dismissButtonText: { fontSize: 13, color: "#6b7280" },
|
|
29
|
+
};
|
|
30
|
+
const defaultLabels = {
|
|
31
|
+
title: (version) => `Version ${version} disponible`,
|
|
32
|
+
action: "Voir",
|
|
33
|
+
dismiss: "Fermer",
|
|
34
|
+
dismissAccessibilityLabel: "Fermer la notification de mise à jour",
|
|
35
|
+
};
|
|
36
|
+
// Dismissible banner announcing an available update: version, release notes
|
|
37
|
+
// (via `ChangelogNotes`), and an action + dismiss button. Has no opinion on
|
|
38
|
+
// what "action" does (e.g. navigate to an update screen) or on how/whether
|
|
39
|
+
// dismissal is persisted — both are left entirely to the caller.
|
|
40
|
+
export function UpdateAvailableBanner({ version, notes, onPress, onDismiss, labels, styles, }) {
|
|
41
|
+
// Style fields are merged as arrays (default, then override) so a partial
|
|
42
|
+
// override only changes the properties it specifies instead of replacing
|
|
43
|
+
// the whole default style object. `notes` is forwarded as-is to
|
|
44
|
+
// ChangelogNotes, which does its own equivalent merge against its defaults.
|
|
45
|
+
const merged = {
|
|
46
|
+
container: [defaultStyles.container, styles?.container],
|
|
47
|
+
header: [defaultStyles.header, styles?.header],
|
|
48
|
+
title: [defaultStyles.title, styles?.title],
|
|
49
|
+
notes: styles?.notes ?? defaultStyles.notes,
|
|
50
|
+
actionButton: [defaultStyles.actionButton, styles?.actionButton],
|
|
51
|
+
actionButtonText: [
|
|
52
|
+
defaultStyles.actionButtonText,
|
|
53
|
+
styles?.actionButtonText,
|
|
54
|
+
],
|
|
55
|
+
dismissButton: [defaultStyles.dismissButton, styles?.dismissButton],
|
|
56
|
+
dismissButtonText: [
|
|
57
|
+
defaultStyles.dismissButtonText,
|
|
58
|
+
styles?.dismissButtonText,
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
const t = { ...defaultLabels, ...labels };
|
|
62
|
+
return (_jsxs(View, { style: merged.container, children: [_jsxs(View, { style: merged.header, children: [_jsx(Text, { style: merged.title, children: t.title(version) }), _jsx(Pressable, { style: merged.dismissButton, onPress: onDismiss, accessibilityRole: "button", accessibilityLabel: t.dismissAccessibilityLabel, children: _jsx(Text, { style: merged.dismissButtonText, children: t.dismiss }) })] }), notes ? _jsx(ChangelogNotes, { notes: notes, styles: merged.notes }) : null, _jsx(Pressable, { style: merged.actionButton, onPress: onPress, accessibilityRole: "button", accessibilityLabel: t.action, children: _jsx(Text, { style: merged.actionButtonText, children: t.action }) })] }));
|
|
63
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export interface UpdateCheckRelease {
|
|
2
|
+
version: string;
|
|
3
|
+
notes: string;
|
|
4
|
+
apkUrl: string;
|
|
5
|
+
}
|
|
6
|
+
export type UpdateCheckState = {
|
|
7
|
+
status: "idle";
|
|
8
|
+
} | {
|
|
9
|
+
status: "available";
|
|
10
|
+
release: UpdateCheckRelease;
|
|
11
|
+
} | {
|
|
12
|
+
status: "error";
|
|
13
|
+
};
|
|
14
|
+
export interface UseUpdateCheckOptions {
|
|
15
|
+
/** The app's currently installed version, e.g. from its own version string. */
|
|
16
|
+
currentVersion: string;
|
|
17
|
+
/** Fetches the latest available release, or `null` if there is none. */
|
|
18
|
+
checkForUpdate: () => Promise<UpdateCheckRelease | null>;
|
|
19
|
+
/** Positive when `a` is newer than `b`, e.g. semver comparison. */
|
|
20
|
+
compareVersions: (a: string, b: string) => number;
|
|
21
|
+
/** Read once on mount: when the last check ran, and which version (if any) the user already dismissed. */
|
|
22
|
+
getLastCheck: () => {
|
|
23
|
+
lastCheckedAt: number | null;
|
|
24
|
+
dismissedVersion: string | null;
|
|
25
|
+
};
|
|
26
|
+
/** Called after each completed check (success or failure) so the caller can persist the timestamp. */
|
|
27
|
+
onChecked: (lastCheckedAt: number) => void;
|
|
28
|
+
/** Minimum delay between two checks. Defaults to 12h. */
|
|
29
|
+
minIntervalMs?: number;
|
|
30
|
+
now?: () => number;
|
|
31
|
+
}
|
|
32
|
+
export declare function useUpdateCheck({ currentVersion, checkForUpdate, compareVersions, getLastCheck, onChecked, minIntervalMs, now, }: UseUpdateCheckOptions): UpdateCheckState & {
|
|
33
|
+
dismiss: () => void;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=useUpdateCheck.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUpdateCheck.d.ts","sourceRoot":"","sources":["../src/useUpdateCheck.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,gBAAgB,GACxB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,GAClB;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,OAAO,EAAE,kBAAkB,CAAA;CAAE,GACpD;IAAE,MAAM,EAAE,OAAO,CAAA;CAAE,CAAC;AAExB,MAAM,WAAW,qBAAqB;IACpC,+EAA+E;IAC/E,cAAc,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,cAAc,EAAE,MAAM,OAAO,CAAC,kBAAkB,GAAG,IAAI,CAAC,CAAC;IACzD,mEAAmE;IACnE,eAAe,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAClD,0GAA0G;IAC1G,YAAY,EAAE,MAAM;QAClB,aAAa,EAAE,MAAM,GAAG,IAAI,CAAC;QAC7B,gBAAgB,EAAE,MAAM,GAAG,IAAI,CAAC;KACjC,CAAC;IACF,sGAAsG;IACtG,SAAS,EAAE,CAAC,aAAa,EAAE,MAAM,KAAK,IAAI,CAAC;IAC3C,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAUD,wBAAgB,cAAc,CAAC,EAC7B,cAAc,EACd,cAAc,EACd,eAAe,EACf,YAAY,EACZ,SAAS,EACT,aAAuC,EACvC,GAAc,GACf,EAAE,qBAAqB,GAAG,gBAAgB,GAAG;IAAE,OAAO,EAAE,MAAM,IAAI,CAAA;CAAE,CAyCpE"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useEffect, useState } from "react";
|
|
2
|
+
const DEFAULT_MIN_INTERVAL_MS = 12 * 60 * 60 * 1000;
|
|
3
|
+
// Checks once per mount (e.g. app launch) whether a newer release is
|
|
4
|
+
// available, throttled to at most one real network check per `minIntervalMs`
|
|
5
|
+
// and silent for a release the user already dismissed. Persistence of
|
|
6
|
+
// "when did we last check" / "which version did the user dismiss" is left
|
|
7
|
+
// entirely to the caller (`getLastCheck`/`onChecked`, plus its own dismiss
|
|
8
|
+
// handler) — this hook has no opinion on where that lives.
|
|
9
|
+
export function useUpdateCheck({ currentVersion, checkForUpdate, compareVersions, getLastCheck, onChecked, minIntervalMs = DEFAULT_MIN_INTERVAL_MS, now = Date.now, }) {
|
|
10
|
+
const [state, setState] = useState({ status: "idle" });
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
const { lastCheckedAt, dismissedVersion } = getLastCheck();
|
|
13
|
+
if (lastCheckedAt != null && now() - lastCheckedAt < minIntervalMs)
|
|
14
|
+
return;
|
|
15
|
+
let cancelled = false;
|
|
16
|
+
checkForUpdate()
|
|
17
|
+
.then((release) => {
|
|
18
|
+
if (cancelled)
|
|
19
|
+
return;
|
|
20
|
+
onChecked(now());
|
|
21
|
+
if (release &&
|
|
22
|
+
compareVersions(release.version, currentVersion) > 0 &&
|
|
23
|
+
release.version !== dismissedVersion) {
|
|
24
|
+
setState({ status: "available", release });
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
setState({ status: "idle" });
|
|
28
|
+
}
|
|
29
|
+
})
|
|
30
|
+
.catch(() => {
|
|
31
|
+
if (cancelled)
|
|
32
|
+
return;
|
|
33
|
+
onChecked(now());
|
|
34
|
+
setState({ status: "error" });
|
|
35
|
+
});
|
|
36
|
+
return () => {
|
|
37
|
+
cancelled = true;
|
|
38
|
+
};
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps, @eslint-react/exhaustive-deps -- runs once per mount by design (e.g. once per app launch); options are expected to be stable for the caller's lifetime.
|
|
40
|
+
}, []);
|
|
41
|
+
return {
|
|
42
|
+
...state,
|
|
43
|
+
dismiss: () => {
|
|
44
|
+
setState({ status: "idle" });
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@forthtilliath/expo-release-updates-ui",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/Forthtilliath/forthtilliath-packages.git",
|
|
12
|
+
"directory": "packages/expo-release-updates-ui"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/Forthtilliath/forthtilliath-packages/tree/main/packages/expo-release-updates-ui#readme",
|
|
15
|
+
"bugs": "https://github.com/Forthtilliath/forthtilliath-packages/issues",
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./dist/index.js",
|
|
21
|
+
"./*": "./dist/*.js"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@forthtilliath/expo-release-updates": "0.3.0"
|
|
25
|
+
},
|
|
26
|
+
"peerDependencies": {
|
|
27
|
+
"react": ">=19",
|
|
28
|
+
"react-native": ">=0.81"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/react": "^19.2.18",
|
|
32
|
+
"@types/react-test-renderer": "^19.1.0",
|
|
33
|
+
"eslint": "10.7.0",
|
|
34
|
+
"react": "^19.2.8",
|
|
35
|
+
"react-native": "0.86.0",
|
|
36
|
+
"react-test-renderer": "19.2.3",
|
|
37
|
+
"typescript": "^5.9.3",
|
|
38
|
+
"vitest": "^4.1.10",
|
|
39
|
+
"@forthtilliath/eslint-config": "0.4.2",
|
|
40
|
+
"@forthtilliath/typescript-config": "0.0.0"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"lint": "eslint . --max-warnings 0",
|
|
44
|
+
"check-types": "tsc --noEmit",
|
|
45
|
+
"clean": "rm -rf dist",
|
|
46
|
+
"dev": "tsc --watch -p tsconfig.build.json",
|
|
47
|
+
"build": "pnpm run clean && tsc -p tsconfig.build.json",
|
|
48
|
+
"test": "vitest run",
|
|
49
|
+
"test:watch": "vitest"
|
|
50
|
+
}
|
|
51
|
+
}
|