mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-04-22 19:57:51 +08:00
feat(remote-config): support minimumFetchInterval config setting (#2789)
Prior to this change the only RemoteConfig setting that was available is the isDeveloperModeEnabled setting. On iOS this setting causes react native firebase to call `initWithDeveloperModeEnabled` - which [is deprecated](https://github.com/firebase/firebase-ios-sdk/blob/master/FirebaseRemoteConfig/Sources/Public/FIRRemoteConfig.h#L148-L149) and appears to do nothing. This adds support for the minimumFetchInterval setting, which is the recommended way to control the fetch timeout now (on iOS at least)
This commit is contained in:
committed by
Mike Diarmid
parent
7cab58d87f
commit
57965e73a7
@@ -69,6 +69,10 @@ public class UniversalFirebaseConfigModule extends UniversalFirebaseModule {
|
||||
return Tasks.call(getExecutor(), () -> {
|
||||
FirebaseRemoteConfigSettings.Builder configSettingsBuilder = new FirebaseRemoteConfigSettings.Builder();
|
||||
configSettingsBuilder.setDeveloperModeEnabled(configSettings.getBoolean("isDeveloperModeEnabled"));
|
||||
if (configSettings.containsKey("minimumFetchInterval")) {
|
||||
double fetchInterval = configSettings.getDouble("minimumFetchInterval");
|
||||
configSettingsBuilder.setMinimumFetchIntervalInSeconds((long)fetchInterval);
|
||||
}
|
||||
FirebaseRemoteConfig.getInstance().setConfigSettings(configSettingsBuilder.build());
|
||||
return null;
|
||||
});
|
||||
@@ -174,6 +178,7 @@ public class UniversalFirebaseConfigModule extends UniversalFirebaseModule {
|
||||
appConstants.put("lastFetchTime", remoteConfigInfo.getFetchTimeMillis());
|
||||
appConstants.put("isDeveloperModeEnabled", remoteConfigSettings.isDeveloperModeEnabled());
|
||||
appConstants.put("lastFetchStatus", lastFetchStatusToString(remoteConfigInfo.getLastFetchStatus()));
|
||||
appConstants.put("minimumFetchInterval", remoteConfigSettings.getMinimumFetchIntervalInSeconds());
|
||||
|
||||
return appConstants;
|
||||
}
|
||||
|
||||
@@ -120,6 +120,14 @@ describe('remoteConfig()', () => {
|
||||
firebase.remoteConfig().isDeveloperModeEnabled.should.equal(false);
|
||||
});
|
||||
|
||||
it('minimumFetchInterval sets correctly', async () => {
|
||||
await firebase
|
||||
.remoteConfig()
|
||||
.setConfigSettings({ isDeveloperModeEnabled: true, minimumFetchInterval: 300 });
|
||||
|
||||
firebase.remoteConfig().minimumFetchInterval.should.be.equal(300);
|
||||
});
|
||||
|
||||
it('it throws if no args', async () => {
|
||||
try {
|
||||
await firebase.remoteConfig().setConfigSettings();
|
||||
@@ -151,6 +159,18 @@ describe('remoteConfig()', () => {
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
|
||||
it('throws if minimumFetchInterval is not a number', async () => {
|
||||
try {
|
||||
await firebase
|
||||
.remoteConfig()
|
||||
.setConfigSettings({ isDeveloperModeEnabled: true, minimumFetchInterval: 'potato' });
|
||||
return Promise.reject(new Error('Did not throw'));
|
||||
} catch (error) {
|
||||
error.message.should.containEql("'settings.minimumFetchInterval' must be a number value");
|
||||
return Promise.resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('getAll()', () => {
|
||||
|
||||
@@ -141,6 +141,11 @@ RCT_EXPORT_METHOD(setConfigSettings:
|
||||
) {
|
||||
FIRRemoteConfigSettings *remoteConfigSettings =
|
||||
[[FIRRemoteConfigSettings alloc] initWithDeveloperModeEnabled:[configSettings[@"isDeveloperModeEnabled"] boolValue]];
|
||||
|
||||
if ([configSettings objectForKey:@"minimumFetchInterval"]) {
|
||||
remoteConfigSettings.minimumFetchInterval = [configSettings[@"minimumFetchInterval"] doubleValue];
|
||||
}
|
||||
|
||||
[FIRRemoteConfig remoteConfig].configSettings = remoteConfigSettings;
|
||||
resolve([self resultWithConstants:[NSNull null]]);
|
||||
}
|
||||
@@ -184,6 +189,7 @@ RCT_EXPORT_METHOD(setDefaultsFromResource:
|
||||
NSDate *lastFetchTime = remoteConfig.lastFetchTime;
|
||||
BOOL isDeveloperModeEnabled = [RCTConvert BOOL:@([remoteConfig configSettings].isDeveloperModeEnabled)];
|
||||
NSString *lastFetchStatus = convertFIRRemoteConfigFetchStatusToNSString(remoteConfig.lastFetchStatus);
|
||||
double minimumFetchInterval = [RCTConvert double:@([remoteConfig configSettings].minimumFetchInterval)];
|
||||
|
||||
NSMutableDictionary *values = [NSMutableDictionary new];
|
||||
NSSet *keys = [[FIRRemoteConfig remoteConfig] keysWithPrefix:nil];
|
||||
@@ -205,6 +211,7 @@ RCT_EXPORT_METHOD(setDefaultsFromResource:
|
||||
@"lastFetchStatus": lastFetchStatus,
|
||||
@"isDeveloperModeEnabled": @(isDeveloperModeEnabled),
|
||||
@"lastFetchTime": @(round([lastFetchTime timeIntervalSince1970] * 1000.0)),
|
||||
@"minimumFetchInterval": @(minimumFetchInterval)
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
4
packages/remote-config/lib/index.d.ts
vendored
4
packages/remote-config/lib/index.d.ts
vendored
@@ -242,6 +242,10 @@ export namespace FirebaseRemoteConfigTypes {
|
||||
* experience.
|
||||
*/
|
||||
isDeveloperModeEnabled: boolean;
|
||||
/**
|
||||
* The time that remote config should cache flags for.
|
||||
*/
|
||||
minimumFetchInterval?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -119,6 +119,10 @@ class FirebaseConfigModule extends FirebaseModule {
|
||||
return this._isDeveloperModeEnabled;
|
||||
}
|
||||
|
||||
get minimumFetchInterval() {
|
||||
return this._minimumFetchInterval;
|
||||
}
|
||||
|
||||
setConfigSettings(settings = {}) {
|
||||
if (!isObject(settings) || !hasOwnProperty(settings, 'isDeveloperModeEnabled')) {
|
||||
throw new Error(
|
||||
@@ -132,6 +136,15 @@ class FirebaseConfigModule extends FirebaseModule {
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
hasOwnProperty(settings, 'minimumFetchInterval') &&
|
||||
!isNumber(settings.minimumFetchInterval)
|
||||
) {
|
||||
throw new Error(
|
||||
"firebase.remoteConfig().setConfigSettings(): 'settings.minimumFetchInterval' must be a number value.",
|
||||
);
|
||||
}
|
||||
|
||||
return this._promiseWithConstants(this.native.setConfigSettings(settings));
|
||||
}
|
||||
|
||||
@@ -197,6 +210,7 @@ class FirebaseConfigModule extends FirebaseModule {
|
||||
this._lastFetchStatus = constants.lastFetchStatus;
|
||||
this._values = convertNativeConfigValues(constants.values);
|
||||
this._isDeveloperModeEnabled = constants.isDeveloperModeEnabled;
|
||||
this._minimumFetchInterval = constants.minimumFetchInterval;
|
||||
}
|
||||
|
||||
_promiseWithConstants(promise) {
|
||||
|
||||
@@ -204,6 +204,10 @@ export interface ConfigSettings {
|
||||
* experience.
|
||||
*/
|
||||
isDeveloperModeEnabled: boolean;
|
||||
/**
|
||||
* The time that remote config should cache flags for.
|
||||
*/
|
||||
minimumFetchInterval?: number;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user