@react-native-firebase/app 26.3.3 → 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 +75 -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 +208 -60
- 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 +144 -13
- 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 -23
- package/dist/module/FirebaseApp.js +10 -0
- package/dist/module/FirebaseApp.js.map +1 -1
- package/dist/module/common/Base64.js +13 -21
- package/dist/module/common/Base64.js.map +1 -1
- package/dist/module/common/deeps.js +3 -0
- package/dist/module/common/deeps.js.map +1 -1
- package/dist/module/common/index.js +17 -9
- package/dist/module/common/index.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/asyncStorage.js +7 -11
- package/dist/module/internal/asyncStorage.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/logger.js +44 -40
- package/dist/module/internal/logger.js.map +1 -1
- package/dist/module/internal/nativeModuleAndroidIos.js +2 -29
- package/dist/module/internal/nativeModuleAndroidIos.js.map +1 -1
- package/dist/module/internal/nativeModuleDebug.js +74 -0
- package/dist/module/internal/nativeModuleDebug.js.map +1 -0
- package/dist/module/internal/nativeModuleWeb.js +9 -29
- package/dist/module/internal/nativeModuleWeb.js.map +1 -1
- package/dist/module/internal/registry/app.js +8 -2
- package/dist/module/internal/registry/app.js.map +1 -1
- package/dist/module/internal/registry/modular.js +2 -2
- package/dist/module/internal/registry/modular.js.map +1 -1
- package/dist/module/internal/registry/nativeModule.js +3 -3
- package/dist/module/internal/registry/nativeModule.js.map +1 -1
- package/dist/module/internal/web/RNFBAppModule.js +16 -15
- package/dist/module/internal/web/RNFBAppModule.js.map +1 -1
- package/dist/module/internal/web/memidb/lib/FakeEventTarget.js +3 -1
- package/dist/module/internal/web/memidb/lib/FakeEventTarget.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/Base64.d.ts.map +1 -1
- package/dist/typescript/lib/common/deeps.d.ts.map +1 -1
- package/dist/typescript/lib/common/index.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/asyncStorage.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/logger.d.ts.map +1 -1
- package/dist/typescript/lib/internal/nativeModuleAndroidIos.d.ts.map +1 -1
- package/dist/typescript/lib/internal/nativeModuleDebug.d.ts +2 -0
- package/dist/typescript/lib/internal/nativeModuleDebug.d.ts.map +1 -0
- package/dist/typescript/lib/internal/nativeModuleWeb.d.ts.map +1 -1
- package/dist/typescript/lib/internal/registry/app.d.ts.map +1 -1
- package/dist/typescript/lib/internal/web/RNFBAppModule.d.ts +7 -7
- package/dist/typescript/lib/internal/web/RNFBAppModule.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 +5 -1
- 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 +67 -204
- 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.h +73 -0
- package/ios/RNFBApp/RNFBHandleMap.m +87 -0
- 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 -197
- 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 +106 -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 +590 -0
- package/ios/RNFBAppUnitTests/RNFBAppUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBAppUnitTests.xcscheme +69 -0
- package/ios/RNFBAppUnitTests/RNFBFirebaseAppClientTests.swift +165 -0
- package/ios/RNFBAppUnitTests/RNFBHandleMapStorageTests.swift +121 -0
- package/ios/RNFBAppUnitTests/RNFBHandleMapTests.m +238 -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/reactnative/java/io/invertase/firebase/app/ReactNativeFirebaseAppRegistrar.java → ios/RNFBFirebaseUnitTests/RNFBFirebaseClientImport.swift} +22 -17
- 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/Base64.ts +10 -16
- package/lib/common/deeps.ts +3 -0
- package/lib/common/index.ts +20 -9
- 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/asyncStorage.ts +7 -11
- package/lib/internal/index.ts +1 -0
- package/lib/internal/logger.ts +53 -43
- package/lib/internal/nativeModuleAndroidIos.ts +2 -40
- package/lib/internal/nativeModuleDebug.ts +97 -0
- package/lib/internal/nativeModuleWeb.ts +10 -40
- package/lib/internal/react-native-vendor-emitter.d.ts +11 -0
- package/lib/internal/registry/app.ts +8 -2
- package/lib/internal/registry/modular.ts +2 -2
- package/lib/internal/registry/nativeModule.ts +3 -3
- package/lib/internal/web/RNFBAppModule.ts +16 -15
- package/lib/internal/web/memidb/lib/FakeEventTarget.js +3 -1
- package/lib/types/app.ts +10 -3
- package/lib/types/internal.ts +19 -0
- package/lib/version.ts +1 -1
- package/package.json +9 -8
- package/plugin/build/ios/appDelegate.js +19 -9
- package/plugin/build/ios/podfile.js +16 -16
- package/plugin/build/pluginConfig.d.ts +4 -2
- package/plugin/src/ios/appDelegate.ts +45 -15
- package/plugin/src/ios/podfile.ts +20 -23
- package/plugin/src/pluginConfig.ts +4 -2
- package/android/src/main/java/io/invertase/firebase/common/TaskExecutorService.java +0 -124
- 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 -222
- 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/common/RCTConvertFirebase.java +0 -191
- 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 -107
- 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
|
@@ -0,0 +1,135 @@
|
|
|
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
|
+
* Decodes `{ "__rnfbNull": true }` sentinel dictionaries produced by the JS bridge
|
|
21
|
+
* into `NSNull`, walking nested arrays/dictionaries iteratively.
|
|
22
|
+
*
|
|
23
|
+
* The flag must be an `NSNumber` (JS sends boolean `true`). String flags are not
|
|
24
|
+
* treated as sentinels.
|
|
25
|
+
*/
|
|
26
|
+
@objc(RNFBNullSentinelDecoder)
|
|
27
|
+
public final class RNFBNullSentinelDecoder: NSObject {
|
|
28
|
+
private static let sentinelKey = "__rnfbNull"
|
|
29
|
+
|
|
30
|
+
@objc(decodeNullSentinels:)
|
|
31
|
+
public static func decodeNullSentinels(_ value: Any?) -> Any? {
|
|
32
|
+
decode(value)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@objc(decode:)
|
|
36
|
+
public static func decode(_ value: Any?) -> Any? {
|
|
37
|
+
guard let value else {
|
|
38
|
+
return nil
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Non-container values are returned as-is (identity preserved).
|
|
42
|
+
guard value is NSDictionary || value is NSArray else {
|
|
43
|
+
return value
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if let dict = value as? NSDictionary, isNullSentinel(dict) {
|
|
47
|
+
return NSNull()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
let rootMutable: AnyObject
|
|
51
|
+
if let dict = value as? NSDictionary {
|
|
52
|
+
rootMutable = NSMutableDictionary(capacity: dict.count)
|
|
53
|
+
} else {
|
|
54
|
+
let array = value as! NSArray
|
|
55
|
+
rootMutable = NSMutableArray(capacity: array.count)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Stack frames: (original container, mutable container)
|
|
59
|
+
var stack: [(original: AnyObject, mutable: AnyObject)] = [
|
|
60
|
+
(value as AnyObject, rootMutable),
|
|
61
|
+
]
|
|
62
|
+
|
|
63
|
+
while let frame = stack.popLast() {
|
|
64
|
+
if let origDict = frame.original as? NSDictionary {
|
|
65
|
+
let mutableDict = frame.mutable as! NSMutableDictionary
|
|
66
|
+
for key in origDict.allKeys {
|
|
67
|
+
let child = origDict[key]
|
|
68
|
+
processChild(
|
|
69
|
+
child,
|
|
70
|
+
parentMutable: mutableDict,
|
|
71
|
+
key: (key as! any NSCopying),
|
|
72
|
+
isParentDict: true,
|
|
73
|
+
stack: &stack
|
|
74
|
+
)
|
|
75
|
+
}
|
|
76
|
+
} else if let origArray = frame.original as? NSArray {
|
|
77
|
+
let mutableArray = frame.mutable as! NSMutableArray
|
|
78
|
+
for child in origArray {
|
|
79
|
+
processChild(
|
|
80
|
+
child,
|
|
81
|
+
parentMutable: mutableArray,
|
|
82
|
+
key: nil,
|
|
83
|
+
isParentDict: false,
|
|
84
|
+
stack: &stack
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return rootMutable
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// Flag must be an NSNumber whose `boolValue` is true. Strings and other types are not sentinels.
|
|
94
|
+
private static func isNullSentinel(_ dict: NSDictionary) -> Bool {
|
|
95
|
+
guard dict.count == 1, let flag = dict[sentinelKey] as? NSNumber else {
|
|
96
|
+
return false
|
|
97
|
+
}
|
|
98
|
+
return flag.boolValue
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
private static func processChild(
|
|
102
|
+
_ child: Any?,
|
|
103
|
+
parentMutable: AnyObject,
|
|
104
|
+
key: NSCopying?,
|
|
105
|
+
isParentDict: Bool,
|
|
106
|
+
stack: inout [(original: AnyObject, mutable: AnyObject)]
|
|
107
|
+
) {
|
|
108
|
+
let processedValue: AnyObject
|
|
109
|
+
|
|
110
|
+
if let childDict = child as? NSDictionary {
|
|
111
|
+
if isNullSentinel(childDict) {
|
|
112
|
+
processedValue = NSNull()
|
|
113
|
+
} else {
|
|
114
|
+
let childMut = NSMutableDictionary(capacity: childDict.count)
|
|
115
|
+
processedValue = childMut
|
|
116
|
+
stack.append((childDict, childMut))
|
|
117
|
+
}
|
|
118
|
+
} else if let childArray = child as? NSArray {
|
|
119
|
+
let childMut = NSMutableArray(capacity: childArray.count)
|
|
120
|
+
processedValue = childMut
|
|
121
|
+
stack.append((childArray, childMut))
|
|
122
|
+
} else {
|
|
123
|
+
// Preserve primitives; nil → NSNull (enumeration never yields nil).
|
|
124
|
+
processedValue = (child as AnyObject?) ?? NSNull()
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if isParentDict {
|
|
128
|
+
let mutDict = parentMutable as! NSMutableDictionary
|
|
129
|
+
mutDict[key!] = processedValue
|
|
130
|
+
} else {
|
|
131
|
+
let mutArray = parentMutable as! NSMutableArray
|
|
132
|
+
mutArray.add(processedValue)
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -32,15 +32,42 @@
|
|
|
32
32
|
* This class uses method swizzling on RCTCxxConvert to intercept all TurboModule
|
|
33
33
|
* data conversion methods (JS_*Module_Spec*Data:), decoding sentinels before the
|
|
34
34
|
* data reaches the C++ bridging layer and ultimately your module methods.
|
|
35
|
+
*
|
|
36
|
+
* Swizzling is scheduled on the main queue from +load so codegen category methods
|
|
37
|
+
* on RCTCxxConvert are attached before the method list is copied.
|
|
35
38
|
*/
|
|
36
39
|
@interface RNFBNullSentinelInterceptor : NSObject
|
|
37
40
|
|
|
38
41
|
/**
|
|
39
|
-
*
|
|
40
|
-
* This swizzles RCTCxxConvert (TurboModule converter) to automatically decode null sentinels.
|
|
42
|
+
* Schedules TurboModule converter swizzling on the main queue.
|
|
41
43
|
* Called automatically when the class is loaded via +load.
|
|
42
44
|
*/
|
|
43
|
-
+ (void)
|
|
45
|
+
+ (void)load;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Production entry used by +load. Schedules swizzleRCTConvertMethods on the main
|
|
49
|
+
* queue behind a process-wide once-token.
|
|
50
|
+
*/
|
|
51
|
+
+ (void)scheduleSwizzleOnMainQueue;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Testable schedule path. When turboConvertClass is Nil, behaves like production
|
|
55
|
+
* (swizzleRCTConvertMethods). When non-Nil, swizzles that class instead so unit
|
|
56
|
+
* tests can observe deferral without RCTCxxConvert.
|
|
57
|
+
*/
|
|
58
|
+
+ (void)scheduleSwizzleOnMainQueueWithOnceToken:(dispatch_once_t *)onceToken
|
|
59
|
+
turboConvertClass:(Class)turboConvertClass;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Looks up RCTCxxConvert and swizzles matching TurboModule conversion methods.
|
|
63
|
+
*/
|
|
64
|
+
+ (void)swizzleRCTConvertMethods;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Swizzles JS_NativeRNFBTurbo*_Spec* class methods on the given converter class
|
|
68
|
+
* so decodeNullSentinels runs before the original IMP.
|
|
69
|
+
*/
|
|
70
|
+
+ (void)swizzleTurboModuleConversions:(Class)cxxConvertClass;
|
|
44
71
|
|
|
45
72
|
@end
|
|
46
73
|
|
|
@@ -17,14 +17,38 @@
|
|
|
17
17
|
|
|
18
18
|
#import "RNFBNullSentinelInterceptor.h"
|
|
19
19
|
#import <objc/runtime.h>
|
|
20
|
-
|
|
20
|
+
|
|
21
|
+
#if __has_include(<RNFBApp/RNFBApp-Swift.h>)
|
|
22
|
+
#import <RNFBApp/RNFBApp-Swift.h>
|
|
23
|
+
#elif __has_include("RNFBApp-Swift.h")
|
|
24
|
+
#import "RNFBApp-Swift.h"
|
|
25
|
+
#elif __has_include("RNFBHandleMapStorage-Swift.inc")
|
|
26
|
+
#import "RNFBHandleMapStorage-Swift.inc"
|
|
27
|
+
#else
|
|
28
|
+
#error "RNFBApp Swift interface not found"
|
|
29
|
+
#endif
|
|
21
30
|
|
|
22
31
|
@implementation RNFBNullSentinelInterceptor
|
|
23
32
|
|
|
24
33
|
+ (void)load {
|
|
34
|
+
[self scheduleSwizzleOnMainQueue];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
+ (void)scheduleSwizzleOnMainQueue {
|
|
25
38
|
static dispatch_once_t onceToken;
|
|
26
|
-
|
|
27
|
-
|
|
39
|
+
[self scheduleSwizzleOnMainQueueWithOnceToken:&onceToken turboConvertClass:Nil];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
+ (void)scheduleSwizzleOnMainQueueWithOnceToken:(dispatch_once_t *)onceToken
|
|
43
|
+
turboConvertClass:(Class)turboConvertClass {
|
|
44
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
45
|
+
dispatch_once(onceToken, ^{
|
|
46
|
+
if (turboConvertClass) {
|
|
47
|
+
[self swizzleTurboModuleConversions:turboConvertClass];
|
|
48
|
+
} else {
|
|
49
|
+
[self swizzleRCTConvertMethods];
|
|
50
|
+
}
|
|
51
|
+
});
|
|
28
52
|
});
|
|
29
53
|
}
|
|
30
54
|
|
|
@@ -51,12 +75,11 @@
|
|
|
51
75
|
if ([selectorName hasPrefix:@"JS_NativeRNFBTurbo"] && [selectorName containsString:@"_Spec"]) {
|
|
52
76
|
// Create a swizzled version using IMP
|
|
53
77
|
IMP originalIMP = method_getImplementation(method);
|
|
54
|
-
const char *typeEncoding = method_getTypeEncoding(method);
|
|
55
78
|
|
|
56
79
|
// Replace with our wrapper that decodes nulls
|
|
57
80
|
IMP newIMP = imp_implementationWithBlock(^id(id self, id json) {
|
|
58
81
|
// Decode null sentinels before passing to original conversion
|
|
59
|
-
id decoded = [
|
|
82
|
+
id decoded = [RNFBNullSentinelDecoder decodeNullSentinels:json];
|
|
60
83
|
|
|
61
84
|
// Call original implementation with decoded data
|
|
62
85
|
typedef id (*OriginalFunc)(id, SEL, id);
|
|
@@ -17,12 +17,20 @@
|
|
|
17
17
|
|
|
18
18
|
#import "RNFBPreferences.h"
|
|
19
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 "RNFBPreferencesStorage Swift interface not found"
|
|
28
|
+
#endif
|
|
29
|
+
|
|
20
30
|
@interface RNFBPreferences ()
|
|
21
|
-
@property(nonatomic, strong)
|
|
31
|
+
@property(nonatomic, strong) RNFBPreferencesStorage *storage;
|
|
22
32
|
@end
|
|
23
33
|
|
|
24
|
-
static NSString *const RNFBDomainIdentifier = @"io.invertase.firebase";
|
|
25
|
-
|
|
26
34
|
@implementation RNFBPreferences
|
|
27
35
|
|
|
28
36
|
static RNFBPreferences *sharedInstance;
|
|
@@ -35,56 +43,50 @@ static RNFBPreferences *sharedInstance;
|
|
|
35
43
|
self = [super init];
|
|
36
44
|
|
|
37
45
|
if (self) {
|
|
38
|
-
|
|
46
|
+
_storage = [[RNFBPreferencesStorage alloc] init];
|
|
39
47
|
}
|
|
40
48
|
|
|
41
49
|
return self;
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
- (BOOL)contains:(NSString *)key {
|
|
45
|
-
return [
|
|
53
|
+
return [self.storage contains:key];
|
|
46
54
|
}
|
|
47
55
|
|
|
48
56
|
- (BOOL)getBooleanValue:(NSString *)key defaultValue:(BOOL)defaultValue {
|
|
49
|
-
|
|
50
|
-
return [_userDefaults boolForKey:key];
|
|
57
|
+
return [self.storage getBooleanValue:key defaultValue:defaultValue];
|
|
51
58
|
}
|
|
52
59
|
|
|
53
60
|
- (void)setBooleanValue:(NSString *)key boolValue:(BOOL)boolValue {
|
|
54
|
-
[
|
|
55
|
-
[_userDefaults synchronize];
|
|
61
|
+
[self.storage setBooleanValue:key boolValue:boolValue];
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
- (void)setIntegerValue:(NSString *)key integerValue:(NSInteger)integerValue {
|
|
59
|
-
[
|
|
60
|
-
[_userDefaults synchronize];
|
|
65
|
+
[self.storage setIntegerValue:key integerValue:integerValue];
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
- (NSInteger)getIntegerValue:(NSString *)key defaultValue:(NSInteger)defaultValue {
|
|
64
|
-
|
|
65
|
-
return [_userDefaults integerForKey:key];
|
|
69
|
+
return [self.storage getIntegerValue:key defaultValue:defaultValue];
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
- (NSString *)getStringValue:(NSString *)key defaultValue:(NSString *)defaultValue {
|
|
69
|
-
|
|
70
|
-
return [_userDefaults stringForKey:key];
|
|
73
|
+
return [self.storage getStringValue:key defaultValue:defaultValue];
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
- (void)setStringValue:(NSString *)key stringValue:(NSString *)stringValue {
|
|
74
|
-
[
|
|
75
|
-
[_userDefaults synchronize];
|
|
77
|
+
[self.storage setStringValue:key stringValue:stringValue];
|
|
76
78
|
}
|
|
77
79
|
|
|
78
80
|
- (NSDictionary *)getAll {
|
|
79
|
-
return [
|
|
81
|
+
return [self.storage getAll];
|
|
80
82
|
}
|
|
81
83
|
|
|
82
84
|
- (void)clearAll {
|
|
83
|
-
[
|
|
85
|
+
[self.storage clearAll];
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
- (void)remove:(NSString *)key {
|
|
87
|
-
[
|
|
89
|
+
[self.storage remove:key];
|
|
88
90
|
}
|
|
89
91
|
|
|
90
92
|
+ (RNFBPreferences *)shared {
|
|
@@ -0,0 +1,101 @@
|
|
|
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
|
+
private let RNFBPreferencesDomainIdentifier = "io.invertase.firebase"
|
|
20
|
+
|
|
21
|
+
@objc(RNFBPreferencesStorage)
|
|
22
|
+
public final class RNFBPreferencesStorage: NSObject {
|
|
23
|
+
private let userDefaults: UserDefaults
|
|
24
|
+
private let domainIdentifier: String
|
|
25
|
+
|
|
26
|
+
public override convenience init() {
|
|
27
|
+
self.init(
|
|
28
|
+
userDefaults: UserDefaults(suiteName: RNFBPreferencesDomainIdentifier)!,
|
|
29
|
+
domainIdentifier: RNFBPreferencesDomainIdentifier
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@objc(initWithUserDefaults:domainIdentifier:)
|
|
34
|
+
public init(userDefaults: UserDefaults, domainIdentifier: String) {
|
|
35
|
+
self.userDefaults = userDefaults
|
|
36
|
+
self.domainIdentifier = domainIdentifier
|
|
37
|
+
super.init()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@objc(contains:)
|
|
41
|
+
public func contains(_ key: String) -> Bool {
|
|
42
|
+
userDefaults.object(forKey: key) != nil
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@objc(getBooleanValue:defaultValue:)
|
|
46
|
+
public func getBooleanValue(_ key: String, defaultValue: Bool) -> Bool {
|
|
47
|
+
guard contains(key) else {
|
|
48
|
+
return defaultValue
|
|
49
|
+
}
|
|
50
|
+
return userDefaults.bool(forKey: key)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@objc(setBooleanValue:boolValue:)
|
|
54
|
+
public func setBooleanValue(_ key: String, boolValue: Bool) {
|
|
55
|
+
userDefaults.set(boolValue, forKey: key)
|
|
56
|
+
userDefaults.synchronize()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@objc(setIntegerValue:integerValue:)
|
|
60
|
+
public func setIntegerValue(_ key: String, integerValue: Int) {
|
|
61
|
+
userDefaults.set(integerValue, forKey: key)
|
|
62
|
+
userDefaults.synchronize()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@objc(getIntegerValue:defaultValue:)
|
|
66
|
+
public func getIntegerValue(_ key: String, defaultValue: Int) -> Int {
|
|
67
|
+
guard contains(key) else {
|
|
68
|
+
return defaultValue
|
|
69
|
+
}
|
|
70
|
+
return userDefaults.integer(forKey: key)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@objc(getStringValue:defaultValue:)
|
|
74
|
+
public func getStringValue(_ key: String, defaultValue: String) -> String? {
|
|
75
|
+
guard contains(key) else {
|
|
76
|
+
return defaultValue
|
|
77
|
+
}
|
|
78
|
+
return userDefaults.string(forKey: key)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@objc(setStringValue:stringValue:)
|
|
82
|
+
public func setStringValue(_ key: String, stringValue: String) {
|
|
83
|
+
userDefaults.set(stringValue, forKey: key)
|
|
84
|
+
userDefaults.synchronize()
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@objc
|
|
88
|
+
public func getAll() -> [String: Any] {
|
|
89
|
+
userDefaults.dictionaryRepresentation()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@objc
|
|
93
|
+
public func clearAll() {
|
|
94
|
+
userDefaults.removePersistentDomain(forName: domainIdentifier)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@objc(remove:)
|
|
98
|
+
public func remove(_ key: String) {
|
|
99
|
+
userDefaults.removeObject(forKey: key)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -17,26 +17,24 @@
|
|
|
17
17
|
|
|
18
18
|
#import "RNFBRCTEventEmitter.h"
|
|
19
19
|
|
|
20
|
+
#import <React/RCTBridge.h>
|
|
21
|
+
|
|
22
|
+
#if __has_include(<RNFBApp/RNFBApp-Swift.h>)
|
|
23
|
+
#import <RNFBApp/RNFBApp-Swift.h>
|
|
24
|
+
#elif __has_include("RNFBApp-Swift.h")
|
|
25
|
+
#import "RNFBApp-Swift.h"
|
|
26
|
+
#elif __has_include("RNFBHandleMapStorage-Swift.inc")
|
|
27
|
+
#import "RNFBHandleMapStorage-Swift.inc"
|
|
28
|
+
#else
|
|
29
|
+
#error "RNFBRCTEventEmitterCore Swift interface not found"
|
|
30
|
+
#endif
|
|
31
|
+
|
|
20
32
|
@interface RNFBRCTEventEmitter ()
|
|
21
|
-
@property(
|
|
22
|
-
@property(atomic, assign) NSInteger jsListenerCount;
|
|
23
|
-
@property(nonatomic, strong) NSMutableDictionary *jsListeners;
|
|
24
|
-
@property(nonatomic, strong) NSMutableArray *queuedEvents;
|
|
25
|
-
@property(readonly) BOOL isObserving;
|
|
33
|
+
@property(nonatomic, strong) RNFBRCTEventEmitterCore *core;
|
|
26
34
|
@end
|
|
27
35
|
|
|
28
|
-
NSString *const RNFBRCTEventNameKey = @"name";
|
|
29
|
-
NSString *const RNFBRCTEventBodyKey = @"body";
|
|
30
|
-
|
|
31
36
|
@implementation RNFBRCTEventEmitter
|
|
32
37
|
|
|
33
|
-
- (void)invalidate {
|
|
34
|
-
self.jsReady = FALSE;
|
|
35
|
-
self.queuedEvents = [NSMutableArray array];
|
|
36
|
-
self.jsListeners = [NSMutableDictionary dictionary];
|
|
37
|
-
self.jsListenerCount = 0;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
38
|
+ (instancetype)shared {
|
|
41
39
|
static dispatch_once_t once;
|
|
42
40
|
static RNFBRCTEventEmitter *sharedInstance;
|
|
@@ -50,102 +48,47 @@ NSString *const RNFBRCTEventBodyKey = @"body";
|
|
|
50
48
|
self = [super init];
|
|
51
49
|
|
|
52
50
|
if (self) {
|
|
53
|
-
self
|
|
54
|
-
|
|
55
|
-
|
|
51
|
+
__weak typeof(self) weakSelf = self;
|
|
52
|
+
_core = [[RNFBRCTEventEmitterCore alloc]
|
|
53
|
+
initWithIsBridgePresent:^BOOL {
|
|
54
|
+
return weakSelf.bridge != nil;
|
|
55
|
+
}
|
|
56
|
+
emitHandler:^(NSString *eventName, id body) {
|
|
57
|
+
__strong typeof(weakSelf) strongSelf = weakSelf;
|
|
58
|
+
NSString *prefixedEventName = [@"rnfb_" stringByAppendingString:eventName];
|
|
59
|
+
[strongSelf.bridge
|
|
60
|
+
enqueueJSCall:@"RCTDeviceEventEmitter"
|
|
61
|
+
method:@"emit"
|
|
62
|
+
args:body ? @[ prefixedEventName, body ] : @[ prefixedEventName ]
|
|
63
|
+
completion:NULL];
|
|
64
|
+
}];
|
|
56
65
|
}
|
|
57
66
|
|
|
58
67
|
return self;
|
|
59
68
|
}
|
|
60
69
|
|
|
70
|
+
- (void)invalidate {
|
|
71
|
+
[self.core invalidate];
|
|
72
|
+
}
|
|
73
|
+
|
|
61
74
|
- (void)notifyJsReady:(BOOL)jsReady {
|
|
62
|
-
|
|
63
|
-
self.jsReady = jsReady;
|
|
64
|
-
if (jsReady) {
|
|
65
|
-
for (id event in [self.queuedEvents copy]) {
|
|
66
|
-
[self sendEventWithName:event[RNFBRCTEventNameKey] body:event[RNFBRCTEventBodyKey]];
|
|
67
|
-
@synchronized(self.queuedEvents) {
|
|
68
|
-
[self.queuedEvents removeObject:event];
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
75
|
+
[self.core notifyJsReady:jsReady];
|
|
73
76
|
}
|
|
74
77
|
|
|
75
78
|
- (void)sendEventWithName:(NSString *)eventName body:(id)body {
|
|
76
|
-
|
|
77
|
-
if (self.bridge && self.isObserving && self.jsListeners[eventName] != nil) {
|
|
78
|
-
NSString *prefixedEventName = [@"rnfb_" stringByAppendingString:eventName];
|
|
79
|
-
[self.bridge enqueueJSCall:@"RCTDeviceEventEmitter"
|
|
80
|
-
method:@"emit"
|
|
81
|
-
args:body ? @[ prefixedEventName, body ] : @[ prefixedEventName ]
|
|
82
|
-
completion:NULL];
|
|
83
|
-
} else {
|
|
84
|
-
@synchronized(self.queuedEvents) {
|
|
85
|
-
[self.queuedEvents
|
|
86
|
-
addObject:@{RNFBRCTEventNameKey : eventName, RNFBRCTEventBodyKey : body}];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
79
|
+
[self.core sendEventWithName:eventName body:body];
|
|
90
80
|
}
|
|
91
81
|
|
|
92
82
|
- (void)addListener:(NSString *)eventName {
|
|
93
|
-
|
|
94
|
-
self.jsListenerCount++;
|
|
95
|
-
|
|
96
|
-
if (self.jsListeners[eventName] == nil) {
|
|
97
|
-
self.jsListeners[eventName] = @([@1 integerValue]);
|
|
98
|
-
} else {
|
|
99
|
-
self.jsListeners[eventName] =
|
|
100
|
-
@([self.jsListeners[eventName] integerValue] + [@1 integerValue]);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
for (id event in [self.queuedEvents copy]) {
|
|
104
|
-
if ([event[RNFBRCTEventNameKey] isEqualToString:eventName]) {
|
|
105
|
-
[self sendEventWithName:event[RNFBRCTEventNameKey] body:event[RNFBRCTEventBodyKey]];
|
|
106
|
-
@synchronized(self.queuedEvents) {
|
|
107
|
-
[self.queuedEvents removeObject:event];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
83
|
+
[self.core addListener:eventName];
|
|
112
84
|
}
|
|
113
85
|
|
|
114
86
|
- (void)removeListeners:(NSString *)eventName all:(BOOL)all {
|
|
115
|
-
|
|
116
|
-
if (self.jsListeners[eventName] != nil) {
|
|
117
|
-
NSInteger listenersForEvent = [self.jsListeners[eventName] integerValue];
|
|
118
|
-
|
|
119
|
-
if (listenersForEvent <= 1 || all) {
|
|
120
|
-
@synchronized(self.jsListeners) {
|
|
121
|
-
[self.jsListeners removeObjectForKey:eventName];
|
|
122
|
-
}
|
|
123
|
-
} else {
|
|
124
|
-
@synchronized(self.jsListeners) {
|
|
125
|
-
self.jsListeners[eventName] =
|
|
126
|
-
@([self.jsListeners[eventName] integerValue] - [@1 integerValue]);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (all) {
|
|
131
|
-
self.jsListenerCount = self.jsListenerCount - listenersForEvent;
|
|
132
|
-
} else {
|
|
133
|
-
self.jsListenerCount = self.jsListenerCount - [@1 integerValue];
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
87
|
+
[self.core removeListeners:eventName all:all];
|
|
137
88
|
}
|
|
138
89
|
|
|
139
90
|
- (NSDictionary *)getListenersDictionary {
|
|
140
|
-
|
|
141
|
-
listenersDictionary[@"listeners"] = @(self.jsListenerCount);
|
|
142
|
-
listenersDictionary[@"queued"] = @([self.queuedEvents count]);
|
|
143
|
-
listenersDictionary[@"events"] = [self.jsListeners copy];
|
|
144
|
-
return listenersDictionary;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
- (BOOL)isObserving {
|
|
148
|
-
return self.jsReady && self.jsListenerCount > 0;
|
|
91
|
+
return [self.core getListenersDictionary];
|
|
149
92
|
}
|
|
150
93
|
|
|
151
94
|
@end
|