2
0
mirror of synced 2025-01-10 22:26:02 +00:00

[config] Added setDefaultsFromResource method

This commit is contained in:
Elliot Hesp 2017-05-23 14:53:19 +01:00
parent d8a0ebb084
commit fe8c486dcb
4 changed files with 26 additions and 7 deletions

View File

@ -110,6 +110,11 @@ public class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule {
FirebaseRemoteConfig.getInstance().setDefaults(convertedMap); FirebaseRemoteConfig.getInstance().setDefaults(convertedMap);
} }
@ReactMethod
public void setDefaultsFromResource(int resourceId) {
FirebaseRemoteConfig.getInstance().setDefaults(resourceId);
}
private void fetchInternal(final Promise promise, Boolean withExpiration, long expirationDuration) { private void fetchInternal(final Promise promise, Boolean withExpiration, long expirationDuration) {
FirebaseRemoteConfig.getInstance().fetch(withExpiration ? expirationDuration : 43200) // 12 hours default FirebaseRemoteConfig.getInstance().fetch(withExpiration ? expirationDuration : 43200) // 12 hours default
.addOnCompleteListener(new OnCompleteListener<Void>() { .addOnCompleteListener(new OnCompleteListener<Void>() {

View File

@ -98,10 +98,24 @@ Returns all keys as an array by a prefix. If no prefix is defined all keys are r
firebase.config() firebase.config()
.getKeysByPrefix() .getKeysByPrefix()
.then((keys) => { .then((keys) => {
console.log('Current keys: ', keys);
}); });
``` ```
### setDefaultsFromResource(filename: `String`)
Sets the default values from a resource:
* Android: Id for the XML resource, which should be in your application's res/xml folder.
* iOS: The plist file name, with no file name extension
```js
// Anrdoid
firebase.config().setDefaultsFromResource(1337);
// iOS
firebase.config().setDefaultsFromResource('configDefaults');
```
## Usage ## Usage
```js ```js

View File

@ -145,7 +145,7 @@ RCT_EXPORT_METHOD(setDefaults:(NSDictionary *)defaults)
[self.remoteConfig setDefaults:defaults]; [self.remoteConfig setDefaults:defaults];
} }
RCT_EXPORT_METHOD(setDefaultsFromPlistFileName:(NSString *)fileName) RCT_EXPORT_METHOD(setDefaultsFromResource:(NSString *)fileName)
{ {
[self.remoteConfig setDefaultsFromPlistFileName:fileName]; [self.remoteConfig setDefaultsFromPlistFileName:fileName];
} }

View File

@ -38,8 +38,8 @@ export default class RemoteConfig extends Base {
} }
/** /**
* Enable Remote Config developer mode to allow for frequent refreshes of the cache * Enable Remote Config developer mode to allow for frequent refreshes of the cache
*/ */
enableDeveloperMode() { enableDeveloperMode() {
if (!this.developerModeEnabled) { if (!this.developerModeEnabled) {
this.log.debug('Enabled developer mode'); this.log.debug('Enabled developer mode');
@ -137,9 +137,9 @@ export default class RemoteConfig extends Base {
/** /**
* Sets default configs from plist for default namespace; * Sets default configs from plist for default namespace;
* @param filename: The plist file name, with no file name extension * @param resource: The plist file name or resource ID
*/ */
setDefaultsFromPlistFileName(filename: String) { setDefaultsFromResource(resource: String | number) {
FirebaseRemoteConfig.setDefaultsFromPlistFileName(filename); FirebaseRemoteConfig.setDefaultsFromResource(resource);
} }
} }