Skip to content

Commit bff958d

Browse files
committed
WIP: Building
1 parent 677eb64 commit bff958d

File tree

5 files changed

+205
-90
lines changed

5 files changed

+205
-90
lines changed

firestack.ios.js

Lines changed: 198 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,206 @@
22
* @providesModule Firestack
33
* @flow
44
*/
5-
'use strict';
5+
const FirebaseManager = require('firebase');
66

7-
var NativeFirestack = require('NativeModules').Firestack;
7+
const app = require('firebase/app');
8+
const db = require('firebase/database');
9+
const storage = require('firebase/storage');
810

9-
/**
10-
* High-level docs for the Firestack iOS API can be written here.
11-
*/
11+
import {NativeModules, NativeAppEventEmitter} from 'react-native';
12+
const FirebaseHelper = NativeModules.Firestack;
1213

13-
var Firestack = {
14-
test: function() {
15-
NativeFirestack.test();
16-
}
14+
const promisify = fn => (...args) => {
15+
return new Promise((resolve, reject) => {
16+
const handler = (err, resp) => err ? reject(err) : resolve(resp);
17+
args.push(handler);
18+
(typeof fn === 'function' ? fn : FirebaseHelper[fn])
19+
.call(FirebaseHelper, ...args);
20+
});
1721
};
1822

19-
module.exports = Firestack;
23+
export default class Firestack {
24+
constructor(options) {
25+
this.options = options;
26+
this.appInstance = app.initializeApp(options);
27+
this.configured = false;
28+
29+
this.eventHandlers = {};
30+
}
31+
32+
configure() {
33+
return promisify('configure')()
34+
.then((...args) => {
35+
this.configured = true;
36+
return args;
37+
});
38+
}
39+
40+
// Auth
41+
listenForAuth(callback) {
42+
const sub = this.on('listenForAuth', callback);
43+
FirebaseHelper.listenForAuth();
44+
return promisify(() => sub)(sub);
45+
}
46+
47+
unlistenForAuth() {
48+
this.off('listenForAuth');
49+
return promisify('unlistenForAuth')();
50+
}
51+
52+
/**
53+
* Create a user with the email/password functionality
54+
* @param {string} email The user's email
55+
* @param {string} password The user's password
56+
* @return {Promise} A promise indicating the completion
57+
*/
58+
createUserWithEmail(email, password) {
59+
return promisify('createUserWithEmail')(email, password);
60+
}
61+
62+
/**
63+
* Sign a user in with email/password
64+
* @param {string} email The user's email
65+
* @param {string} password The user's password
66+
* @return {Promise} A promise that is resolved upon completion
67+
*/
68+
signInWithEmail(email, password) {
69+
return promisify('signInWithEmail')(email, password);
70+
}
71+
72+
signInWithProvider(provider, authToken, authSecret) {
73+
return promisify('signInWithProvider')(provider, authToken, authSecret);
74+
}
75+
76+
77+
reauthenticateWithCredentialForProvider(provider, token, secret) {
78+
return promisify('reauthenticateWithCredentialForProvider')(provider, token, secret);
79+
}
80+
81+
82+
/**
83+
* Update the current user's email
84+
* @param {string} email The user's _new_ email
85+
* @return {Promise} A promise resolved upon completion
86+
*/
87+
updateUserEmail(email) {
88+
return promisify('updateUserEmail')(email);
89+
}
90+
91+
/**
92+
* Update the current user's password
93+
* @param {string} email the new password
94+
* @return {Promise}
95+
*/
96+
updatePassword(password) {
97+
return promisify('updateUserPassword')(password);
98+
}
99+
100+
/**
101+
* Send reset password instructions via email
102+
* @param {string} email The email to send password reset instructions
103+
*/
104+
sendPasswordResetWithEmail(email) {
105+
return promisify('sendPasswordResetWithEmail')(email);
106+
}
107+
108+
/**
109+
* Delete the current user
110+
* @return {Promise}
111+
*/
112+
deleteUser() {
113+
return promisify('deleteUser')()
114+
}
115+
116+
/**
117+
* Update the current user's profile
118+
* @param {Object} obj An object containing the keys listed [here](https://firebase.google.com/docs/auth/ios/manage-users#update_a_users_profile)
119+
* @return {Promise}
120+
*/
121+
updateUserProfile(obj) {
122+
return promisify('updateUserProfile')(obj);
123+
}
124+
125+
/**
126+
* Sign the current user out
127+
* @return {Promise}
128+
*/
129+
signOut() {
130+
return promisify('signOut')();
131+
}
132+
133+
/**
134+
* Get the currently signed in user
135+
* @return {Promise}
136+
*/
137+
getCurrentUser() {
138+
return promisify('getCurrentUser')();
139+
}
140+
141+
// Analytics
142+
/**
143+
* Log an event
144+
* @param {string} name The name of the event
145+
* @param {object} props An object containing string-keys
146+
* @return {Promise}
147+
*/
148+
logEventWithName(name, props) {
149+
return promisify('logEventWithName')(name, props);
150+
}
151+
152+
// Storage
153+
154+
/**
155+
* Configure the library to store the storage url
156+
* @param {string} url A string of your firebase storage url
157+
* @return {Promise}
158+
*/
159+
setStorageUrl(url) {
160+
return promisify('setStorageUrl')(url);
161+
}
162+
163+
/**
164+
* Upload a filepath
165+
* @param {string} name The destination for the file
166+
* @param {string} filepath The local path of the file
167+
* @param {object} metadata An object containing metadata
168+
* @return {Promise}
169+
*/
170+
uploadFile(name, filepath, metadata) {
171+
return promisify('uploadFile')(name, filepath, metadata);
172+
}
173+
174+
// database
175+
get database() {
176+
return db();
177+
}
178+
179+
/**
180+
* The native storage object provided by Firebase
181+
* @return {instance}
182+
*/
183+
get storage() {
184+
return storage();
185+
}
186+
187+
// other
188+
get ServerValue() {
189+
return db.ServerValue;
190+
}
191+
192+
on(name, cb) {
193+
if (!this.eventHandlers[name]) {
194+
this.eventHandlers[name] = [];
195+
}
196+
const sub = NativeAppEventEmitter.addListener(name, cb);
197+
this.eventHandlers[name].push(sub);
198+
return sub;
199+
}
200+
201+
off(name) {
202+
if (this.eventHandlers[name]) {
203+
this.eventHandlers.forEach(subscription => subscription.remove());
204+
}
205+
}
206+
207+
}

ios/Firestack.podspec

Lines changed: 0 additions & 61 deletions
This file was deleted.

ios/Firestack.xcodeproj/project.pbxproj

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
/* Begin PBXBuildFile section */
1010
D950369E1D19C77400F7094D /* Firestack.m in Sources */ = {isa = PBXBuildFile; fileRef = D950369D1D19C77400F7094D /* Firestack.m */; };
1111
D9FF4BF31D19F5FF00238046 /* libPods-Firestack.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D95036B81D19C90300F7094D /* libPods-Firestack.a */; };
12-
D9FF4BF51D19F61B00238046 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D9FF4BF41D19F61B00238046 /* libReact.a */; };
12+
D9FF4C211D19F96C00238046 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D9FF4C201D19F96C00238046 /* libReact.a */; };
1313
/* End PBXBuildFile section */
1414

1515
/* Begin PBXContainerItemProxy section */
@@ -41,17 +41,16 @@
4141
D950369C1D19C77400F7094D /* Firestack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = Firestack.h; path = Firestack/Firestack.h; sourceTree = "<group>"; };
4242
D950369D1D19C77400F7094D /* Firestack.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = Firestack.m; path = Firestack/Firestack.m; sourceTree = "<group>"; };
4343
D95036B31D19C90300F7094D /* Pods.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Pods.xcodeproj; path = Pods/Pods.xcodeproj; sourceTree = "<group>"; };
44-
D9FF4BEE1D19F3F500238046 /* libReact.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libReact.a; path = "../../../React/build/Debug-iphoneos/libReact.a"; sourceTree = "<group>"; };
45-
D9FF4BF41D19F61B00238046 /* libReact.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libReact.a; path = "../../../React/build/Debug-iphoneos/libReact.a"; sourceTree = "<group>"; };
44+
D9FF4C201D19F96C00238046 /* libReact.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libReact.a; path = "../../../React/build/Debug-iphoneos/libReact.a"; sourceTree = "<group>"; };
4645
/* End PBXFileReference section */
4746

4847
/* Begin PBXFrameworksBuildPhase section */
4948
58B511D81A9E6C8500147676 /* Frameworks */ = {
5049
isa = PBXFrameworksBuildPhase;
5150
buildActionMask = 2147483647;
5251
files = (
53-
D9FF4BF51D19F61B00238046 /* libReact.a in Frameworks */,
5452
D9FF4BF31D19F5FF00238046 /* libPods-Firestack.a in Frameworks */,
53+
D9FF4C211D19F96C00238046 /* libReact.a in Frameworks */,
5554
);
5655
runOnlyForDeploymentPostprocessing = 0;
5756
};
@@ -69,8 +68,7 @@
6968
4C361DE13748C14BF1F87624 /* Frameworks */ = {
7069
isa = PBXGroup;
7170
children = (
72-
D9FF4BF41D19F61B00238046 /* libReact.a */,
73-
D9FF4BEE1D19F3F500238046 /* libReact.a */,
71+
D9FF4C201D19F96C00238046 /* libReact.a */,
7472
D95036B31D19C90300F7094D /* Pods.xcodeproj */,
7573
);
7674
name = Frameworks;
Binary file not shown.

ios/Podfile

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,10 @@
11
# Uncomment this line to define a global platform for your project
2-
# platform :ios, '9.0'
2+
platform :ios, '8.0'
33

44
target 'Firestack' do
5-
# Uncomment this line if you're using Swift or would like to use dynamic frameworks
65
# use_frameworks!
76

8-
# Pods for Firestack
9-
# pod 'React', :path => '../node_modules/react-native'
10-
# pod 'Firestack', :path => '.'
11-
[ 'Firebase/Core',
12-
'Firebase/Analytics',
13-
'Firebase/Auth',
14-
'Firebase/Database',
15-
'Firebase/Storage'
16-
].each do |lib|
17-
pod lib
18-
end
7+
pod 'React', :path => '../node_modules/react-native'
8+
pod 'react-native-firestack', :path => '..'
199

2010
end

0 commit comments

Comments
 (0)