@react-native-firebase/app 23.8.0 → 23.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1541 -0
- package/RNFBApp.podspec +49 -0
- package/android/.editorconfig +10 -0
- package/android/build.gradle +129 -0
- package/android/firebase-json.gradle +73 -0
- package/android/gradle.properties +2 -0
- package/android/lint.xml +5 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +24 -0
- package/android/src/main/java/io/invertase/firebase/app/.gitkeep +0 -0
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.java +124 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebaseModule.java +62 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebasePreferences.java +91 -0
- package/android/src/main/java/io/invertase/firebase/interfaces/.gitkeep +0 -0
- package/android/src/reactnative/AndroidManifest.xml +2 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseApp.java +46 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppInitProvider.java +22 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppModule.java +186 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackage.java +49 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java +35 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseVersion.java +22 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java +191 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEvent.java +53 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.java +151 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseInitProvider.java +78 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseJSON.java +107 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseMeta.java +93 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java +146 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebasePreferences.java +88 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java +440 -0
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/ContextProvider.java +30 -0
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/NativeError.java +32 -0
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/NativeEvent.java +28 -0
- package/android/src/reactnative/java/io/invertase/firebase/utils/ReactNativeFirebaseUtilsModule.java +191 -0
- package/app.plugin.js +1 -0
- package/dist/commonjs/version.js +1 -1
- package/dist/module/version.js +1 -1
- package/dist/typescript/commonjs/lib/modular.d.ts +1 -1
- package/dist/typescript/commonjs/lib/version.d.ts +1 -1
- package/dist/typescript/module/lib/modular.d.ts +1 -1
- package/dist/typescript/module/lib/version.d.ts +1 -1
- package/firebase-schema.json +149 -0
- package/firebase_json.rb +72 -0
- package/ios/RNFBApp/RCTConvert+FIRApp.h +23 -0
- package/ios/RNFBApp/RCTConvert+FIRApp.m +31 -0
- package/ios/RNFBApp/RCTConvert+FIROptions.h +23 -0
- package/ios/RNFBApp/RCTConvert+FIROptions.m +36 -0
- package/ios/RNFBApp/RNFBAppModule.h +28 -0
- package/ios/RNFBApp/RNFBAppModule.m +305 -0
- package/ios/RNFBApp/RNFBJSON.h +36 -0
- package/ios/RNFBApp/RNFBJSON.m +99 -0
- package/ios/RNFBApp/RNFBMeta.h +30 -0
- package/ios/RNFBApp/RNFBMeta.m +61 -0
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.h +47 -0
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.m +74 -0
- package/ios/RNFBApp/RNFBPreferences.h +44 -0
- package/ios/RNFBApp/RNFBPreferences.m +94 -0
- package/ios/RNFBApp/RNFBRCTEventEmitter.h +73 -0
- package/ios/RNFBApp/RNFBRCTEventEmitter.m +151 -0
- package/ios/RNFBApp/RNFBSharedUtils.h +67 -0
- package/ios/RNFBApp/RNFBSharedUtils.m +285 -0
- package/ios/RNFBApp/RNFBUtilsModule.h +30 -0
- package/ios/RNFBApp/RNFBUtilsModule.m +100 -0
- package/ios/RNFBApp/RNFBVersion.h +20 -0
- package/ios/RNFBApp/RNFBVersion.m +21 -0
- package/ios/RNFBApp.xcodeproj/project.pbxproj +411 -0
- package/ios/RNFBApp.xcodeproj/xcshareddata/IDETemplateMacros.plist +24 -0
- package/ios_config.sh +269 -0
- package/lib/version.ts +1 -1
- package/package.json +3 -10
- package/plugin/build/android/applyPlugin.d.ts +6 -0
- package/plugin/build/android/applyPlugin.js +29 -0
- package/plugin/build/android/buildscriptDependency.d.ts +6 -0
- package/plugin/build/android/buildscriptDependency.js +31 -0
- package/plugin/build/android/constants.d.ts +4 -0
- package/plugin/build/android/constants.js +8 -0
- package/plugin/build/android/copyGoogleServices.d.ts +5 -0
- package/plugin/build/android/copyGoogleServices.js +33 -0
- package/plugin/build/android/index.d.ts +4 -0
- package/plugin/build/android/index.js +9 -0
- package/plugin/build/index.d.ts +3 -0
- package/plugin/build/index.js +21 -0
- package/plugin/build/ios/appDelegate.d.ts +6 -0
- package/plugin/build/ios/appDelegate.js +116 -0
- package/plugin/build/ios/googleServicesPlist.d.ts +7 -0
- package/plugin/build/ios/googleServicesPlist.js +42 -0
- package/plugin/build/ios/index.d.ts +3 -0
- package/plugin/build/ios/index.js +7 -0
- package/plugin/src/android/applyPlugin.ts +30 -0
- package/plugin/src/android/buildscriptDependency.ts +33 -0
- package/plugin/src/android/constants.ts +7 -0
- package/plugin/src/android/copyGoogleServices.ts +36 -0
- package/plugin/src/android/index.ts +5 -0
- package/plugin/src/index.ts +27 -0
- package/plugin/src/ios/appDelegate.ts +140 -0
- package/plugin/src/ios/googleServicesPlist.ts +55 -0
- package/plugin/src/ios/index.ts +4 -0
- package/plugin/tsconfig.json +9 -0
- package/plugin/tsconfig.tsbuildinfo +1 -0
- package/react-native.config.js +19 -0
- package/tsconfig.json +10 -0
package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppModule.java
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
package io.invertase.firebase.app;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.util.Log;
|
|
21
|
+
import com.facebook.react.bridge.Promise;
|
|
22
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
23
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
24
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
25
|
+
import com.facebook.react.bridge.WritableMap;
|
|
26
|
+
import com.google.firebase.FirebaseApp;
|
|
27
|
+
import io.invertase.firebase.common.RCTConvertFirebase;
|
|
28
|
+
import io.invertase.firebase.common.ReactNativeFirebaseEvent;
|
|
29
|
+
import io.invertase.firebase.common.ReactNativeFirebaseEventEmitter;
|
|
30
|
+
import io.invertase.firebase.common.ReactNativeFirebaseJSON;
|
|
31
|
+
import io.invertase.firebase.common.ReactNativeFirebaseMeta;
|
|
32
|
+
import io.invertase.firebase.common.ReactNativeFirebaseModule;
|
|
33
|
+
import io.invertase.firebase.common.ReactNativeFirebasePreferences;
|
|
34
|
+
import java.util.ArrayList;
|
|
35
|
+
import java.util.HashMap;
|
|
36
|
+
import java.util.List;
|
|
37
|
+
import java.util.Map;
|
|
38
|
+
|
|
39
|
+
public class ReactNativeFirebaseAppModule extends ReactNativeFirebaseModule {
|
|
40
|
+
private static final String TAG = "App";
|
|
41
|
+
|
|
42
|
+
public static Map<String, String> authDomains = new HashMap<>();
|
|
43
|
+
|
|
44
|
+
ReactNativeFirebaseAppModule(ReactApplicationContext reactContext) {
|
|
45
|
+
super(reactContext, TAG);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Override
|
|
49
|
+
public void initialize() {
|
|
50
|
+
super.initialize();
|
|
51
|
+
ReactNativeFirebaseEventEmitter.getSharedInstance().attachReactContext(getContext());
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@ReactMethod
|
|
55
|
+
public void initializeApp(ReadableMap options, ReadableMap appConfig, Promise promise) {
|
|
56
|
+
FirebaseApp firebaseApp =
|
|
57
|
+
RCTConvertFirebase.readableMapToFirebaseApp(options, appConfig, getContext());
|
|
58
|
+
ReactNativeFirebaseAppModule.configureAuthDomain(
|
|
59
|
+
appConfig.getString("name"), options.getString("authDomain"));
|
|
60
|
+
|
|
61
|
+
WritableMap firebaseAppMap = RCTConvertFirebase.firebaseAppToWritableMap(firebaseApp);
|
|
62
|
+
promise.resolve(firebaseAppMap);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public static void configureAuthDomain(String name, String authDomain) {
|
|
66
|
+
if (authDomain != null) {
|
|
67
|
+
Log.d(TAG, name + " custom authDomain " + authDomain);
|
|
68
|
+
authDomains.put(name, authDomain);
|
|
69
|
+
} else {
|
|
70
|
+
authDomains.remove(name);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@ReactMethod
|
|
75
|
+
public void setAutomaticDataCollectionEnabled(String appName, Boolean enabled) {
|
|
76
|
+
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
|
77
|
+
firebaseApp.setDataCollectionDefaultEnabled(enabled);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@ReactMethod
|
|
81
|
+
public void deleteApp(String appName, Promise promise) {
|
|
82
|
+
FirebaseApp firebaseApp = FirebaseApp.getInstance(appName);
|
|
83
|
+
|
|
84
|
+
if (firebaseApp != null) {
|
|
85
|
+
firebaseApp.delete();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
promise.resolve(null);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@ReactMethod
|
|
92
|
+
public void eventsNotifyReady(Boolean ready) {
|
|
93
|
+
ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
|
|
94
|
+
emitter.notifyJsReady(ready);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@ReactMethod
|
|
98
|
+
public void eventsGetListeners(Promise promise) {
|
|
99
|
+
ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
|
|
100
|
+
promise.resolve(emitter.getListenersMap());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@ReactMethod
|
|
104
|
+
public void eventsPing(String eventName, ReadableMap eventBody, Promise promise) {
|
|
105
|
+
ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
|
|
106
|
+
emitter.sendEvent(
|
|
107
|
+
new ReactNativeFirebaseEvent(
|
|
108
|
+
eventName, RCTConvertFirebase.readableMapToWritableMap(eventBody)));
|
|
109
|
+
promise.resolve(RCTConvertFirebase.readableMapToWritableMap(eventBody));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@ReactMethod
|
|
113
|
+
public void eventsAddListener(String eventName) {
|
|
114
|
+
ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
|
|
115
|
+
emitter.addListener(eventName);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@ReactMethod
|
|
119
|
+
public void eventsRemoveListener(String eventName, Boolean all) {
|
|
120
|
+
ReactNativeFirebaseEventEmitter emitter = ReactNativeFirebaseEventEmitter.getSharedInstance();
|
|
121
|
+
emitter.removeListener(eventName, all);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@ReactMethod
|
|
125
|
+
public void addListener(String eventName) {
|
|
126
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@ReactMethod
|
|
130
|
+
public void removeListeners(Integer count) {
|
|
131
|
+
// Keep: Required for RN built in Event Emitter Calls.
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** ------------------ META ------------------ */
|
|
135
|
+
@ReactMethod
|
|
136
|
+
public void metaGetAll(Promise promise) {
|
|
137
|
+
promise.resolve(ReactNativeFirebaseMeta.getSharedInstance().getAll());
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/** ------------------ JSON ------------------ */
|
|
141
|
+
@ReactMethod
|
|
142
|
+
public void jsonGetAll(Promise promise) {
|
|
143
|
+
promise.resolve(ReactNativeFirebaseJSON.getSharedInstance().getAll());
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/** ------------------ PREFERENCES ------------------ */
|
|
147
|
+
@ReactMethod
|
|
148
|
+
public void preferencesSetBool(String key, boolean value, Promise promise) {
|
|
149
|
+
ReactNativeFirebasePreferences.getSharedInstance().setBooleanValue(key, value);
|
|
150
|
+
promise.resolve(null);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
@ReactMethod
|
|
154
|
+
public void preferencesSetString(String key, String value, Promise promise) {
|
|
155
|
+
ReactNativeFirebasePreferences.getSharedInstance().setStringValue(key, value);
|
|
156
|
+
promise.resolve(null);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
@ReactMethod
|
|
160
|
+
public void preferencesGetAll(Promise promise) {
|
|
161
|
+
promise.resolve(ReactNativeFirebasePreferences.getSharedInstance().getAll());
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
@ReactMethod
|
|
165
|
+
public void preferencesClearAll(Promise promise) {
|
|
166
|
+
ReactNativeFirebasePreferences.getSharedInstance().clearAll();
|
|
167
|
+
promise.resolve(null);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@Override
|
|
171
|
+
public Map<String, Object> getConstants() {
|
|
172
|
+
Map<String, Object> constants = new HashMap<>();
|
|
173
|
+
List<Map<String, Object>> appsList = new ArrayList<>();
|
|
174
|
+
List<FirebaseApp> firebaseApps = FirebaseApp.getApps(getReactApplicationContext());
|
|
175
|
+
|
|
176
|
+
for (FirebaseApp app : firebaseApps) {
|
|
177
|
+
appsList.add(RCTConvertFirebase.firebaseAppToMap(app));
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
constants.put("NATIVE_FIREBASE_APPS", appsList);
|
|
181
|
+
|
|
182
|
+
constants.put("FIREBASE_RAW_JSON", ReactNativeFirebaseJSON.getSharedInstance().getRawJSON());
|
|
183
|
+
|
|
184
|
+
return constants;
|
|
185
|
+
}
|
|
186
|
+
}
|
package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackage.java
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
package io.invertase.firebase.app;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import com.facebook.react.ReactPackage;
|
|
21
|
+
import com.facebook.react.bridge.NativeModule;
|
|
22
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
23
|
+
import com.facebook.react.uimanager.ViewManager;
|
|
24
|
+
import io.invertase.firebase.utils.ReactNativeFirebaseUtilsModule;
|
|
25
|
+
import java.util.ArrayList;
|
|
26
|
+
import java.util.Collections;
|
|
27
|
+
import java.util.List;
|
|
28
|
+
import javax.annotation.Nonnull;
|
|
29
|
+
|
|
30
|
+
@SuppressWarnings("unused")
|
|
31
|
+
public class ReactNativeFirebaseAppPackage implements ReactPackage {
|
|
32
|
+
@Nonnull
|
|
33
|
+
@Override
|
|
34
|
+
public List<NativeModule> createNativeModules(@Nonnull ReactApplicationContext reactContext) {
|
|
35
|
+
if (ReactNativeFirebaseApp.getApplicationContext() == null) {
|
|
36
|
+
ReactNativeFirebaseApp.setApplicationContext(reactContext.getApplicationContext());
|
|
37
|
+
}
|
|
38
|
+
List<NativeModule> modules = new ArrayList<>();
|
|
39
|
+
modules.add(new ReactNativeFirebaseAppModule(reactContext));
|
|
40
|
+
modules.add(new ReactNativeFirebaseUtilsModule(reactContext));
|
|
41
|
+
return modules;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Nonnull
|
|
45
|
+
@Override
|
|
46
|
+
public List<ViewManager> createViewManagers(@Nonnull ReactApplicationContext reactContext) {
|
|
47
|
+
return Collections.emptyList();
|
|
48
|
+
}
|
|
49
|
+
}
|
package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package io.invertase.firebase.app;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import androidx.annotation.Keep;
|
|
21
|
+
import com.google.firebase.components.Component;
|
|
22
|
+
import com.google.firebase.components.ComponentRegistrar;
|
|
23
|
+
import com.google.firebase.platforminfo.LibraryVersionComponent;
|
|
24
|
+
import java.util.Collections;
|
|
25
|
+
import java.util.List;
|
|
26
|
+
|
|
27
|
+
@Keep
|
|
28
|
+
public class ReactNativeFirebaseAppRegistrar implements ComponentRegistrar {
|
|
29
|
+
@Override
|
|
30
|
+
public List<Component<?>> getComponents() {
|
|
31
|
+
return Collections.singletonList(
|
|
32
|
+
LibraryVersionComponent.create(
|
|
33
|
+
"react-native-firebase", ReactNativeFirebaseVersion.VERSION));
|
|
34
|
+
}
|
|
35
|
+
}
|
package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseVersion.java
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
package io.invertase.firebase.app;
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
// generated file - do not modify or commit
|
|
20
|
+
public class ReactNativeFirebaseVersion {
|
|
21
|
+
public static String VERSION = "23.8.1";
|
|
22
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
package io.invertase.firebase.common;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.content.Context;
|
|
21
|
+
import android.util.Log;
|
|
22
|
+
import com.facebook.react.bridge.Arguments;
|
|
23
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
24
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
25
|
+
import com.facebook.react.bridge.WritableMap;
|
|
26
|
+
import com.google.firebase.FirebaseApp;
|
|
27
|
+
import com.google.firebase.FirebaseOptions;
|
|
28
|
+
import io.invertase.firebase.app.ReactNativeFirebaseAppModule;
|
|
29
|
+
import java.util.HashMap;
|
|
30
|
+
import java.util.List;
|
|
31
|
+
import java.util.Map;
|
|
32
|
+
import javax.annotation.Nullable;
|
|
33
|
+
|
|
34
|
+
/** Utilities to convert to and from React Native bridge formats. */
|
|
35
|
+
public class RCTConvertFirebase {
|
|
36
|
+
private static String TAG = "RCTConvertFirebase";
|
|
37
|
+
|
|
38
|
+
public static Map<String, Object> firebaseAppToMap(FirebaseApp firebaseApp) {
|
|
39
|
+
String name = firebaseApp.getName();
|
|
40
|
+
FirebaseOptions appOptions = firebaseApp.getOptions();
|
|
41
|
+
|
|
42
|
+
Map<String, Object> root = new HashMap<>();
|
|
43
|
+
Map<String, Object> options = new HashMap<>();
|
|
44
|
+
Map<String, Object> appConfig = new HashMap<>();
|
|
45
|
+
|
|
46
|
+
appConfig.put("name", name);
|
|
47
|
+
appConfig.put("automaticDataCollectionEnabled", firebaseApp.isDataCollectionDefaultEnabled());
|
|
48
|
+
|
|
49
|
+
// TODO: Salakar: Firebase SDK does not support reading this value
|
|
50
|
+
// appConfig.put("automaticResourceManagement", false);
|
|
51
|
+
|
|
52
|
+
options.put("apiKey", appOptions.getApiKey());
|
|
53
|
+
options.put("appId", appOptions.getApplicationId());
|
|
54
|
+
options.put("projectId", appOptions.getProjectId());
|
|
55
|
+
options.put("databaseURL", appOptions.getDatabaseUrl());
|
|
56
|
+
options.put("measurementId", appOptions.getGaTrackingId());
|
|
57
|
+
options.put("messagingSenderId", appOptions.getGcmSenderId());
|
|
58
|
+
options.put("storageBucket", appOptions.getStorageBucket());
|
|
59
|
+
|
|
60
|
+
if (ReactNativeFirebaseAppModule.authDomains.get(name) != null) {
|
|
61
|
+
options.put("authDomain", ReactNativeFirebaseAppModule.authDomains.get(name));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
root.put("options", options);
|
|
65
|
+
root.put("appConfig", appConfig);
|
|
66
|
+
|
|
67
|
+
return root;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public static WritableMap firebaseAppToWritableMap(FirebaseApp firebaseApp) {
|
|
71
|
+
return Arguments.makeNativeMap(firebaseAppToMap(firebaseApp));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public static FirebaseApp readableMapToFirebaseApp(
|
|
75
|
+
ReadableMap options, ReadableMap appConfig, Context context) {
|
|
76
|
+
FirebaseOptions.Builder builder = new FirebaseOptions.Builder();
|
|
77
|
+
|
|
78
|
+
String name = appConfig.getString("name");
|
|
79
|
+
|
|
80
|
+
builder.setApiKey(options.getString("apiKey"));
|
|
81
|
+
builder.setApplicationId(options.getString("appId"));
|
|
82
|
+
builder.setProjectId(options.getString("projectId"));
|
|
83
|
+
builder.setDatabaseUrl(options.getString("databaseURL"));
|
|
84
|
+
|
|
85
|
+
if (options.hasKey("measurementId")) {
|
|
86
|
+
builder.setGaTrackingId(options.getString("measurementId"));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
builder.setStorageBucket(options.getString("storageBucket"));
|
|
90
|
+
builder.setGcmSenderId(options.getString("messagingSenderId"));
|
|
91
|
+
|
|
92
|
+
FirebaseApp firebaseApp;
|
|
93
|
+
if (name.equals("[DEFAULT]")) {
|
|
94
|
+
firebaseApp = FirebaseApp.initializeApp(context, builder.build());
|
|
95
|
+
} else {
|
|
96
|
+
firebaseApp = FirebaseApp.initializeApp(context, builder.build(), name);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (appConfig.hasKey("automaticDataCollectionEnabled")) {
|
|
100
|
+
firebaseApp.setDataCollectionDefaultEnabled(
|
|
101
|
+
Boolean.valueOf(appConfig.getBoolean("automaticDataCollectionEnabled")));
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (appConfig.hasKey("automaticResourceManagement")) {
|
|
105
|
+
// https://developers.google.com/android/reference/com/google/firebase/FirebaseApp.html#setAutomaticResourceManagementEnabled(boolean)
|
|
106
|
+
firebaseApp.setAutomaticResourceManagementEnabled(
|
|
107
|
+
appConfig.getBoolean("automaticResourceManagement"));
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return firebaseApp;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Takes a value and calls the appropriate setter for its type on the target map + key
|
|
115
|
+
*
|
|
116
|
+
* @param key String key to set on target map
|
|
117
|
+
* @param value Object value to set on target map
|
|
118
|
+
* @param map WritableMap target map to write the value to
|
|
119
|
+
*/
|
|
120
|
+
@SuppressWarnings("unchecked")
|
|
121
|
+
public static WritableMap mapPutValue(String key, @Nullable Object value, WritableMap map) {
|
|
122
|
+
if (value == null) {
|
|
123
|
+
map.putNull(key);
|
|
124
|
+
return map;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
String type = value.getClass().getName();
|
|
128
|
+
|
|
129
|
+
switch (type) {
|
|
130
|
+
case "java.lang.Boolean":
|
|
131
|
+
map.putBoolean(key, (Boolean) value);
|
|
132
|
+
break;
|
|
133
|
+
case "java.lang.Long":
|
|
134
|
+
Long longVal = (Long) value;
|
|
135
|
+
map.putDouble(key, (double) longVal);
|
|
136
|
+
break;
|
|
137
|
+
case "java.lang.Float":
|
|
138
|
+
float floatVal = (float) value;
|
|
139
|
+
map.putDouble(key, (double) floatVal);
|
|
140
|
+
break;
|
|
141
|
+
case "java.lang.Double":
|
|
142
|
+
map.putDouble(key, (Double) value);
|
|
143
|
+
break;
|
|
144
|
+
case "java.lang.Integer":
|
|
145
|
+
map.putInt(key, (int) value);
|
|
146
|
+
break;
|
|
147
|
+
case "java.lang.String":
|
|
148
|
+
map.putString(key, (String) value);
|
|
149
|
+
break;
|
|
150
|
+
case "org.json.JSONObject$1":
|
|
151
|
+
map.putString(key, value.toString());
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
if (List.class.isAssignableFrom(value.getClass())) {
|
|
155
|
+
map.putArray(key, Arguments.makeNativeArray((List<Object>) value));
|
|
156
|
+
} else if (Map.class.isAssignableFrom(value.getClass())) {
|
|
157
|
+
WritableMap childMap = Arguments.createMap();
|
|
158
|
+
Map<String, Object> valueMap = (Map<String, Object>) value;
|
|
159
|
+
|
|
160
|
+
for (Map.Entry<String, Object> entry : valueMap.entrySet()) {
|
|
161
|
+
mapPutValue(entry.getKey(), entry.getValue(), childMap);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
map.putMap(key, childMap);
|
|
165
|
+
} else {
|
|
166
|
+
Log.d(TAG, "utils:mapPutValue:unknownType:" + type);
|
|
167
|
+
map.putNull(key);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return map;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// TODO Remove me - also in SharedUtils
|
|
175
|
+
public static WritableMap readableMapToWritableMap(ReadableMap map) {
|
|
176
|
+
WritableMap writableMap = Arguments.createMap();
|
|
177
|
+
// https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/WritableNativeMap.java#L54
|
|
178
|
+
writableMap.merge(map);
|
|
179
|
+
return writableMap;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public static Map<String, Object> toHashMap(ReadableMap readableMap) {
|
|
183
|
+
// https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeMap.java#L216
|
|
184
|
+
return readableMap.toHashMap();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
public static List<Object> toArrayList(ReadableArray readableArray) {
|
|
188
|
+
// https://github.com/facebook/react-native/blob/main/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeArray.java#L175
|
|
189
|
+
return readableArray.toArrayList();
|
|
190
|
+
}
|
|
191
|
+
}
|
package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEvent.java
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
package io.invertase.firebase.common;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import com.facebook.react.bridge.WritableMap;
|
|
21
|
+
import io.invertase.firebase.interfaces.NativeEvent;
|
|
22
|
+
|
|
23
|
+
public class ReactNativeFirebaseEvent implements NativeEvent {
|
|
24
|
+
private String eventName;
|
|
25
|
+
private WritableMap eventBody;
|
|
26
|
+
private String firebaseAppName;
|
|
27
|
+
|
|
28
|
+
public ReactNativeFirebaseEvent(String eventName, WritableMap eventBody) {
|
|
29
|
+
this.eventName = eventName;
|
|
30
|
+
this.eventBody = eventBody;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public ReactNativeFirebaseEvent(String eventName, WritableMap eventBody, String firebaseAppName) {
|
|
34
|
+
this.eventName = eventName;
|
|
35
|
+
this.eventBody = eventBody;
|
|
36
|
+
this.firebaseAppName = firebaseAppName;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@Override
|
|
40
|
+
public String getEventName() {
|
|
41
|
+
return eventName;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public WritableMap getEventBody() {
|
|
46
|
+
return eventBody;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@Override
|
|
50
|
+
public String getFirebaseAppName() {
|
|
51
|
+
return firebaseAppName;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
package io.invertase.firebase.common;
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this library except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import android.os.Handler;
|
|
21
|
+
import android.os.Looper;
|
|
22
|
+
import android.util.Log;
|
|
23
|
+
import androidx.annotation.MainThread;
|
|
24
|
+
import com.facebook.react.bridge.Arguments;
|
|
25
|
+
import com.facebook.react.bridge.ReactContext;
|
|
26
|
+
import com.facebook.react.bridge.WritableMap;
|
|
27
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
28
|
+
import io.invertase.firebase.interfaces.NativeEvent;
|
|
29
|
+
import java.util.ArrayList;
|
|
30
|
+
import java.util.HashMap;
|
|
31
|
+
import java.util.List;
|
|
32
|
+
|
|
33
|
+
public class ReactNativeFirebaseEventEmitter {
|
|
34
|
+
private static ReactNativeFirebaseEventEmitter sharedInstance =
|
|
35
|
+
new ReactNativeFirebaseEventEmitter();
|
|
36
|
+
private final List<NativeEvent> queuedEvents = new ArrayList<>();
|
|
37
|
+
private final Handler handler = new Handler(Looper.getMainLooper());
|
|
38
|
+
private final HashMap<String, Integer> jsListeners = new HashMap<>();
|
|
39
|
+
private ReactContext reactContext;
|
|
40
|
+
private Boolean jsReady = false;
|
|
41
|
+
private int jsListenerCount;
|
|
42
|
+
|
|
43
|
+
public static ReactNativeFirebaseEventEmitter getSharedInstance() {
|
|
44
|
+
return sharedInstance;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public void attachReactContext(final ReactContext reactContext) {
|
|
48
|
+
handler.post(
|
|
49
|
+
() -> {
|
|
50
|
+
ReactNativeFirebaseEventEmitter.this.reactContext = reactContext;
|
|
51
|
+
sendQueuedEvents();
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public void notifyJsReady(Boolean ready) {
|
|
56
|
+
handler.post(
|
|
57
|
+
() -> {
|
|
58
|
+
jsReady = ready;
|
|
59
|
+
sendQueuedEvents();
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
public void sendEvent(final NativeEvent event) {
|
|
64
|
+
handler.post(
|
|
65
|
+
() -> {
|
|
66
|
+
synchronized (jsListeners) {
|
|
67
|
+
if (!jsListeners.containsKey(event.getEventName()) || !emit(event)) {
|
|
68
|
+
queuedEvents.add(event);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
public void addListener(String eventName) {
|
|
75
|
+
synchronized (jsListeners) {
|
|
76
|
+
jsListenerCount++;
|
|
77
|
+
if (!jsListeners.containsKey(eventName)) {
|
|
78
|
+
jsListeners.put(eventName, 1);
|
|
79
|
+
} else {
|
|
80
|
+
int listenersForEvent = jsListeners.get(eventName);
|
|
81
|
+
jsListeners.put(eventName, listenersForEvent + 1);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
handler.post(this::sendQueuedEvents);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public void removeListener(String eventName, Boolean all) {
|
|
89
|
+
synchronized (jsListeners) {
|
|
90
|
+
if (jsListeners.containsKey(eventName)) {
|
|
91
|
+
int listenersForEvent = jsListeners.get(eventName);
|
|
92
|
+
|
|
93
|
+
if (listenersForEvent <= 1 || all) {
|
|
94
|
+
jsListeners.remove(eventName);
|
|
95
|
+
} else {
|
|
96
|
+
jsListeners.put(eventName, listenersForEvent - 1);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
jsListenerCount -= all ? listenersForEvent : 1;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public WritableMap getListenersMap() {
|
|
105
|
+
WritableMap writableMap = Arguments.createMap();
|
|
106
|
+
WritableMap events = Arguments.createMap();
|
|
107
|
+
|
|
108
|
+
writableMap.putInt("listeners", jsListenerCount);
|
|
109
|
+
writableMap.putInt("queued", queuedEvents.size());
|
|
110
|
+
|
|
111
|
+
synchronized (jsListeners) {
|
|
112
|
+
for (HashMap.Entry<String, Integer> entry : jsListeners.entrySet()) {
|
|
113
|
+
events.putInt(entry.getKey(), entry.getValue());
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
writableMap.putMap("events", events);
|
|
118
|
+
|
|
119
|
+
return writableMap;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@MainThread
|
|
123
|
+
private void sendQueuedEvents() {
|
|
124
|
+
synchronized (jsListeners) {
|
|
125
|
+
for (NativeEvent event : new ArrayList<>(queuedEvents)) {
|
|
126
|
+
if (jsListeners.containsKey(event.getEventName())) {
|
|
127
|
+
queuedEvents.remove(event);
|
|
128
|
+
sendEvent(event);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@MainThread
|
|
135
|
+
private boolean emit(final NativeEvent event) {
|
|
136
|
+
if (!jsReady || reactContext == null || !reactContext.hasActiveCatalystInstance()) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
reactContext
|
|
142
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
143
|
+
.emit("rnfb_" + event.getEventName(), event.getEventBody());
|
|
144
|
+
} catch (Exception e) {
|
|
145
|
+
Log.wtf("RNFB_EMITTER", "Error sending Event " + event.getEventName(), e);
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
}
|