@smartcrab/react-native 0.3.0 → 0.3.1
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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AppStatePort } from "../lifecycle-ports.js";
|
|
2
2
|
/**
|
|
3
3
|
* Default `AppStatePort`: React Native's own `AppState` (design.md §21.1,
|
|
4
|
-
* §21.7). RN
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* §21.7). RN 0.87 widens `AppState.currentState` to include `null`,
|
|
5
|
+
* `undefined`, and arbitrary strings. Pass through known lifecycle states and
|
|
6
|
+
* map anything else to `unknown` to preserve this package's narrower contract.
|
|
7
7
|
*/
|
|
8
8
|
export declare const reactNativeAppStatePort: AppStatePort;
|
|
@@ -1,13 +1,22 @@
|
|
|
1
1
|
import { AppState } from "react-native";
|
|
2
|
+
const KNOWN_APP_STATES = new Set([
|
|
3
|
+
"active",
|
|
4
|
+
"background",
|
|
5
|
+
"inactive",
|
|
6
|
+
"unknown",
|
|
7
|
+
"extension",
|
|
8
|
+
]);
|
|
9
|
+
const isAppStateStatus = (value) => KNOWN_APP_STATES.has(value);
|
|
2
10
|
/**
|
|
3
11
|
* Default `AppStatePort`: React Native's own `AppState` (design.md §21.1,
|
|
4
|
-
* §21.7). RN
|
|
5
|
-
*
|
|
6
|
-
*
|
|
12
|
+
* §21.7). RN 0.87 widens `AppState.currentState` to include `null`,
|
|
13
|
+
* `undefined`, and arbitrary strings. Pass through known lifecycle states and
|
|
14
|
+
* map anything else to `unknown` to preserve this package's narrower contract.
|
|
7
15
|
*/
|
|
8
16
|
export const reactNativeAppStatePort = {
|
|
9
17
|
get currentState() {
|
|
10
|
-
|
|
18
|
+
const state = AppState.currentState;
|
|
19
|
+
return state != null && isAppStateStatus(state) ? state : "unknown";
|
|
11
20
|
},
|
|
12
21
|
addEventListener: (type, handler) => AppState.addEventListener(type, handler),
|
|
13
22
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartcrab/react-native",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@smartcrab/contracts-public": "0.3.
|
|
37
|
+
"@smartcrab/contracts-public": "0.3.1"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"react": ">=19",
|
|
@@ -50,16 +50,16 @@
|
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"typescript": "5.9.3",
|
|
52
52
|
"vitest": "4.1.11",
|
|
53
|
-
"react": "19.
|
|
54
|
-
"react-native": "0.
|
|
55
|
-
"expo": "57.0.
|
|
56
|
-
"expo-secure-store": "57.0.
|
|
57
|
-
"expo-web-browser": "57.0.
|
|
58
|
-
"expo-auth-session": "57.0.
|
|
59
|
-
"expo-linking": "57.0.
|
|
60
|
-
"expo-crypto": "57.0.
|
|
61
|
-
"react-native-passkeys": "0.4.
|
|
62
|
-
"@types/react": "19.
|
|
53
|
+
"react": "19.3.0",
|
|
54
|
+
"react-native": "0.87.1",
|
|
55
|
+
"expo": "57.0.27",
|
|
56
|
+
"expo-secure-store": "57.0.4",
|
|
57
|
+
"expo-web-browser": "57.0.3",
|
|
58
|
+
"expo-auth-session": "57.0.14",
|
|
59
|
+
"expo-linking": "57.0.12",
|
|
60
|
+
"expo-crypto": "57.0.3",
|
|
61
|
+
"react-native-passkeys": "0.4.2",
|
|
62
|
+
"@types/react": "19.3.0"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"typecheck": "tsc --noEmit",
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
import { AppState } from "react-native";
|
|
2
|
-
import type { AppStatePort } from "../lifecycle-ports.js";
|
|
2
|
+
import type { AppStatePort, AppStateStatus } from "../lifecycle-ports.js";
|
|
3
|
+
|
|
4
|
+
const KNOWN_APP_STATES: ReadonlySet<string> = new Set<AppStateStatus>([
|
|
5
|
+
"active",
|
|
6
|
+
"background",
|
|
7
|
+
"inactive",
|
|
8
|
+
"unknown",
|
|
9
|
+
"extension",
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const isAppStateStatus = (value: string): value is AppStateStatus => KNOWN_APP_STATES.has(value);
|
|
3
13
|
|
|
4
14
|
/**
|
|
5
15
|
* Default `AppStatePort`: React Native's own `AppState` (design.md §21.1,
|
|
6
|
-
* §21.7). RN
|
|
7
|
-
*
|
|
8
|
-
*
|
|
16
|
+
* §21.7). RN 0.87 widens `AppState.currentState` to include `null`,
|
|
17
|
+
* `undefined`, and arbitrary strings. Pass through known lifecycle states and
|
|
18
|
+
* map anything else to `unknown` to preserve this package's narrower contract.
|
|
9
19
|
*/
|
|
10
20
|
export const reactNativeAppStatePort: AppStatePort = {
|
|
11
21
|
get currentState() {
|
|
12
|
-
|
|
22
|
+
const state = AppState.currentState;
|
|
23
|
+
return state != null && isAppStateStatus(state) ? state : "unknown";
|
|
13
24
|
},
|
|
14
25
|
addEventListener: (type, handler) => AppState.addEventListener(type, handler),
|
|
15
26
|
};
|