Skip to content

Commit f8f698f

Browse files
chrisbobbegnprice
authored andcommitted
reactNativeUtils: Add 'unknown' branch to AppStateValues
As of writing, we've seen this reported to Sentry from two installs of the app on iOS 16.2. useAppState's callers don't try to take meaning from the returned value, they just use it in a useEffect dependency array. So they don't have to grow special logic to handle the new branch.
1 parent 074a99c commit f8f698f

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/reactNativeUtils.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import React from 'react';
44
import { AppState, Platform } from 'react-native';
5-
import type { AppStateValues } from 'react-native/Libraries/AppState/AppState';
5+
import type { AppStateValues as AppStateValuesBusted } from 'react-native/Libraries/AppState/AppState';
66
// eslint-disable-next-line id-match
77
import type { ____ViewStyle_Internal } from 'react-native/Libraries/StyleSheet/StyleSheetTypes';
88
import invariant from 'invariant';
@@ -28,12 +28,16 @@ export type ViewStylePropWithout<T: { ... }> = GenericStyleProp<
2828
$ReadOnly<$Shape<BoundedDiff<____ViewStyle_Internal, T>>>,
2929
>;
3030

31+
/**
32+
* Documented app-state values, plus any we've seen in the wild.
33+
*/
34+
type AppStateValues = AppStateValuesBusted | 'unknown';
35+
3136
/**
3237
* A hook for AppState's current state value, updated on 'change' events.
3338
*
34-
* Gives `null` if the state isn't one of the documented values
35-
* (AppStateValues), which the upstream types allow for the initial value,
36-
* and logs to Sentry in that unexpected case.
39+
* Gives `null` if the state isn't one of the expected values
40+
* (AppStateValues), and logs to Sentry in that case.
3741
*/
3842
export function useAppState(): null | AppStateValues {
3943
// Upstream has `?string`… probably they mean `AppStateValues`, but we'll
@@ -48,10 +52,11 @@ export function useAppState(): null | AppStateValues {
4852
|| (typeof initialState === 'string'
4953
&& initialState !== 'inactive'
5054
&& initialState !== 'background'
51-
&& initialState !== 'active')
55+
&& initialState !== 'active'
56+
&& initialState !== 'unknown')
5257
) {
5358
// If Flow errors here, adjust cases in the conditional.
54-
typesEquivalent<AppStateValues, 'inactive' | 'background' | 'active'>();
59+
typesEquivalent<AppStateValues, 'inactive' | 'background' | 'active' | 'unknown'>();
5560
logging.warn(`Unexpected AppState.currentState: ${initialState?.toString() ?? '[nullish]'}`);
5661
initialState = null;
5762
}

0 commit comments

Comments
 (0)