@react-native-firebase/app 26.4.0 → 27.0.0
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 +48 -0
- package/README.md +10 -27
- package/RNFBApp.podspec +13 -5
- package/android/build.gradle +3 -0
- package/android/src/main/java/io/invertase/firebase/common/RNFBHandleCollisionException.kt +29 -0
- package/android/src/main/java/io/invertase/firebase/common/RNFBHandleMap.kt +146 -0
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.kt +156 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebaseModule.kt +44 -0
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebasePreferences.kt +100 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/NativeRNFBTurboApp.kt +250 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseApp.kt +64 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/{ReactNativeFirebaseAppInitProvider.java → ReactNativeFirebaseAppInitProvider.kt} +3 -4
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackage.kt +47 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.kt +33 -0
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseVersion.java +1 -1
- package/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.kt +185 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEvent.kt +35 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.kt +662 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseJSON.kt +103 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseMeta.kt +96 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.kt +140 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebasePreferences.kt +109 -0
- package/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.kt +451 -0
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/{ContextProvider.java → ContextProvider.kt} +8 -8
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/{NativeError.java → NativeError.kt} +8 -8
- package/android/src/reactnative/java/io/invertase/firebase/interfaces/{NativeEvent.java → NativeEvent.kt} +6 -6
- package/android/src/reactnative/java/io/invertase/firebase/utils/NativeRNFBTurboUtils.kt +219 -0
- package/android/src/test/java/expo/core/ModuleRegistry.java +9 -0
- package/android/src/test/java/io/invertase/firebase/app/NativeRNFBTurboAppTest.java +182 -59
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppComponentsJavaCompatibilityTest.java +70 -0
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppJavaCompatibilityTest.java +60 -0
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackageTest.java +165 -0
- package/android/src/test/java/io/invertase/firebase/app/ReactNativeFirebaseAppTest.kt +167 -0
- package/android/src/test/java/io/invertase/firebase/common/RCTConvertFirebaseJavaCompatibilityTest.java +112 -0
- package/android/src/test/java/io/invertase/firebase/common/RCTConvertFirebaseTest.kt +317 -0
- package/android/src/test/java/io/invertase/firebase/common/RNFBHandleMapTest.kt +309 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitterJavaCompatibilityTest.java +176 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitterTest.java +143 -12
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseEventTest.kt +61 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseJSONJavaCompatibilityTest.java +85 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseJSONTest.kt +296 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseMetaJavaCompatibilityTest.java +67 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseMetaTest.kt +246 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseModuleTest.kt +254 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebasePreferencesJavaCompatibilityTest.java +87 -0
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebasePreferencesTest.kt +260 -0
- package/android/src/test/java/io/invertase/firebase/common/SharedUtilsJavaCompatibilityTest.java +255 -0
- package/android/src/test/java/io/invertase/firebase/common/SharedUtilsTest.kt +674 -0
- package/android/src/test/java/io/invertase/firebase/common/TaskExecutorServiceTest.kt +290 -0
- package/android/src/test/java/io/invertase/firebase/common/UniversalFirebaseModuleJavaCompatibilityTest.java +178 -0
- package/android/src/test/java/io/invertase/firebase/common/UniversalFirebasePreferencesJavaCompatibilityTest.java +99 -0
- package/android/src/test/java/io/invertase/firebase/common/UniversalFirebasePreferencesTest.kt +217 -0
- package/android/src/test/java/io/invertase/firebase/commoncompat/ReactNativeFirebaseModuleJavaCompatibilityTest.java +176 -0
- package/android/src/test/java/io/invertase/firebase/commoncompat/ReactNativeFirebaseModuleKotlinCompatibilityTest.kt +52 -0
- package/android/src/test/java/io/invertase/firebase/interfaces/InterfacesJavaCompatibilityTest.java +144 -0
- package/android/src/test/java/io/invertase/firebase/interfaces/NativeEventTest.kt +56 -0
- package/android/src/test/java/io/invertase/firebase/utils/NativeRNFBTurboUtilsTest.java +517 -21
- package/dist/module/FirebaseApp.js +10 -0
- package/dist/module/FirebaseApp.js.map +1 -1
- package/dist/module/common/deeps.js +3 -0
- package/dist/module/common/deeps.js.map +1 -1
- package/dist/module/internal/FirebaseModule.js.map +1 -1
- package/dist/module/internal/RNFBNativeEventEmitter.js +12 -1
- package/dist/module/internal/RNFBNativeEventEmitter.js.map +1 -1
- package/dist/module/internal/SharedEventEmitter.js +3 -1
- package/dist/module/internal/SharedEventEmitter.js.map +1 -1
- package/dist/module/internal/index.js +1 -0
- package/dist/module/internal/index.js.map +1 -1
- package/dist/module/internal/registry/app.js +7 -1
- package/dist/module/internal/registry/app.js.map +1 -1
- package/dist/module/types/app.js.map +1 -1
- package/dist/module/types/internal.js +2 -0
- package/dist/module/version.js +1 -1
- package/dist/typescript/lib/FirebaseApp.d.ts +7 -0
- package/dist/typescript/lib/FirebaseApp.d.ts.map +1 -1
- package/dist/typescript/lib/common/deeps.d.ts.map +1 -1
- package/dist/typescript/lib/internal/FirebaseModule.d.ts +2 -3
- package/dist/typescript/lib/internal/FirebaseModule.d.ts.map +1 -1
- package/dist/typescript/lib/internal/NativeModules.d.ts +4 -1
- package/dist/typescript/lib/internal/NativeModules.d.ts.map +1 -1
- package/dist/typescript/lib/internal/RNFBNativeEventEmitter.d.ts +2 -2
- package/dist/typescript/lib/internal/RNFBNativeEventEmitter.d.ts.map +1 -1
- package/dist/typescript/lib/internal/SharedEventEmitter.d.ts +3 -3
- package/dist/typescript/lib/internal/SharedEventEmitter.d.ts.map +1 -1
- package/dist/typescript/lib/internal/index.d.ts +1 -0
- package/dist/typescript/lib/internal/index.d.ts.map +1 -1
- package/dist/typescript/lib/internal/registry/app.d.ts.map +1 -1
- package/dist/typescript/lib/types/app.d.ts +10 -3
- package/dist/typescript/lib/types/app.d.ts.map +1 -1
- package/dist/typescript/lib/types/internal.d.ts +12 -0
- package/dist/typescript/lib/types/internal.d.ts.map +1 -1
- package/dist/typescript/lib/version.d.ts +1 -1
- package/firebase-schema.json +4 -0
- package/firebase_spm.rb +552 -96
- package/ios/RNFBApp/RCTConvert+FIRApp.h +2 -5
- package/ios/RNFBApp/RCTConvert+FIRApp.m +11 -6
- package/ios/RNFBApp/RCTConvert+FIROptions.h +2 -5
- package/ios/RNFBApp/RCTConvert+FIROptions.m +11 -10
- package/ios/RNFBApp/RCTConvertFIRApp.swift +86 -0
- package/ios/RNFBApp/RCTConvertFIROptions.swift +259 -0
- package/ios/RNFBApp/RNFBAppCustomAuthDomains.swift +63 -0
- package/ios/RNFBApp/RNFBAppInitializeOptionsMapper.swift +113 -0
- package/ios/RNFBApp/RNFBAppLogLevelMapper.swift +53 -0
- package/ios/RNFBApp/RNFBAppModule+CustomAuthDomain.m +35 -0
- package/ios/RNFBApp/RNFBAppModule.h +6 -2
- package/ios/RNFBApp/RNFBAppModule.mm +65 -228
- package/ios/RNFBApp/RNFBAppModuleFirebase.swift +439 -0
- package/ios/RNFBApp/RNFBAppModuleImplementation.h +68 -0
- package/ios/RNFBApp/RNFBAppModuleImplementation.m +195 -0
- package/ios/RNFBApp/RNFBHandleMap.m +27 -56
- package/ios/RNFBApp/RNFBHandleMapStorage.swift +90 -0
- package/ios/RNFBApp/RNFBInitializeAppArguments.swift +82 -0
- package/ios/RNFBApp/RNFBJSON.m +22 -38
- package/ios/RNFBApp/RNFBJSONImplementation.swift +71 -0
- package/ios/RNFBApp/RNFBMeta.m +24 -26
- package/ios/RNFBApp/RNFBMetaStorage.swift +76 -0
- package/ios/RNFBApp/RNFBNullSentinelDecoding.swift +135 -0
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.h +30 -3
- package/ios/RNFBApp/RNFBNullSentinelInterceptor.m +28 -5
- package/ios/RNFBApp/RNFBPreferences.m +22 -20
- package/ios/RNFBApp/RNFBPreferencesStorage.swift +101 -0
- package/ios/RNFBApp/RNFBRCTEventEmitter.m +36 -93
- package/ios/RNFBApp/RNFBRCTEventEmitterCore.swift +161 -0
- package/ios/RNFBApp/RNFBSharedUtils.h +2 -5
- package/ios/RNFBApp/RNFBSharedUtils.m +109 -198
- package/ios/RNFBApp/RNFBSharedUtilsConfig.swift +72 -0
- package/ios/RNFBApp/RNFBSharedUtilsFIRApp.swift +271 -0
- package/ios/RNFBApp/RNFBSharedUtilsFormatting.swift +59 -0
- package/ios/RNFBApp/RNFBSharedUtilsPromiseRejection.swift +88 -0
- package/ios/RNFBApp/RNFBUtilsHelpers.swift +116 -0
- package/ios/RNFBApp/RNFBUtilsModule+Foundation.m +44 -0
- package/ios/RNFBApp/RNFBUtilsModule+PhotoAssets.m +47 -0
- package/ios/RNFBApp/RNFBUtilsModule.h +11 -1
- package/ios/RNFBApp/RNFBUtilsModule.mm +10 -85
- package/ios/RNFBApp/RNFBUtilsModuleImplementation.h +32 -0
- package/ios/RNFBApp/RNFBUtilsModuleImplementation.m +56 -0
- package/ios/RNFBApp/RNFBVersion.m +1 -1
- package/ios/RNFBApp.xcodeproj/project.pbxproj +100 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseCore/FIRApp.m +171 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseCore/FirebaseCore.h +78 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseInstallations/FIRInstallations.m +7 -0
- package/ios/RNFBAppUnitTests/HostStubs/FirebaseInstallations/FirebaseInstallations.h +8 -0
- package/ios/RNFBAppUnitTests/HostStubs/RNFBAppModuleHostStub.m +55 -0
- package/ios/RNFBAppUnitTests/HostStubs/RNFBAppTurboModules.h +89 -0
- package/ios/RNFBAppUnitTests/HostStubs/RNFBAppTurboModules.mm +30 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTBridge.h +19 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTBridge.m +32 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTBridgeModule.h +19 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTConvert.h +28 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTConvert.m +23 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTEventEmitter.h +9 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTInvalidating.h +24 -0
- package/ios/RNFBAppUnitTests/HostStubs/React/RCTUtils.h +9 -0
- package/ios/RNFBAppUnitTests/HostStubs/module.modulemap +13 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIRAppFacadeTests.m +61 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIRAppTests.swift +73 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIROptionsFacadeTests.m +57 -0
- package/ios/RNFBAppUnitTests/RCTConvertFIROptionsTests.swift +243 -0
- package/ios/RNFBAppUnitTests/RNFBAppCustomAuthDomainsFacadeTests.m +73 -0
- package/ios/RNFBAppUnitTests/RNFBAppCustomAuthDomainsTests.swift +70 -0
- package/ios/RNFBAppUnitTests/RNFBAppInitializeOptionsMapperTests.swift +190 -0
- package/ios/RNFBAppUnitTests/RNFBAppLogLevelFacadeTests.m +76 -0
- package/ios/RNFBAppUnitTests/RNFBAppLogLevelMapperTests.swift +59 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleFirebaseFacadeTests.m +215 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleFirebaseTests.swift +430 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleLifecycleTests.m +206 -0
- package/ios/RNFBAppUnitTests/RNFBAppModuleShellTests.mm +367 -0
- package/ios/RNFBAppUnitTests/RNFBAppUnitTests.xcodeproj/project.pbxproj +355 -2
- package/ios/RNFBAppUnitTests/RNFBFirebaseAppClientTests.swift +165 -0
- package/ios/RNFBAppUnitTests/RNFBHandleMapStorageTests.swift +121 -0
- package/ios/RNFBAppUnitTests/RNFBInitializeAppArgumentsTests.swift +256 -0
- package/ios/RNFBAppUnitTests/RNFBJSONImplementationTests.swift +126 -0
- package/ios/RNFBAppUnitTests/RNFBJSONTests.m +172 -0
- package/ios/RNFBAppUnitTests/RNFBMetaStorageTests.swift +106 -0
- package/ios/RNFBAppUnitTests/RNFBMetaTests.m +65 -0
- package/ios/RNFBAppUnitTests/RNFBNullSentinelDecodingTests.swift +286 -0
- package/ios/RNFBAppUnitTests/RNFBNullSentinelInterceptorTests.m +312 -0
- package/ios/RNFBAppUnitTests/RNFBPreferencesStorageTests.swift +105 -0
- package/ios/RNFBAppUnitTests/RNFBPreferencesTests.m +110 -0
- package/ios/RNFBAppUnitTests/RNFBRCTEventEmitterCoreTests.swift +163 -0
- package/ios/RNFBAppUnitTests/RNFBRCTEventEmitterFacadeTests.m +141 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsConfigFacadeTests.m +100 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsConfigTests.swift +234 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFIRAppFacadeTests.m +145 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFIRAppTests.swift +173 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFormattingFacadeTests.m +38 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsFormattingTests.swift +82 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsNullSentinelTests.m +35 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsPromiseRejectionFacadeTests.m +107 -0
- package/ios/RNFBAppUnitTests/RNFBSharedUtilsPromiseRejectionTests.swift +133 -0
- package/ios/RNFBAppUnitTests/RNFBUtilsHelpersTests.swift +144 -0
- package/ios/RNFBAppUnitTests/RNFBUtilsModuleFacadeTests.m +72 -0
- package/ios/RNFBAppUnitTests/RNFBUtilsModuleShellTests.mm +282 -0
- package/ios/RNFBFirebase/Package.swift +53 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebase/RNFBFirebase.swift +285 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebaseBridge/Public/.gitkeep +0 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebaseBridge/RNFBFirebaseBridge.m +169 -0
- package/ios/RNFBFirebase/Sources/RNFBFirebaseBridge/include/RNFBFirebaseBridge.h +52 -0
- package/ios/RNFBFirebaseUnitTests/RNFBAppDynamicFacadeTests.swift +240 -0
- package/{android/src/main/java/io/invertase/firebase/common/RNFBHandleCollisionException.java → ios/RNFBFirebaseUnitTests/RNFBFirebaseClientImport.swift} +23 -14
- package/ios/RNFBFirebaseUnitTests/RNFBFirebaseUnitTests.xcodeproj/project.pbxproj +588 -0
- package/ios/RNFBFirebaseUnitTests/RNFBFirebaseUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBFirebaseUnitTests.xcscheme +83 -0
- package/ios_config.sh +50 -22
- package/lib/FirebaseApp.ts +10 -0
- package/lib/common/deeps.ts +3 -0
- package/lib/internal/FirebaseModule.ts +6 -3
- package/lib/internal/NativeModules.ts +4 -1
- package/lib/internal/RNFBNativeEventEmitter.ts +14 -5
- package/lib/internal/SharedEventEmitter.ts +5 -1
- package/lib/internal/index.ts +1 -0
- package/lib/internal/react-native-vendor-emitter.d.ts +11 -0
- package/lib/internal/registry/app.ts +7 -1
- package/lib/types/app.ts +10 -3
- package/lib/types/internal.ts +19 -0
- package/lib/version.ts +1 -1
- package/package.json +8 -8
- package/plugin/build/ios/appDelegate.js +2 -2
- package/plugin/build/ios/podfile.js +16 -16
- package/plugin/build/pluginConfig.d.ts +4 -2
- package/plugin/src/ios/appDelegate.ts +2 -2
- package/plugin/src/ios/podfile.ts +20 -23
- package/plugin/src/pluginConfig.ts +4 -2
- package/android/src/main/java/io/invertase/firebase/common/RNFBHandleMap.java +0 -150
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.java +0 -148
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebaseModule.java +0 -62
- package/android/src/main/java/io/invertase/firebase/common/UniversalFirebasePreferences.java +0 -91
- package/android/src/reactnative/java/io/invertase/firebase/app/NativeRNFBTurboApp.java +0 -224
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseApp.java +0 -46
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppPackage.java +0 -49
- package/android/src/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java +0 -35
- package/android/src/reactnative/java/io/invertase/firebase/common/RCTConvertFirebase.java +0 -192
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEvent.java +0 -53
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseEventEmitter.java +0 -606
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseJSON.java +0 -109
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseMeta.java +0 -101
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebaseModule.java +0 -146
- package/android/src/reactnative/java/io/invertase/firebase/common/ReactNativeFirebasePreferences.java +0 -96
- package/android/src/reactnative/java/io/invertase/firebase/common/SharedUtils.java +0 -441
- package/android/src/reactnative/java/io/invertase/firebase/utils/NativeRNFBTurboUtils.java +0 -223
- package/android/src/test/java/io/invertase/firebase/common/RNFBHandleMapTest.java +0 -275
- package/android/src/test/java/io/invertase/firebase/common/ReactNativeFirebaseJSONTest.java +0 -108
- package/android/src/test/java/io/invertase/firebase/common/TaskExecutorServiceTest.java +0 -97
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#if RNFB_DYNAMIC_FIREBASE_PROBE
|
|
18
|
+
import RNFBFirebase
|
|
19
|
+
#else
|
|
20
|
+
import FirebaseCore
|
|
21
|
+
#endif
|
|
22
|
+
import Foundation
|
|
23
|
+
|
|
24
|
+
#if RNFB_DYNAMIC_FIREBASE_PROBE
|
|
25
|
+
/**
|
|
26
|
+
* Foundation snapshot from `RNFBFirebaseAppClient`, shaped as `RNFBFIROptionsProviding`.
|
|
27
|
+
*/
|
|
28
|
+
private final class RNFBOpaqueOptionsProvider: NSObject, RNFBFIROptionsProviding {
|
|
29
|
+
let apiKey: String?
|
|
30
|
+
let googleAppID: String?
|
|
31
|
+
let projectID: String?
|
|
32
|
+
let databaseURL: String?
|
|
33
|
+
let storageBucket: String?
|
|
34
|
+
let gcmSenderID: String?
|
|
35
|
+
let clientID: String?
|
|
36
|
+
|
|
37
|
+
init(_ snapshot: RNFBFirebaseAppSnapshot) {
|
|
38
|
+
apiKey = snapshot.apiKey
|
|
39
|
+
googleAppID = snapshot.googleAppID
|
|
40
|
+
projectID = snapshot.projectID
|
|
41
|
+
databaseURL = snapshot.databaseURL
|
|
42
|
+
storageBucket = snapshot.storageBucket
|
|
43
|
+
gcmSenderID = snapshot.gcmSenderID
|
|
44
|
+
clientID = snapshot.clientID
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Foundation snapshot from `RNFBFirebaseAppClient`, shaped as `RNFBFIRAppProviding`.
|
|
50
|
+
*/
|
|
51
|
+
private final class RNFBOpaqueAppProvider: NSObject, RNFBFIRAppProviding {
|
|
52
|
+
let name: String
|
|
53
|
+
let options: RNFBFIROptionsProviding
|
|
54
|
+
private let dataCollectionEnabled: Bool
|
|
55
|
+
|
|
56
|
+
init(_ snapshot: RNFBFirebaseAppSnapshot) {
|
|
57
|
+
name = snapshot.name
|
|
58
|
+
options = RNFBOpaqueOptionsProvider(snapshot)
|
|
59
|
+
dataCollectionEnabled = snapshot.isDataCollectionDefaultEnabled
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
@objc(isDataCollectionDefaultEnabled)
|
|
63
|
+
func isDataCollectionDefaultEnabled() -> Bool {
|
|
64
|
+
dataCollectionEnabled
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
#else
|
|
68
|
+
/**
|
|
69
|
+
* Adapts live `FirebaseOptions` (`FIROptions`) to `RNFBFIROptionsProviding`.
|
|
70
|
+
*
|
|
71
|
+
* Field mapping matches
|
|
72
|
+
* https://github.com/firebase/firebase-ios-sdk/blob/main/FirebaseCore/Sources/Public/FirebaseCore/FIROptions.h
|
|
73
|
+
* (`apiKey`, `googleAppID`, `projectID`, `databaseURL`, `storageBucket`, `gcmSenderID`, `clientID`).
|
|
74
|
+
*/
|
|
75
|
+
@objc(RNFBFIROptionsAdapter)
|
|
76
|
+
final class RNFBFIROptionsAdapter: NSObject, RNFBFIROptionsProviding {
|
|
77
|
+
private let options: FirebaseOptions
|
|
78
|
+
|
|
79
|
+
init(options: FirebaseOptions) {
|
|
80
|
+
self.options = options
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
var apiKey: String? { options.apiKey }
|
|
84
|
+
var googleAppID: String? { options.googleAppID }
|
|
85
|
+
var projectID: String? { options.projectID }
|
|
86
|
+
var databaseURL: String? { options.databaseURL }
|
|
87
|
+
var storageBucket: String? { options.storageBucket }
|
|
88
|
+
var gcmSenderID: String? { options.gcmSenderID }
|
|
89
|
+
var clientID: String? { options.clientID }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Adapts live `FirebaseApp` (`FIRApp`) to `RNFBFIRAppProviding`.
|
|
94
|
+
*
|
|
95
|
+
* Uses `name`, `options`, and `isDataCollectionDefaultEnabled` from
|
|
96
|
+
* https://github.com/firebase/firebase-ios-sdk/blob/main/FirebaseCore/Sources/Public/FirebaseCore/FIRApp.h
|
|
97
|
+
*/
|
|
98
|
+
@objc(RNFBFIRAppAdapter)
|
|
99
|
+
final class RNFBFIRAppAdapter: NSObject, RNFBFIRAppProviding {
|
|
100
|
+
private let app: FirebaseApp
|
|
101
|
+
private let optionsAdapter: RNFBFIROptionsAdapter
|
|
102
|
+
|
|
103
|
+
init(app: FirebaseApp) {
|
|
104
|
+
self.app = app
|
|
105
|
+
optionsAdapter = RNFBFIROptionsAdapter(options: app.options)
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
var name: String { app.name }
|
|
109
|
+
|
|
110
|
+
var options: RNFBFIROptionsProviding { optionsAdapter }
|
|
111
|
+
|
|
112
|
+
@objc(isDataCollectionDefaultEnabled)
|
|
113
|
+
func isDataCollectionDefaultEnabled() -> Bool {
|
|
114
|
+
app.isDataCollectionDefaultEnabled
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
#endif
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* FIROptions fields needed by `firAppToDictionary`.
|
|
121
|
+
*
|
|
122
|
+
* Production adapts live `FIROptions`; unit tests inject doubles.
|
|
123
|
+
*/
|
|
124
|
+
@objc public protocol RNFBFIROptionsProviding: AnyObject {
|
|
125
|
+
var apiKey: String? { get }
|
|
126
|
+
var googleAppID: String? { get }
|
|
127
|
+
var projectID: String? { get }
|
|
128
|
+
var databaseURL: String? { get }
|
|
129
|
+
var storageBucket: String? { get }
|
|
130
|
+
var gcmSenderID: String? { get }
|
|
131
|
+
var clientID: String? { get }
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* FIRApp fields needed by SharedUtils FIR helpers.
|
|
136
|
+
*
|
|
137
|
+
* Production adapts live `FIRApp`; unit tests inject doubles.
|
|
138
|
+
*/
|
|
139
|
+
@objc public protocol RNFBFIRAppProviding: AnyObject {
|
|
140
|
+
var name: String { get }
|
|
141
|
+
var options: RNFBFIROptionsProviding { get }
|
|
142
|
+
|
|
143
|
+
@objc(isDataCollectionDefaultEnabled)
|
|
144
|
+
func isDataCollectionDefaultEnabled() -> Bool
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Custom auth-domain lookup previously hard-wired to `RNFBAppModule getCustomDomain:`.
|
|
149
|
+
*/
|
|
150
|
+
@objc public protocol RNFBCustomDomainProviding: AnyObject {
|
|
151
|
+
@objc(getCustomDomain:)
|
|
152
|
+
func getCustomDomain(_ appName: String) -> String?
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* JS event sink previously hard-wired to `RNFBRCTEventEmitter.shared`.
|
|
157
|
+
*/
|
|
158
|
+
@objc public protocol RNFBJSEventSending: AnyObject {
|
|
159
|
+
@objc(sendEventWithName:body:)
|
|
160
|
+
func sendEvent(name: String, body: Any?)
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* FIR app dictionary / JS-event helpers previously inline in `RNFBSharedUtils.m`.
|
|
165
|
+
*
|
|
166
|
+
* Mirrors pre-port:
|
|
167
|
+
* - `__FIRAPP_DEFAULT` → `[DEFAULT]` for `appConfig.name`
|
|
168
|
+
* - options keys from FIROptions; `authDomain` only when custom-domain provider returns non-nil
|
|
169
|
+
* - `sendJSEventForApp` mutably copies body, injects `appName` via JS name mapping, forwards to sender
|
|
170
|
+
*/
|
|
171
|
+
@objc(RNFBSharedUtilsFIRApp)
|
|
172
|
+
public final class RNFBSharedUtilsFIRApp: NSObject {
|
|
173
|
+
/// Matches `DEFAULT_APP_NAME` in `RNFBSharedUtils.m`.
|
|
174
|
+
private static let defaultAppName = "__FIRAPP_DEFAULT"
|
|
175
|
+
/// Matches `DEFAULT_APP_DISPLAY_NAME` in `RNFBSharedUtils.m`.
|
|
176
|
+
private static let defaultAppDisplayName = "[DEFAULT]"
|
|
177
|
+
|
|
178
|
+
/// Live `FIRApp` entry used by `RNFBSharedUtils`.
|
|
179
|
+
@objc(firAppToDictionaryFromFIRApp:customDomainProvider:)
|
|
180
|
+
public static func firAppToDictionary(
|
|
181
|
+
fromFIRApp firApp: NSObject,
|
|
182
|
+
customDomainProvider: RNFBCustomDomainProviding
|
|
183
|
+
) -> NSDictionary {
|
|
184
|
+
#if RNFB_DYNAMIC_FIREBASE_PROBE
|
|
185
|
+
firAppToDictionary(
|
|
186
|
+
RNFBOpaqueAppProvider(RNFBFirebaseAppClient.snapshot(of: firApp)),
|
|
187
|
+
customDomainProvider: customDomainProvider
|
|
188
|
+
)
|
|
189
|
+
#else
|
|
190
|
+
firAppToDictionary(
|
|
191
|
+
RNFBFIRAppAdapter(app: firApp as! FirebaseApp),
|
|
192
|
+
customDomainProvider: customDomainProvider
|
|
193
|
+
)
|
|
194
|
+
#endif
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@objc(firAppToDictionary:customDomainProvider:)
|
|
198
|
+
public static func firAppToDictionary(
|
|
199
|
+
_ app: RNFBFIRAppProviding,
|
|
200
|
+
customDomainProvider: RNFBCustomDomainProviding
|
|
201
|
+
) -> NSDictionary {
|
|
202
|
+
let firAppDictionary = NSMutableDictionary()
|
|
203
|
+
let firAppOptions = NSMutableDictionary()
|
|
204
|
+
let firAppConfig = NSMutableDictionary()
|
|
205
|
+
|
|
206
|
+
var name = app.name
|
|
207
|
+
if name == defaultAppName {
|
|
208
|
+
name = defaultAppDisplayName
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
firAppConfig["name"] = name
|
|
212
|
+
firAppConfig["automaticDataCollectionEnabled"] = NSNumber(
|
|
213
|
+
value: app.isDataCollectionDefaultEnabled()
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
let options = app.options
|
|
217
|
+
firAppOptions["apiKey"] = options.apiKey
|
|
218
|
+
firAppOptions["appId"] = options.googleAppID
|
|
219
|
+
firAppOptions["projectId"] = options.projectID
|
|
220
|
+
firAppOptions["databaseURL"] = options.databaseURL
|
|
221
|
+
firAppOptions["storageBucket"] = options.storageBucket
|
|
222
|
+
firAppOptions["messagingSenderId"] = options.gcmSenderID
|
|
223
|
+
// missing from android sdk - ios only:
|
|
224
|
+
firAppOptions["clientId"] = options.clientID
|
|
225
|
+
// not in FIROptions API but in JS SDK and project config JSON
|
|
226
|
+
if let customAuthDomain = customDomainProvider.getCustomDomain(name) {
|
|
227
|
+
firAppOptions["authDomain"] = customAuthDomain
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
firAppDictionary["options"] = firAppOptions
|
|
231
|
+
firAppDictionary["appConfig"] = firAppConfig
|
|
232
|
+
return firAppDictionary
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/// Live `FIRApp` entry used by `RNFBSharedUtils`.
|
|
236
|
+
@objc(sendJSEventForFIRApp:name:body:eventSender:)
|
|
237
|
+
public static func sendJSEvent(
|
|
238
|
+
forFIRApp firApp: NSObject,
|
|
239
|
+
name: String,
|
|
240
|
+
body: NSDictionary,
|
|
241
|
+
eventSender: RNFBJSEventSending
|
|
242
|
+
) {
|
|
243
|
+
#if RNFB_DYNAMIC_FIREBASE_PROBE
|
|
244
|
+
sendJSEvent(
|
|
245
|
+
forApp: RNFBOpaqueAppProvider(RNFBFirebaseAppClient.snapshot(of: firApp)),
|
|
246
|
+
name: name,
|
|
247
|
+
body: body,
|
|
248
|
+
eventSender: eventSender
|
|
249
|
+
)
|
|
250
|
+
#else
|
|
251
|
+
sendJSEvent(
|
|
252
|
+
forApp: RNFBFIRAppAdapter(app: firApp as! FirebaseApp),
|
|
253
|
+
name: name,
|
|
254
|
+
body: body,
|
|
255
|
+
eventSender: eventSender
|
|
256
|
+
)
|
|
257
|
+
#endif
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
@objc(sendJSEventForApp:name:body:eventSender:)
|
|
261
|
+
public static func sendJSEvent(
|
|
262
|
+
forApp app: RNFBFIRAppProviding,
|
|
263
|
+
name: String,
|
|
264
|
+
body: NSDictionary,
|
|
265
|
+
eventSender: RNFBJSEventSending
|
|
266
|
+
) {
|
|
267
|
+
let newBody = NSMutableDictionary(dictionary: body)
|
|
268
|
+
newBody["appName"] = RNFBSharedUtilsFormatting.getAppJavaScriptName(app.name)
|
|
269
|
+
eventSender.sendEvent(name: name, body: newBody)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import Foundation
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Name/date formatting helpers previously inline in `RNFBSharedUtils.m`.
|
|
21
|
+
*
|
|
22
|
+
* Mirrors pre-port:
|
|
23
|
+
* - `__FIRAPP_DEFAULT` → `[DEFAULT]` for JS app names
|
|
24
|
+
* - ISO-8601 via POSIX/`UTC` formatter + trailing `Z` (no fractional seconds)
|
|
25
|
+
*/
|
|
26
|
+
@objc(RNFBSharedUtilsFormatting)
|
|
27
|
+
public final class RNFBSharedUtilsFormatting: NSObject {
|
|
28
|
+
/// Matches `DEFAULT_APP_NAME` in `RNFBSharedUtils.m`.
|
|
29
|
+
private static let defaultAppName = "__FIRAPP_DEFAULT"
|
|
30
|
+
/// Matches `DEFAULT_APP_DISPLAY_NAME` in `RNFBSharedUtils.m`.
|
|
31
|
+
private static let defaultAppDisplayName = "[DEFAULT]"
|
|
32
|
+
|
|
33
|
+
private static let iso8601Formatter: DateFormatter = {
|
|
34
|
+
let formatter = DateFormatter()
|
|
35
|
+
formatter.locale = Locale(identifier: "en_US_POSIX")
|
|
36
|
+
formatter.timeZone = TimeZone(abbreviation: "UTC")
|
|
37
|
+
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
|
|
38
|
+
return formatter
|
|
39
|
+
}()
|
|
40
|
+
|
|
41
|
+
@objc(getAppJavaScriptName:)
|
|
42
|
+
public static func getAppJavaScriptName(_ appDisplayName: String?) -> String? {
|
|
43
|
+
guard let appDisplayName else {
|
|
44
|
+
return nil
|
|
45
|
+
}
|
|
46
|
+
if appDisplayName == defaultAppName {
|
|
47
|
+
return defaultAppDisplayName
|
|
48
|
+
}
|
|
49
|
+
return appDisplayName
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@objc(getISO8601String:)
|
|
53
|
+
public static func getISO8601String(_ date: Date?) -> String? {
|
|
54
|
+
guard let date else {
|
|
55
|
+
return nil
|
|
56
|
+
}
|
|
57
|
+
return iso8601Formatter.string(from: date) + "Z"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import Foundation
|
|
18
|
+
|
|
19
|
+
/// Reject callback matching `RCTPromiseRejectBlock` (`code`, `message`, `error`).
|
|
20
|
+
public typealias RNFBPromiseRejectCallback = (String?, String?, (any Error)?) -> Void
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Promise-rejection helpers previously inline in `RNFBSharedUtils.m`.
|
|
24
|
+
*
|
|
25
|
+
* Mirrors pre-port:
|
|
26
|
+
* - Constructed `NSError` always uses domain `RNFBErrorDomain` and code `666`
|
|
27
|
+
* - Exception path: fatal=YES, code="unknown", message/nativeErrorMessage=reason,
|
|
28
|
+
* nativeErrorCode=name; reject(name, reason, error)
|
|
29
|
+
* - NSError path: fatal=NO, code="unknown", message/nativeErrorMessage=localizedDescription,
|
|
30
|
+
* nativeErrorCode=@(error.code); reject("unknown", localizedDescription, newError)
|
|
31
|
+
* - UserInfo path: NSError from given userInfo; reject(userInfo["code"], userInfo["message"], error)
|
|
32
|
+
*/
|
|
33
|
+
@objc(RNFBSharedUtilsPromiseRejection)
|
|
34
|
+
public final class RNFBSharedUtilsPromiseRejection: NSObject {
|
|
35
|
+
/// Matches pre-port private `RNFBErrorDomain` in `RNFBSharedUtils.m`.
|
|
36
|
+
private static let errorDomain = "RNFBErrorDomain"
|
|
37
|
+
private static let constructedErrorCode = 666
|
|
38
|
+
|
|
39
|
+
@objc(rejectPromiseWithException:exception:)
|
|
40
|
+
public static func rejectPromise(
|
|
41
|
+
withException reject: @escaping RNFBPromiseRejectCallback,
|
|
42
|
+
exception: NSException
|
|
43
|
+
) {
|
|
44
|
+
let userInfo = NSMutableDictionary()
|
|
45
|
+
userInfo.setValue(true, forKey: "fatal")
|
|
46
|
+
userInfo.setValue("unknown", forKey: "code")
|
|
47
|
+
userInfo.setValue(exception.reason, forKey: "message")
|
|
48
|
+
userInfo.setValue(exception.name.rawValue, forKey: "nativeErrorCode")
|
|
49
|
+
userInfo.setValue(exception.reason, forKey: "nativeErrorMessage")
|
|
50
|
+
|
|
51
|
+
let error = makeError(userInfo: userInfo)
|
|
52
|
+
reject(exception.name.rawValue, exception.reason, error)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@objc(rejectPromiseWithNSError:error:)
|
|
56
|
+
public static func rejectPromise(
|
|
57
|
+
withNSError reject: @escaping RNFBPromiseRejectCallback,
|
|
58
|
+
error: NSError
|
|
59
|
+
) {
|
|
60
|
+
let userInfo = NSMutableDictionary()
|
|
61
|
+
userInfo.setValue(false, forKey: "fatal")
|
|
62
|
+
userInfo.setValue("unknown", forKey: "code")
|
|
63
|
+
userInfo.setValue(error.localizedDescription, forKey: "message")
|
|
64
|
+
userInfo.setValue(NSNumber(value: error.code), forKey: "nativeErrorCode")
|
|
65
|
+
userInfo.setValue(error.localizedDescription, forKey: "nativeErrorMessage")
|
|
66
|
+
|
|
67
|
+
let newError = makeError(userInfo: userInfo)
|
|
68
|
+
reject("unknown", error.localizedDescription, newError)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@objc(rejectPromiseWithUserInfo:userInfo:)
|
|
72
|
+
public static func rejectPromise(
|
|
73
|
+
withUserInfo reject: @escaping RNFBPromiseRejectCallback,
|
|
74
|
+
userInfo: NSMutableDictionary
|
|
75
|
+
) {
|
|
76
|
+
let error = makeError(userInfo: userInfo)
|
|
77
|
+
reject(userInfo["code"] as? String, userInfo["message"] as? String, error)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private static func makeError(userInfo: NSDictionary) -> NSError {
|
|
81
|
+
// NSDictionary bridges to [String: Any] for NSError when keys are strings.
|
|
82
|
+
NSError(
|
|
83
|
+
domain: errorDomain,
|
|
84
|
+
code: constructedErrorCode,
|
|
85
|
+
userInfo: (userInfo as! [String: Any])
|
|
86
|
+
)
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import Foundation
|
|
18
|
+
|
|
19
|
+
/// Path lookup previously hard-wired to `NSSearchPathForDirectoriesInDomains`.
|
|
20
|
+
public typealias RNFBUtilsPathProvider = (Int32) -> String?
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Foundation-pure helpers previously inline in `RNFBUtilsModule.mm`.
|
|
24
|
+
*
|
|
25
|
+
* Mirrors pre-port:
|
|
26
|
+
* - `pathForDirectory` → `NSSearchPathForDirectoriesInDomains(..., NSUserDomainMask, YES).firstObject`
|
|
27
|
+
* - constants keys + optional `appVersion` when `CFBundleShortVersionString` is a non-empty `NSString`
|
|
28
|
+
* - remote asset prefixes `assets-library://` / `ph://`
|
|
29
|
+
* - HEIC via `pathExtension` + `caseInsensitiveCompare:` (nil path → YES, matching ObjC nil messaging)
|
|
30
|
+
* - query item lookup via `NSPredicate` `name=%@` + `firstObject`
|
|
31
|
+
*/
|
|
32
|
+
@objc(RNFBUtilsHelpers)
|
|
33
|
+
public final class RNFBUtilsHelpers: NSObject {
|
|
34
|
+
@objc(pathForDirectory:)
|
|
35
|
+
public static func path(forDirectory directory: Int32) -> String? {
|
|
36
|
+
let searchDirectory = FileManager.SearchPathDirectory(rawValue: UInt(directory))!
|
|
37
|
+
let paths = NSSearchPathForDirectoriesInDomains(searchDirectory, .userDomainMask, true)
|
|
38
|
+
return paths.first
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@objc(utilsConstantsDictionary)
|
|
42
|
+
public static func utilsConstantsDictionary() -> NSDictionary {
|
|
43
|
+
utilsConstantsDictionary(
|
|
44
|
+
bundlePath: Bundle.main.bundlePath,
|
|
45
|
+
appVersion: Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString"),
|
|
46
|
+
pathProvider: { directory in path(forDirectory: directory) },
|
|
47
|
+
temporaryDirectory: NSTemporaryDirectory()
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@objc(utilsConstantsDictionaryWithBundlePath:appVersion:pathProvider:temporaryDirectory:)
|
|
52
|
+
public static func utilsConstantsDictionary(
|
|
53
|
+
bundlePath: String,
|
|
54
|
+
appVersion: Any?,
|
|
55
|
+
pathProvider: @escaping RNFBUtilsPathProvider,
|
|
56
|
+
temporaryDirectory: String
|
|
57
|
+
) -> NSDictionary {
|
|
58
|
+
let constants = NSMutableDictionary()
|
|
59
|
+
constants["isRunningInTestLab"] = NSNumber(value: false)
|
|
60
|
+
constants["MAIN_BUNDLE"] = bundlePath
|
|
61
|
+
constants["CACHES_DIRECTORY"] = pathProvider(
|
|
62
|
+
Int32(FileManager.SearchPathDirectory.cachesDirectory.rawValue)
|
|
63
|
+
)
|
|
64
|
+
constants["DOCUMENT_DIRECTORY"] = pathProvider(
|
|
65
|
+
Int32(FileManager.SearchPathDirectory.documentDirectory.rawValue)
|
|
66
|
+
)
|
|
67
|
+
constants["PICTURES_DIRECTORY"] = pathProvider(
|
|
68
|
+
Int32(FileManager.SearchPathDirectory.picturesDirectory.rawValue)
|
|
69
|
+
)
|
|
70
|
+
constants["MOVIES_DIRECTORY"] = pathProvider(
|
|
71
|
+
Int32(FileManager.SearchPathDirectory.moviesDirectory.rawValue)
|
|
72
|
+
)
|
|
73
|
+
constants["TEMP_DIRECTORY"] = temporaryDirectory
|
|
74
|
+
constants["LIBRARY_DIRECTORY"] = pathProvider(
|
|
75
|
+
Int32(FileManager.SearchPathDirectory.libraryDirectory.rawValue)
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
// Pre-port: `[appVersion isKindOfClass:[NSString class]] && appVersion.length > 0`
|
|
79
|
+
if let appVersion = appVersion as? String, !appVersion.isEmpty {
|
|
80
|
+
constants["appVersion"] = appVersion
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return constants.copy() as! NSDictionary
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@objc(isRemoteAsset:)
|
|
87
|
+
public static func isRemoteAsset(_ localFilePath: String?) -> Bool {
|
|
88
|
+
// Pre-port: nil receiver → hasPrefix returns NO
|
|
89
|
+
guard let localFilePath else {
|
|
90
|
+
return false
|
|
91
|
+
}
|
|
92
|
+
return localFilePath.hasPrefix("assets-library://") || localFilePath.hasPrefix("ph://")
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@objc(unused_isHeic:)
|
|
96
|
+
public static func unusedIsHeic(_ localFilePath: String?) -> Bool {
|
|
97
|
+
// Pre-port: `[[localFilePath pathExtension] caseInsensitiveCompare:@"heic"] == NSOrderedSame`
|
|
98
|
+
// Messaging nil returns 0 for NSComparisonResult → equals NSOrderedSame → YES.
|
|
99
|
+
let pathExtension = (localFilePath as NSString?)?.pathExtension
|
|
100
|
+
guard let pathExtension else {
|
|
101
|
+
return true
|
|
102
|
+
}
|
|
103
|
+
return (pathExtension as NSString).caseInsensitiveCompare("heic") == .orderedSame
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@objc(valueForKey:fromQueryItems:)
|
|
107
|
+
public static func value(forKey key: String?, fromQueryItems queryItems: [Any]?) -> String? {
|
|
108
|
+
// Pre-port: nil queryItems → filteredArray nil → firstObject nil → value nil
|
|
109
|
+
guard let queryItems else {
|
|
110
|
+
return nil
|
|
111
|
+
}
|
|
112
|
+
let predicate = NSPredicate(format: "name=%@", key ?? "")
|
|
113
|
+
let queryItem = (queryItems as NSArray).filtered(using: predicate).first as? URLQueryItem
|
|
114
|
+
return queryItem?.value
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
#import "RNFBUtilsModule.h"
|
|
19
|
+
|
|
20
|
+
#if __has_include(<RNFBApp/RNFBApp-Swift.h>)
|
|
21
|
+
#import <RNFBApp/RNFBApp-Swift.h>
|
|
22
|
+
#elif __has_include("RNFBApp-Swift.h")
|
|
23
|
+
#import "RNFBApp-Swift.h"
|
|
24
|
+
#elif __has_include("RNFBHandleMapStorage-Swift.inc")
|
|
25
|
+
#import "RNFBHandleMapStorage-Swift.inc"
|
|
26
|
+
#else
|
|
27
|
+
#error "RNFBApp Swift interface not found"
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
@implementation RNFBUtilsModule (FoundationHelpers)
|
|
31
|
+
|
|
32
|
+
+ (BOOL)isRemoteAsset:(NSString *)localFilePath {
|
|
33
|
+
return [RNFBUtilsHelpers isRemoteAsset:localFilePath];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
+ (BOOL)unused_isHeic:(NSString *)localFilePath {
|
|
37
|
+
return [RNFBUtilsHelpers unused_isHeic:localFilePath];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
+ (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems {
|
|
41
|
+
return [RNFBUtilsHelpers valueForKey:key fromQueryItems:queryItems];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
#import <Photos/Photos.h>
|
|
18
|
+
|
|
19
|
+
#import "RNFBUtilsModule.h"
|
|
20
|
+
|
|
21
|
+
@implementation RNFBUtilsModule (PhotoAssets)
|
|
22
|
+
|
|
23
|
+
+ (PHAsset *)fetchAssetForPath:(NSString *)localFilePath {
|
|
24
|
+
PHAsset *asset = nil;
|
|
25
|
+
|
|
26
|
+
if ([localFilePath hasPrefix:@"assets-library://"] || [localFilePath hasPrefix:@"ph://"]) {
|
|
27
|
+
if ([localFilePath hasPrefix:@"assets-library://"]) {
|
|
28
|
+
static BOOL hasWarned = NO;
|
|
29
|
+
if (!hasWarned) {
|
|
30
|
+
NSLog(@"'assets-library://' & 'ph://' URLs are not supported in Catalyst-based targets "
|
|
31
|
+
@"or iOS 12 and higher; returning nil (future warnings will be suppressed)");
|
|
32
|
+
hasWarned = YES;
|
|
33
|
+
}
|
|
34
|
+
} else {
|
|
35
|
+
NSString *assetId = [localFilePath substringFromIndex:@"ph://".length];
|
|
36
|
+
asset = [[PHAsset fetchAssetsWithLocalIdentifiers:@[ assetId ] options:nil] firstObject];
|
|
37
|
+
}
|
|
38
|
+
} else {
|
|
39
|
+
NSURLComponents *components = [NSURLComponents componentsWithString:localFilePath];
|
|
40
|
+
NSString *assetId = [self valueForKey:@"id" fromQueryItems:components.queryItems];
|
|
41
|
+
asset = [[PHAsset fetchAssetsWithLocalIdentifiers:@[ assetId ] options:nil] firstObject];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return asset;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
@end
|
|
@@ -16,13 +16,23 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
#import <Foundation/Foundation.h>
|
|
19
|
-
|
|
19
|
+
|
|
20
|
+
@class PHAsset;
|
|
20
21
|
|
|
21
22
|
@interface RNFBUtilsModule : NSObject
|
|
22
23
|
|
|
24
|
+
@end
|
|
25
|
+
|
|
26
|
+
@interface RNFBUtilsModule (FoundationHelpers)
|
|
27
|
+
|
|
23
28
|
+ (BOOL)isRemoteAsset:(NSString *)localFilePath;
|
|
24
29
|
+ (BOOL)unused_isHeic:(NSString *)localFilePath;
|
|
25
30
|
+ (NSString *)valueForKey:(NSString *)key fromQueryItems:(NSArray *)queryItems;
|
|
31
|
+
|
|
32
|
+
@end
|
|
33
|
+
|
|
34
|
+
@interface RNFBUtilsModule (PhotoAssets)
|
|
35
|
+
|
|
26
36
|
+ (PHAsset *)fetchAssetForPath:(NSString *)localFilePath;
|
|
27
37
|
|
|
28
38
|
@end
|