Skip to content

Commit a2cd599

Browse files
committed
Merge branch 'master' into anonymous
* master: Fixeds #62 2.3.1 Allow modular headers to be included Change asset upload to use data rather than file Bugfix in configuration using google-services.json Update README to include info about google-services.json Fix Android Storage, allow config via .json file
2 parents 3dfd285 + f1e6ff4 commit a2cd599

File tree

9 files changed

+75
-70
lines changed

9 files changed

+75
-70
lines changed

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,31 @@ Lastly, due to some dependencies requirements, Firestack supports iOS versions 8
200200

201201
### Android
202202

203-
There are several ways to setup Firebase on Android. The _easiest_ way is to pass the configuration settings in JavaScript. In that way, there is no setup for the native platform.
203+
There are several ways to setup Firebase on Android. The _easiest_ way is to pass the configuration settings in JavaScript. In that way, there is no setup for the native platform.
204204

205+
#### google-services.json setup
205206
If you prefer to include the default settings in the source of your app, download the `google-services.json` file provided by Firebase in the _Add Firebase to Android_ platform menu in your Firebase configuration console.
206207

208+
Next you'll have to add the google-services gradle plugin in order to parse it.
209+
210+
Add the google-services gradle plugin as a dependency in the *project* level build.gradle
211+
`android/build.gradle`
212+
```java
213+
buildscript {
214+
// ...
215+
dependencies {
216+
// ...
217+
classpath 'com.google.gms:google-services:3.0.0'
218+
}
219+
}
220+
```
221+
222+
In your app build.gradle file, add the gradle plugin at the VERY BOTTOM of the file (below all dependencies)
223+
`android/app/build.gradle`
224+
```java
225+
apply plugin: 'com.google.gms.google-services'
226+
```
227+
207228
## Usage
208229

209230
After creating a Firebase project and installing the library, we can use it in our project by importing the library in our JavaScript:

android/src/main/java/io/fullstack/firestack/FirestackModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public String setKeyOrDefault(
6666
final String val = params.getString(key);
6767
Log.d(TAG, "Setting " + key + " from params to: " + val);
6868
return val;
69-
} else if (defaultValue != null && defaultValue != "") {
69+
} else if (defaultValue != null && !defaultValue.equals("")) {
7070
Log.d(TAG, "Setting " + key + " from params to: " + defaultValue);
7171
return defaultValue;
7272
} else {

android/src/main/java/io/fullstack/firestack/FirestackStorage.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,16 @@ public String getName() {
6060
}
6161

6262
@ReactMethod
63-
public void downloadUrl(final String storageUrl,
63+
public void downloadUrl(final String javascriptStorageBucket,
6464
final String path,
6565
final Callback callback) {
6666
FirebaseStorage storage = FirebaseStorage.getInstance();
67+
String storageBucket = storage.getApp().getOptions().getStorageBucket();
68+
String storageUrl = "gs://"+storageBucket;
6769
StorageReference storageRef = storage.getReferenceFromUrl(storageUrl);
68-
StorageReference fileRef = storageRef.child(path);
70+
StorageReference fileRef = storageRef.child(path);
6971

70-
Task<Uri> downloadTask = storageRef.getDownloadUrl();
72+
Task<Uri> downloadTask = fileRef.getDownloadUrl();
7173
downloadTask.addOnSuccessListener(new OnSuccessListener<Uri>() {
7274
@Override
7375
public void onSuccess(Uri uri) {

ios/Firestack.xcodeproj/project.pbxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@
244244
58B511F01A9E6C8500147676 /* Debug */ = {
245245
isa = XCBuildConfiguration;
246246
buildSettings = {
247+
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES;
247248
DEFINES_MODULE = NO;
248249
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
249250
ENABLE_BITCODE = YES;
@@ -272,6 +273,7 @@
272273
58B511F11A9E6C8500147676 /* Release */ = {
273274
isa = XCBuildConfiguration;
274275
buildSettings = {
276+
CLANG_ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES;
275277
DEFINES_MODULE = NO;
276278
EMBEDDED_CONTENT_CONTAINS_SWIFT = NO;
277279
ENABLE_BITCODE = YES;

ios/Firestack/FirestackStorage.m

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,45 +53,36 @@ @implementation FirestackStorage
5353
return callback(@[err]);
5454
}
5555

56+
FIRStorageReference *storageRef = [[FIRStorage storage] referenceForURL:urlStr];
57+
FIRStorageReference *uploadRef = [storageRef child:name];
58+
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc] initWithDictionary:metadata];
59+
5660
if ([path hasPrefix:@"assets-library://"]) {
5761
NSURL *localFile = [[NSURL alloc] initWithString:path];
5862
PHFetchResult* assets = [PHAsset fetchAssetsWithALAssetURLs:@[localFile] options:nil];
5963
PHAsset *asset = [assets firstObject];
60-
[asset requestContentEditingInputWithOptions:nil
61-
completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
62-
NSURL *imageFile = contentEditingInput.fullSizeImageURL;
63-
64-
[self performUpload:urlStr
65-
name:name
66-
file:imageFile
67-
metadata:nil
68-
callback:callback];
69-
}];
64+
[[PHImageManager defaultManager] requestImageDataForAsset:asset
65+
options:nil
66+
resultHandler:^(NSData * imageData, NSString * dataUTI, UIImageOrientation orientation, NSDictionary * info) {
67+
FIRStorageUploadTask *uploadTask = [uploadRef putData:imageData
68+
metadata:firmetadata];
69+
[self addUploadObservers:uploadTask
70+
callback:callback];
71+
}];
7072
} else {
71-
NSURL *localFile = [NSURL fileURLWithPath:path];
72-
FIRStorageMetadata *firmetadata = [[FIRStorageMetadata alloc] initWithDictionary:metadata];
73+
NSURL *imageFile = [NSURL fileURLWithPath:path];
74+
FIRStorageUploadTask *uploadTask = [uploadRef putFile:imageFile
75+
metadata:firmetadata];
7376

74-
[self performUpload:urlStr
75-
name:name
76-
file:localFile
77-
metadata:firmetadata
78-
callback:callback];
77+
[self addUploadObservers:uploadTask
78+
callback:callback];
7979
}
8080

8181
}
8282

83-
- (void) performUpload:(NSString *) urlStr
84-
name:(NSString *) name
85-
file:(NSURL *) imageFile
86-
metadata:(FIRStorageMetadata *) firmetadata
87-
callback:(RCTResponseSenderBlock) callback
83+
- (void) addUploadObservers:(FIRStorageUploadTask *) uploadTask
84+
callback:(RCTResponseSenderBlock) callback
8885
{
89-
FIRStorageReference *storageRef = [[FIRStorage storage] referenceForURL:urlStr];
90-
FIRStorageReference *uploadRef = [storageRef child:name];
91-
92-
FIRStorageUploadTask *uploadTask = [uploadRef putFile:imageFile
93-
metadata:firmetadata];
94-
9586
// Listen for state changes, errors, and completion of the upload.
9687
[uploadTask observeStatus:FIRStorageTaskStatusResume handler:^(FIRStorageTaskSnapshot *snapshot) {
9788
// Upload resumed, also fires when the upload starts

lib/firestack.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export class Firestack extends Singleton {
3535

3636
instance.options = options || {};
3737
instance._debug = instance.options.debug || false;
38-
log = instance._log = new Log('firestack', instance._debug);
38+
39+
Log.enable(instance._debug);
40+
log = instance._log = new Log('firestack');
3941

4042
log.info('Creating new firestack instance');
4143

lib/modules/database.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class DatabaseRef extends ReferenceBase {
337337
}
338338

339339
get namespace() {
340-
return `firestack:dbRef:${this.dbPath()}`
340+
return `firestack:dbRef`
341341
}
342342
}
343343

lib/utils/log.js

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,44 @@
11
// document hack
22
import root from './window-or-global'
3+
4+
let bows;
35
(function (base) {
46
window = base || window
5-
if (!window.document) {
6-
window.document = { documentElement: { style: { WebkitAppearance: true } } }
7-
}
87
if(!window.localStorage) window.localStorage = {};
98
})(root);
109

11-
let debug = () => {};
10+
const levels = [
11+
'warn', 'info', 'error', 'debug'
12+
];
1213

1314
export class Log {
14-
constructor(namespace, enable) {
15+
constructor(namespace) {
1516
this._namespace = namespace || 'firestack';
16-
this.l = null;
1717
this.loggers = {};
18-
this.enabled = false;
19-
this.enable(enable);
18+
// Add the logging levels for each level
19+
levels
20+
.forEach(level => this[level] = (...args) => this._log(level)(...args));
2021
}
2122

22-
enable(booleanOrStringDebug) {
23-
window.localStorage.debug =
23+
static enable(booleanOrStringDebug) {
24+
window.localStorage.debug =
2425
typeof booleanOrStringDebug === 'string' ?
25-
booleanOrStringDebug :
26-
(booleanOrStringDebug ? '*' : booleanOrStringDebug);
27-
28-
this.enabled = !!window.localStorage.debug;
29-
}
30-
31-
info(...args) {
32-
this._logger('info')(...args);
33-
}
26+
(booleanOrStringDebug === '*' ? true : booleanOrStringDebug) :
27+
(booleanOrStringDebug instanceof RegExp ? booleanOrStringDebug.toString() : booleanOrStringDebug);
3428

35-
error(...args) {
36-
this._logger('error')(...args);
29+
window.localStorage.debugColors = !!window.localStorage.debug;
3730
}
3831

39-
debug(...args) {
40-
this._logger('debug')(...args);
41-
}
42-
43-
_logger(level) {
32+
_log(level) {
4433
if (!this.loggers[level]) {
45-
this.loggers[level] = this._debug()(`${this._namespace}:${level}`)
34+
(function() {
35+
const bows = require('bows');
36+
bows.config({ padLength: 20 });
37+
this.loggers[level] = bows(this._namespace, `[${level}]`);
38+
}.bind(this))();
4639
}
4740
return this.loggers[level];
4841
}
49-
50-
_debug() {
51-
if (!this.l) {
52-
this.l = debug = require('debug');
53-
}
54-
return this.l;
55-
}
5642
}
5743

5844
export default Log;

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-firestack",
3-
"version": "2.3.0",
3+
"version": "2.3.1",
44
"author": "Ari Lerner <ari@fullstack.io> (https://fullstackreact.com)",
55
"description": "A firebase v3 adapter",
66
"main": "index",
@@ -67,6 +67,7 @@
6767
"sinon": "^2.0.0-pre.2"
6868
},
6969
"dependencies": {
70+
"bows": "^1.6.0",
7071
"es6-symbol": "^3.1.0"
7172
}
7273
}

0 commit comments

Comments
 (0)