From fe8c486dcb40c4fae2815ffacebd8bf630ea78e6 Mon Sep 17 00:00:00 2001 From: Elliot Hesp Date: Tue, 23 May 2017 14:53:19 +0100 Subject: [PATCH] [config] Added setDefaultsFromResource method --- .../firebase/config/RNFirebaseRemoteConfig.java | 5 +++++ docs/modules/config.md | 16 +++++++++++++++- ios/RNFirebase/RNFirebaseRemoteConfig.m | 2 +- lib/modules/config/index.js | 10 +++++----- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/android/src/main/java/io/invertase/firebase/config/RNFirebaseRemoteConfig.java b/android/src/main/java/io/invertase/firebase/config/RNFirebaseRemoteConfig.java index daeb68ec..3300a2cd 100644 --- a/android/src/main/java/io/invertase/firebase/config/RNFirebaseRemoteConfig.java +++ b/android/src/main/java/io/invertase/firebase/config/RNFirebaseRemoteConfig.java @@ -110,6 +110,11 @@ public class RNFirebaseRemoteConfig extends ReactContextBaseJavaModule { FirebaseRemoteConfig.getInstance().setDefaults(convertedMap); } + @ReactMethod + public void setDefaultsFromResource(int resourceId) { + FirebaseRemoteConfig.getInstance().setDefaults(resourceId); + } + private void fetchInternal(final Promise promise, Boolean withExpiration, long expirationDuration) { FirebaseRemoteConfig.getInstance().fetch(withExpiration ? expirationDuration : 43200) // 12 hours default .addOnCompleteListener(new OnCompleteListener() { diff --git a/docs/modules/config.md b/docs/modules/config.md index 09de81d0..0e4fb5eb 100644 --- a/docs/modules/config.md +++ b/docs/modules/config.md @@ -98,10 +98,24 @@ Returns all keys as an array by a prefix. If no prefix is defined all keys are r firebase.config() .getKeysByPrefix() .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 ```js diff --git a/ios/RNFirebase/RNFirebaseRemoteConfig.m b/ios/RNFirebase/RNFirebaseRemoteConfig.m index c41e6727..9978c6ff 100644 --- a/ios/RNFirebase/RNFirebaseRemoteConfig.m +++ b/ios/RNFirebase/RNFirebaseRemoteConfig.m @@ -145,7 +145,7 @@ RCT_EXPORT_METHOD(setDefaults:(NSDictionary *)defaults) [self.remoteConfig setDefaults:defaults]; } -RCT_EXPORT_METHOD(setDefaultsFromPlistFileName:(NSString *)fileName) +RCT_EXPORT_METHOD(setDefaultsFromResource:(NSString *)fileName) { [self.remoteConfig setDefaultsFromPlistFileName:fileName]; } diff --git a/lib/modules/config/index.js b/lib/modules/config/index.js index b8acf788..f2a8b36b 100644 --- a/lib/modules/config/index.js +++ b/lib/modules/config/index.js @@ -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() { if (!this.developerModeEnabled) { this.log.debug('Enabled developer mode'); @@ -137,9 +137,9 @@ export default class RemoteConfig extends Base { /** * 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) { - FirebaseRemoteConfig.setDefaultsFromPlistFileName(filename); + setDefaultsFromResource(resource: String | number) { + FirebaseRemoteConfig.setDefaultsFromResource(resource); } }