Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3749259
D8652.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D8652.diff
View Options
diff --git a/native/components/feature-flags-provider.react.js b/native/components/feature-flags-provider.react.js
--- a/native/components/feature-flags-provider.react.js
+++ b/native/components/feature-flags-provider.react.js
@@ -1,5 +1,6 @@
// @flow
+import AsyncStorage from '@react-native-async-storage/async-storage';
import * as React from 'react';
import { Platform } from 'react-native';
@@ -14,17 +15,19 @@
type FeatureFlagsContextType = {
+configuration: FeatureFlagsConfiguration,
- +loaded: boolean,
+ +loadedFromService: boolean,
};
const defaultContext = {
configuration: {},
- loaded: false,
+ loadedFromService: false,
};
const FeatureFlagsContext: React.Context<FeatureFlagsContextType> =
React.createContext<FeatureFlagsContextType>(defaultContext);
+const featureFlagsStorageKey = 'FeatureFlags';
+
type Props = {
+children: React.Node,
};
@@ -33,6 +36,31 @@
const isStaff = useIsCurrentUserStaff();
const [featuresConfig, setFeaturesConfig] = React.useState(defaultContext);
+
+ React.useEffect(() => {
+ (async () => {
+ if (featuresConfig.loadedFromService) {
+ return;
+ }
+
+ const persistedFeaturesConfig = await AsyncStorage.getItem(
+ featureFlagsStorageKey,
+ );
+ if (!persistedFeaturesConfig) {
+ return;
+ }
+
+ setFeaturesConfig(config =>
+ config.loadedFromService
+ ? config
+ : {
+ configuration: JSON.parse(persistedFeaturesConfig),
+ loadedFromService: false,
+ },
+ );
+ })();
+ }, [featuresConfig.loadedFromService]);
+
React.useEffect(() => {
(async () => {
try {
@@ -47,8 +75,12 @@
}
setFeaturesConfig({
configuration,
- loaded: true,
+ loadedFromService: true,
});
+ await AsyncStorage.setItem(
+ featureFlagsStorageKey,
+ JSON.stringify(configuration),
+ );
} catch (e) {
console.error('Feature flag retrieval failed:', e);
}
@@ -62,4 +94,4 @@
);
}
-export { FeatureFlagsContext, FeatureFlagsProvider };
+export { FeatureFlagsContext, FeatureFlagsProvider, featureFlagsStorageKey };
diff --git a/native/utils/crash-utils.js b/native/utils/crash-utils.js
--- a/native/utils/crash-utils.js
+++ b/native/utils/crash-utils.js
@@ -4,6 +4,7 @@
import sleep from 'lib/utils/sleep.js';
+import { featureFlagsStorageKey } from '../components/feature-flags-provider.react.js';
import { commCoreModule } from '../native-modules.js';
import { navStateAsyncStorageKey } from '../navigation/persistance.js';
import { getPersistor } from '../redux/persist.js';
@@ -13,6 +14,7 @@
getPersistor().purge(),
__DEV__ ? AsyncStorage.removeItem(navStateAsyncStorageKey) : null,
AsyncStorage.removeItem('ANDROID_REFERRER'),
+ AsyncStorage.removeItem(featureFlagsStorageKey),
]);
await sleep(50);
commCoreModule.terminate();
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jan 10, 9:02 PM (18 h, 31 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2855374
Default Alt Text
D8652.diff (2 KB)
Attached To
Mode
D8652: [native] Cache feature flags config
Attached
Detach File
Event Timeline
Log In to Comment