Skip to content

Commit

Permalink
feat(remote-config): support minimumFetchInterval config setting (#2789)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
obmarg authored and Salakar committed Nov 23, 2019
1 parent 7cab58d commit 57965e7
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
Expand Up @@ -69,6 +69,10 @@ Task<Void> setConfigSettings(Bundle configSettings) {
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;
});
Expand Down Expand Up @@ -174,6 +178,7 @@ public Map<String, Object> getConstantsForApp(String appName) {
appConstants.put("lastFetchTime", remoteConfigInfo.getFetchTimeMillis());
appConstants.put("isDeveloperModeEnabled", remoteConfigSettings.isDeveloperModeEnabled());
appConstants.put("lastFetchStatus", lastFetchStatusToString(remoteConfigInfo.getLastFetchStatus()));
appConstants.put("minimumFetchInterval", remoteConfigSettings.getMinimumFetchIntervalInSeconds());

return appConstants;
}
Expand Down
20 changes: 20 additions & 0 deletions packages/remote-config/e2e/config.e2e.js
Expand Up @@ -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();
Expand Down Expand Up @@ -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()', () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/remote-config/ios/RNFBConfig/RNFBConfigModule.m
Expand Up @@ -141,6 +141,11 @@ + (BOOL)requiresMainQueueSetup {
) {
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]]);
}
Expand Down Expand Up @@ -184,6 +189,7 @@ - (NSDictionary *)getConstantsForApp {
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];
Expand All @@ -205,6 +211,7 @@ - (NSDictionary *)getConstantsForApp {
@"lastFetchStatus": lastFetchStatus,
@"isDeveloperModeEnabled": @(isDeveloperModeEnabled),
@"lastFetchTime": @(round([lastFetchTime timeIntervalSince1970] * 1000.0)),
@"minimumFetchInterval": @(minimumFetchInterval)
};
}

Expand Down
4 changes: 4 additions & 0 deletions packages/remote-config/lib/index.d.ts
Expand Up @@ -242,6 +242,10 @@ export namespace FirebaseRemoteConfigTypes {
* experience.
*/
isDeveloperModeEnabled: boolean;
/**
* The time that remote config should cache flags for.
*/
minimumFetchInterval?: number;
}

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/remote-config/lib/index.js
Expand Up @@ -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(
Expand All @@ -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));
}

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions packages/remote-config/lib/index.js.flow
Expand Up @@ -204,6 +204,10 @@ export interface ConfigSettings {
* experience.
*/
isDeveloperModeEnabled: boolean;
/**
* The time that remote config should cache flags for.
*/
minimumFetchInterval?: number;
}

/**
Expand Down

0 comments on commit 57965e7

Please sign in to comment.