react-native-daro 1.0.13 → 1.0.16
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/LICENSE +1 -1
- package/README.md +30 -30
- package/android/build.gradle +52 -59
- package/android/src/admob/java/com/daro/reactnative/DaroSdkBridge.kt +23 -0
- package/android/src/main/AndroidManifest.xml +1 -2
- package/android/src/main/java/com/{darom → daro/reactnative}/DaroMAdBannerViewManager.kt +38 -15
- package/android/src/main/java/com/daro/reactnative/DaroMAdNativeViewManager.kt +167 -0
- package/android/src/main/java/com/daro/reactnative/DaroMModule.kt +257 -0
- package/android/src/main/java/com/daro/reactnative/DaroMPackage.kt +45 -0
- package/android/src/main/java/com/daro/reactnative/DaroMediaViewManager.kt +25 -0
- package/android/src/main/java/com/{darom → daro/reactnative}/constants/InternalDaroMBannerSize.kt +1 -1
- package/android/src/main/java/com/{darom → daro/reactnative}/event/DaroMEvent.kt +19 -8
- package/android/src/main/java/com/{darom → daro/reactnative}/impl/DaroMBannerViewModuleImpl.kt +2 -2
- package/android/src/main/java/com/{darom → daro/reactnative}/impl/DaroMInterstitialModuleImpl.kt +26 -26
- package/android/src/main/java/com/{darom → daro/reactnative}/impl/DaroMLightPopupModuleImpl.kt +30 -29
- package/android/src/main/java/com/{darom → daro/reactnative}/impl/DaroMRewardedAdModuleImpl.kt +27 -27
- package/android/src/main/java/com/{darom → daro/reactnative}/util/AdInfoUtil.kt +25 -1
- package/android/src/main/java/com/daro/reactnative/util/EventEmitterUtil.kt +37 -0
- package/android/src/main/java/com/daro/reactnative/view/DaroMAdBannerViewContainer.kt +417 -0
- package/android/src/main/java/com/daro/reactnative/view/DaroMAdNativeViewContainer.kt +624 -0
- package/android/src/main/java/com/daro/reactnative/view/DaroMediaView.kt +123 -0
- package/android/src/newarch/java/com/daro/reactnative/DaroMModuleSpec.kt +6 -0
- package/android/src/oldarch/java/com/daro/reactnative/DaroMModuleSpec.kt +90 -0
- package/app.plugin.js +1 -0
- package/ios/DaroMModule+AppOpen.swift +38 -32
- package/ios/DaroMModule+Interstitial.swift +32 -26
- package/ios/DaroMModule+LightPopup.swift +43 -33
- package/ios/DaroMModule+Rewarded.swift +38 -27
- package/ios/DaroMModule.mm +45 -17
- package/ios/DaroMModule.swift +24 -17
- package/ios/Fabric/DaroMAdBannerComponentView.mm +207 -0
- package/ios/Fabric/DaroMFabricEventSink.mm +31 -0
- package/ios/Fabric/DaroMFabricPropApplier.mm +123 -0
- package/ios/Fabric/DaroMNativeAdComponentView.mm +294 -0
- package/ios/{DaroMAdBannerViewManager.m → Paper/DaroMAdBannerViewManager.m} +3 -1
- package/ios/Paper/DaroMAdBannerViewManager.swift +21 -0
- package/ios/{DaroMNativeAdViewManager.m → Paper/DaroMNativeAdViewManager.m} +2 -1
- package/ios/Paper/DaroMNativeAdViewManager.swift +22 -0
- package/ios/Shared/DaroMAdEventSink.swift +24 -0
- package/ios/Shared/DaroMBannerAdView.swift +188 -0
- package/ios/Shared/DaroMNativeAdLoadCoordinator.swift +49 -0
- package/ios/Shared/DaroMNativeAdView.swift +575 -0
- package/ios/Shared/DaroMNativeAssetResolver.swift +53 -0
- package/ios/mediation/admob/DaroMediationDebugger.swift +11 -0
- package/ios/mediation/admob/DaroMediationTypes.swift +23 -0
- package/lib/commonjs/AdBannerView.js +21 -35
- package/lib/commonjs/AdBannerView.js.map +1 -1
- package/lib/commonjs/AppOpenAd.js +80 -21
- package/lib/commonjs/AppOpenAd.js.map +1 -1
- package/lib/commonjs/DaroMAdBannerViewNativeComponent.ts +47 -0
- package/lib/commonjs/DaroMNativeAdViewNativeComponent.ts +62 -0
- package/lib/commonjs/DaroMediaViewNativeComponent.ts +9 -0
- package/lib/commonjs/ErrorCode.js.map +1 -1
- package/lib/commonjs/EventEmitter.js +4 -5
- package/lib/commonjs/EventEmitter.js.map +1 -1
- package/lib/commonjs/InterstitialAd.js +48 -22
- package/lib/commonjs/InterstitialAd.js.map +1 -1
- package/lib/commonjs/LightPopupAd.js +64 -46
- package/lib/commonjs/LightPopupAd.js.map +1 -1
- package/lib/commonjs/NativeDaroModule.js +9 -0
- package/lib/commonjs/NativeDaroModule.js.map +1 -0
- package/lib/commonjs/RewardedAd.js +47 -23
- package/lib/commonjs/RewardedAd.js.map +1 -1
- package/lib/commonjs/codegen-env.d.js +2 -0
- package/lib/commonjs/codegen-env.d.js.map +1 -0
- package/lib/commonjs/hooks/useInterstitialAd.js +110 -0
- package/lib/commonjs/hooks/useInterstitialAd.js.map +1 -0
- package/lib/commonjs/hooks/useLightPopupAd.js +114 -0
- package/lib/commonjs/hooks/useLightPopupAd.js.map +1 -0
- package/lib/commonjs/hooks/useRewardedAd.js +113 -0
- package/lib/commonjs/hooks/useRewardedAd.js.map +1 -0
- package/lib/commonjs/index.js +29 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdView.js +23 -18
- package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdViewComponents.js +43 -31
- package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
- package/lib/commonjs/nativeAd/NativeAdViewProvider.js +34 -7
- package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
- package/lib/commonjs/package.json +1 -0
- package/lib/module/AdBannerView.js +20 -36
- package/lib/module/AdBannerView.js.map +1 -1
- package/lib/module/AppOpenAd.js +80 -22
- package/lib/module/AppOpenAd.js.map +1 -1
- package/lib/module/DaroMAdBannerViewNativeComponent.ts +47 -0
- package/lib/module/DaroMNativeAdViewNativeComponent.ts +62 -0
- package/lib/module/DaroMediaViewNativeComponent.ts +9 -0
- package/lib/module/ErrorCode.js.map +1 -1
- package/lib/module/EventEmitter.js +4 -6
- package/lib/module/EventEmitter.js.map +1 -1
- package/lib/module/InterstitialAd.js +47 -22
- package/lib/module/InterstitialAd.js.map +1 -1
- package/lib/module/LightPopupAd.js +65 -47
- package/lib/module/LightPopupAd.js.map +1 -1
- package/lib/module/NativeDaroModule.js +5 -0
- package/lib/module/NativeDaroModule.js.map +1 -0
- package/lib/module/RewardedAd.js +46 -23
- package/lib/module/RewardedAd.js.map +1 -1
- package/lib/module/codegen-env.d.js +2 -0
- package/lib/module/codegen-env.d.js.map +1 -0
- package/lib/module/hooks/useInterstitialAd.js +106 -0
- package/lib/module/hooks/useInterstitialAd.js.map +1 -0
- package/lib/module/hooks/useLightPopupAd.js +110 -0
- package/lib/module/hooks/useLightPopupAd.js.map +1 -0
- package/lib/module/hooks/useRewardedAd.js +109 -0
- package/lib/module/hooks/useRewardedAd.js.map +1 -0
- package/lib/module/index.js +7 -13
- package/lib/module/index.js.map +1 -1
- package/lib/module/nativeAd/NativeAdView.js +22 -19
- package/lib/module/nativeAd/NativeAdView.js.map +1 -1
- package/lib/module/nativeAd/NativeAdViewComponents.js +45 -34
- package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
- package/lib/module/nativeAd/NativeAdViewProvider.js +35 -8
- package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
- package/lib/module/package.json +1 -0
- package/lib/typescript/commonjs/plugin/src/index.d.ts +19 -0
- package/lib/typescript/commonjs/plugin/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/plugin/src/skAdNetworkIds.d.ts +6 -0
- package/lib/typescript/commonjs/plugin/src/skAdNetworkIds.d.ts.map +1 -0
- package/lib/typescript/commonjs/plugin/src/withAndroid.d.ts +8 -0
- package/lib/typescript/commonjs/plugin/src/withAndroid.d.ts.map +1 -0
- package/lib/typescript/commonjs/plugin/src/withIos.d.ts +8 -0
- package/lib/typescript/commonjs/plugin/src/withIos.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/AdBannerView.d.ts +126 -4
- package/lib/typescript/commonjs/src/AdBannerView.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/AppOpenAd.d.ts +6 -0
- package/lib/typescript/commonjs/src/AppOpenAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/DaroMAdBannerViewNativeComponent.d.ts +32 -0
- package/lib/typescript/commonjs/src/DaroMAdBannerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/DaroMNativeAdViewNativeComponent.d.ts +42 -0
- package/lib/typescript/commonjs/src/DaroMNativeAdViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/DaroMediaViewNativeComponent.d.ts +6 -0
- package/lib/typescript/commonjs/src/DaroMediaViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/ErrorCode.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/EventEmitter.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/InterstitialAd.d.ts +6 -0
- package/lib/typescript/commonjs/src/InterstitialAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/LightPopupAd.d.ts +6 -0
- package/lib/typescript/commonjs/src/LightPopupAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/NativeDaroModule.d.ts +61 -0
- package/lib/typescript/commonjs/src/NativeDaroModule.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/RewardedAd.d.ts +6 -0
- package/lib/typescript/commonjs/src/RewardedAd.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/hooks/useInterstitialAd.d.ts +19 -0
- package/lib/typescript/commonjs/src/hooks/useInterstitialAd.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts +23 -0
- package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/hooks/useRewardedAd.d.ts +20 -0
- package/lib/typescript/commonjs/src/hooks/useRewardedAd.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +7 -1
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts +125 -2
- package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/nativeAd/NativeAdViewProvider.d.ts +11 -5
- package/lib/typescript/commonjs/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts +2 -2
- package/lib/typescript/commonjs/src/types/AdBannerViewProps.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdInfo.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/AdProps.d.ts +2 -2
- package/lib/typescript/commonjs/src/types/AdProps.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/DaroMMobileAds.d.ts.map +1 -1
- package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts +2 -0
- package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts.map +1 -1
- package/lib/typescript/module/plugin/src/index.d.ts +19 -0
- package/lib/typescript/module/plugin/src/index.d.ts.map +1 -0
- package/lib/typescript/module/plugin/src/skAdNetworkIds.d.ts +6 -0
- package/lib/typescript/module/plugin/src/skAdNetworkIds.d.ts.map +1 -0
- package/lib/typescript/module/plugin/src/withAndroid.d.ts +8 -0
- package/lib/typescript/module/plugin/src/withAndroid.d.ts.map +1 -0
- package/lib/typescript/module/plugin/src/withIos.d.ts +8 -0
- package/lib/typescript/module/plugin/src/withIos.d.ts.map +1 -0
- package/lib/typescript/module/src/AdBannerView.d.ts +126 -4
- package/lib/typescript/module/src/AdBannerView.d.ts.map +1 -1
- package/lib/typescript/module/src/AppOpenAd.d.ts +6 -0
- package/lib/typescript/module/src/AppOpenAd.d.ts.map +1 -1
- package/lib/typescript/module/src/DaroMAdBannerViewNativeComponent.d.ts +32 -0
- package/lib/typescript/module/src/DaroMAdBannerViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/DaroMNativeAdViewNativeComponent.d.ts +42 -0
- package/lib/typescript/module/src/DaroMNativeAdViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/DaroMediaViewNativeComponent.d.ts +6 -0
- package/lib/typescript/module/src/DaroMediaViewNativeComponent.d.ts.map +1 -0
- package/lib/typescript/module/src/ErrorCode.d.ts.map +1 -1
- package/lib/typescript/module/src/EventEmitter.d.ts.map +1 -1
- package/lib/typescript/module/src/InterstitialAd.d.ts +6 -0
- package/lib/typescript/module/src/InterstitialAd.d.ts.map +1 -1
- package/lib/typescript/module/src/LightPopupAd.d.ts +6 -0
- package/lib/typescript/module/src/LightPopupAd.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeDaroModule.d.ts +61 -0
- package/lib/typescript/module/src/NativeDaroModule.d.ts.map +1 -0
- package/lib/typescript/module/src/RewardedAd.d.ts +6 -0
- package/lib/typescript/module/src/RewardedAd.d.ts.map +1 -1
- package/lib/typescript/module/src/hooks/useInterstitialAd.d.ts +19 -0
- package/lib/typescript/module/src/hooks/useInterstitialAd.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts +23 -0
- package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts.map +1 -0
- package/lib/typescript/module/src/hooks/useRewardedAd.d.ts +20 -0
- package/lib/typescript/module/src/hooks/useRewardedAd.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +7 -1
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts +125 -2
- package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts.map +1 -1
- package/lib/typescript/module/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
- package/lib/typescript/module/src/nativeAd/NativeAdViewProvider.d.ts +11 -5
- package/lib/typescript/module/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdBannerViewProps.d.ts +2 -2
- package/lib/typescript/module/src/types/AdBannerViewProps.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdInfo.d.ts.map +1 -1
- package/lib/typescript/module/src/types/AdProps.d.ts +2 -2
- package/lib/typescript/module/src/types/AdProps.d.ts.map +1 -1
- package/lib/typescript/module/src/types/DaroMMobileAds.d.ts.map +1 -1
- package/lib/typescript/module/src/types/NativeAdViewProps.d.ts +2 -0
- package/lib/typescript/module/src/types/NativeAdViewProps.d.ts.map +1 -1
- package/package.json +95 -105
- package/plugin/build/index.d.ts +18 -0
- package/plugin/build/index.js +71 -0
- package/plugin/build/skAdNetworkIds.d.ts +5 -0
- package/plugin/build/skAdNetworkIds.js +205 -0
- package/plugin/build/withAndroid.d.ts +7 -0
- package/plugin/build/withAndroid.js +222 -0
- package/plugin/build/withIos.d.ts +7 -0
- package/plugin/build/withIos.js +82 -0
- package/react-native-daro.podspec +28 -0
- package/src/AdBannerView.tsx +48 -48
- package/src/AppOpenAd.ts +101 -20
- package/src/DaroMAdBannerViewNativeComponent.ts +47 -0
- package/src/DaroMNativeAdViewNativeComponent.ts +62 -0
- package/src/DaroMediaViewNativeComponent.ts +9 -0
- package/src/ErrorCode.ts +1 -2
- package/src/EventEmitter.ts +9 -7
- package/src/InterstitialAd.ts +75 -21
- package/src/LightPopupAd.ts +90 -51
- package/src/NativeDaroModule.ts +91 -0
- package/src/RewardedAd.ts +72 -22
- package/src/codegen-env.d.ts +45 -0
- package/src/hooks/useInterstitialAd.ts +117 -0
- package/src/hooks/useLightPopupAd.ts +132 -0
- package/src/hooks/useRewardedAd.ts +122 -0
- package/src/index.tsx +21 -22
- package/src/nativeAd/NativeAdView.tsx +83 -45
- package/src/nativeAd/NativeAdViewComponents.tsx +129 -64
- package/src/nativeAd/NativeAdViewProvider.tsx +84 -16
- package/src/types/AdBannerViewProps.ts +11 -11
- package/src/types/AdInfo.ts +17 -17
- package/src/types/AdProps.ts +8 -9
- package/src/types/DaroMMobileAds.ts +3 -6
- package/src/types/NativeAdViewProps.ts +12 -5
- package/src/types/index.ts +1 -1
- package/android/gradle.properties +0 -5
- package/android/src/main/AndroidManifestNew.xml +0 -7
- package/android/src/main/java/com/darom/DaroMAdNativeViewManager.kt +0 -136
- package/android/src/main/java/com/darom/DaroMModule.kt +0 -203
- package/android/src/main/java/com/darom/DaroMPackage.kt +0 -21
- package/android/src/main/java/com/darom/util/EventEmitterUtil.kt +0 -24
- package/android/src/main/java/com/darom/view/DaroMAdBannerViewContainer.kt +0 -163
- package/android/src/main/java/com/darom/view/DaroMAdNativeViewContainer.kt +0 -375
- package/android/src/main/res/layout/layout_activity_transparent.xml +0 -7
- package/android/src/main/res/values/styles.xml +0 -11
- package/ios/DaroM-Bridging-Header.h +0 -6
- package/ios/DaroMAdBannerViewManager.swift +0 -91
- package/ios/DaroMNativeAdViewManager.swift +0 -291
- package/react-native-daro-m.podspec +0 -44
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
#import <React/RCTDefines.h>
|
|
2
|
+
|
|
3
|
+
#ifdef RCT_NEW_ARCH_ENABLED
|
|
4
|
+
|
|
5
|
+
#import <React/RCTComponent.h>
|
|
6
|
+
#import <React/RCTFabricComponentsPlugins.h>
|
|
7
|
+
#import <React/RCTViewComponentView.h>
|
|
8
|
+
#import <react/renderer/components/DaroReactNativeSpec/ComponentDescriptors.h>
|
|
9
|
+
#import <react/renderer/components/DaroReactNativeSpec/EventEmitters.h>
|
|
10
|
+
#import <react/renderer/components/DaroReactNativeSpec/Props.h>
|
|
11
|
+
#import <react/renderer/components/DaroReactNativeSpec/RCTComponentViewHelpers.h>
|
|
12
|
+
#include <folly/dynamic.h>
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
using namespace facebook::react;
|
|
16
|
+
|
|
17
|
+
extern UIView *DaroMFabricCreateSwiftView(NSString *className);
|
|
18
|
+
extern void DaroMFabricSetValue(UIView *view, NSString *key, id value);
|
|
19
|
+
extern void DaroMFabricPerformSelector(UIView *view, SEL selector);
|
|
20
|
+
extern void DaroMFabricPerformSelectorWithObject(UIView *view, SEL selector, id object);
|
|
21
|
+
extern void DaroMFabricPerformSelectorWithTwoObjects(UIView *view, SEL selector, id firstObject, id secondObject);
|
|
22
|
+
extern NSString *DaroMFabricNSStringFromStdString(const std::string &value);
|
|
23
|
+
extern id DaroMFabricIdFromDynamic(const folly::dynamic &value);
|
|
24
|
+
extern NSDictionary *DaroMFabricEventBody(NSDictionary *body);
|
|
25
|
+
extern std::string DaroMFabricEventString(NSDictionary *body, NSString *key);
|
|
26
|
+
extern double DaroMFabricEventDouble(NSDictionary *body, NSString *key);
|
|
27
|
+
extern int DaroMFabricEventInt(NSDictionary *body, NSString *key);
|
|
28
|
+
|
|
29
|
+
static NSString *DaroMFabricAdChoicesPositionString(DaroMNativeAdViewAdChoicesPosition position)
|
|
30
|
+
{
|
|
31
|
+
switch (position) {
|
|
32
|
+
case DaroMNativeAdViewAdChoicesPosition::TopLeft:
|
|
33
|
+
return @"topLeft";
|
|
34
|
+
case DaroMNativeAdViewAdChoicesPosition::TopRight:
|
|
35
|
+
return @"topRight";
|
|
36
|
+
case DaroMNativeAdViewAdChoicesPosition::BottomLeft:
|
|
37
|
+
return @"bottomLeft";
|
|
38
|
+
case DaroMNativeAdViewAdChoicesPosition::BottomRight:
|
|
39
|
+
default:
|
|
40
|
+
return @"bottomRight";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@interface DaroMNativeAdViewComponentView : RCTViewComponentView <RCTDaroMNativeAdViewViewProtocol>
|
|
45
|
+
@end
|
|
46
|
+
|
|
47
|
+
@implementation DaroMNativeAdViewComponentView {
|
|
48
|
+
UIView *_nativeAdView;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
+ (void)load
|
|
52
|
+
{
|
|
53
|
+
[super load];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
- (instancetype)initWithFrame:(CGRect)frame
|
|
57
|
+
{
|
|
58
|
+
if (self = [super initWithFrame:frame]) {
|
|
59
|
+
static const auto defaultProps = std::make_shared<const DaroMNativeAdViewProps>();
|
|
60
|
+
_props = defaultProps;
|
|
61
|
+
[self createNativeAdView];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return self;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (void)createNativeAdView
|
|
68
|
+
{
|
|
69
|
+
_nativeAdView = DaroMFabricCreateSwiftView(@"RNDaroMNativeAdView");
|
|
70
|
+
_nativeAdView.frame = self.bounds;
|
|
71
|
+
_nativeAdView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
72
|
+
DaroMFabricPerformSelectorWithObject(_nativeAdView, NSSelectorFromString(@"setAssetSearchRootView:"), _nativeAdView);
|
|
73
|
+
[self addSubview:_nativeAdView];
|
|
74
|
+
[self installEventHandlers];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
- (void)installEventHandlers
|
|
78
|
+
{
|
|
79
|
+
__weak DaroMNativeAdViewComponentView *weakSelf = self;
|
|
80
|
+
|
|
81
|
+
RCTDirectEventBlock onAdLoadedEvent = ^(NSDictionary *body) {
|
|
82
|
+
DaroMNativeAdViewComponentView *strongSelf = weakSelf;
|
|
83
|
+
if (!strongSelf) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
auto eventEmitter = std::static_pointer_cast<const DaroMNativeAdViewEventEmitter>(strongSelf->_eventEmitter);
|
|
88
|
+
if (!eventEmitter) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
NSDictionary *eventBody = DaroMFabricEventBody(body);
|
|
93
|
+
eventEmitter->onAdLoadedEvent({
|
|
94
|
+
.adUnitId = DaroMFabricEventString(eventBody, @"adUnitId"),
|
|
95
|
+
.latencyMillis = DaroMFabricEventDouble(eventBody, @"latencyMillis"),
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
RCTDirectEventBlock onAdLoadFailedEvent = ^(NSDictionary *body) {
|
|
100
|
+
DaroMNativeAdViewComponentView *strongSelf = weakSelf;
|
|
101
|
+
if (!strongSelf) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
auto eventEmitter = std::static_pointer_cast<const DaroMNativeAdViewEventEmitter>(strongSelf->_eventEmitter);
|
|
106
|
+
if (!eventEmitter) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
NSDictionary *eventBody = DaroMFabricEventBody(body);
|
|
111
|
+
eventEmitter->onAdLoadFailedEvent({
|
|
112
|
+
.adUnitId = DaroMFabricEventString(eventBody, @"adUnitId"),
|
|
113
|
+
.code = DaroMFabricEventInt(eventBody, @"code"),
|
|
114
|
+
.message = DaroMFabricEventString(eventBody, @"message"),
|
|
115
|
+
.latencyMillis = DaroMFabricEventDouble(eventBody, @"latencyMillis"),
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
RCTDirectEventBlock onAdClickedEvent = ^(NSDictionary *body) {
|
|
120
|
+
DaroMNativeAdViewComponentView *strongSelf = weakSelf;
|
|
121
|
+
if (!strongSelf) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
auto eventEmitter = std::static_pointer_cast<const DaroMNativeAdViewEventEmitter>(strongSelf->_eventEmitter);
|
|
126
|
+
if (!eventEmitter) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
NSDictionary *eventBody = DaroMFabricEventBody(body);
|
|
131
|
+
eventEmitter->onAdClickedEvent({
|
|
132
|
+
.adUnitId = DaroMFabricEventString(eventBody, @"adUnitId"),
|
|
133
|
+
.latencyMillis = DaroMFabricEventDouble(eventBody, @"latencyMillis"),
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
RCTDirectEventBlock onAdImpressionRecordedEvent = ^(NSDictionary *body) {
|
|
138
|
+
DaroMNativeAdViewComponentView *strongSelf = weakSelf;
|
|
139
|
+
if (!strongSelf) {
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
auto eventEmitter = std::static_pointer_cast<const DaroMNativeAdViewEventEmitter>(strongSelf->_eventEmitter);
|
|
144
|
+
if (!eventEmitter) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
NSDictionary *eventBody = DaroMFabricEventBody(body);
|
|
149
|
+
eventEmitter->onAdImpressionRecordedEvent({
|
|
150
|
+
.adUnitId = DaroMFabricEventString(eventBody, @"adUnitId"),
|
|
151
|
+
.latencyMillis = DaroMFabricEventDouble(eventBody, @"latencyMillis"),
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
DaroMFabricSetValue(_nativeAdView, @"onAdLoadedEvent", onAdLoadedEvent);
|
|
156
|
+
DaroMFabricSetValue(_nativeAdView, @"onAdLoadFailedEvent", onAdLoadFailedEvent);
|
|
157
|
+
DaroMFabricSetValue(_nativeAdView, @"onAdClickedEvent", onAdClickedEvent);
|
|
158
|
+
DaroMFabricSetValue(_nativeAdView, @"onAdImpressionRecordedEvent", onAdImpressionRecordedEvent);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider
|
|
162
|
+
{
|
|
163
|
+
return concreteComponentDescriptorProvider<DaroMNativeAdViewComponentDescriptor>();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
- (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &)oldProps
|
|
167
|
+
{
|
|
168
|
+
const auto &oldComponentProps = *std::static_pointer_cast<const DaroMNativeAdViewProps>(_props);
|
|
169
|
+
const auto &newComponentProps = *std::static_pointer_cast<const DaroMNativeAdViewProps>(props);
|
|
170
|
+
NSMutableArray<NSString *> *changedProps = [NSMutableArray new];
|
|
171
|
+
|
|
172
|
+
if (oldComponentProps.adUnitId != newComponentProps.adUnitId) {
|
|
173
|
+
DaroMFabricSetValue(_nativeAdView, @"adUnitId", DaroMFabricNSStringFromStdString(newComponentProps.adUnitId));
|
|
174
|
+
[changedProps addObject:@"adUnitId"];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
if (oldComponentProps.loadOnMount != newComponentProps.loadOnMount) {
|
|
178
|
+
DaroMFabricSetValue(_nativeAdView, @"loadOnMount", @(newComponentProps.loadOnMount));
|
|
179
|
+
[changedProps addObject:@"loadOnMount"];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (oldComponentProps.adChoicesPosition != newComponentProps.adChoicesPosition) {
|
|
183
|
+
DaroMFabricSetValue(
|
|
184
|
+
_nativeAdView, @"adChoicesPosition", DaroMFabricAdChoicesPositionString(newComponentProps.adChoicesPosition));
|
|
185
|
+
[changedProps addObject:@"adChoicesPosition"];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (oldComponentProps.titleView != newComponentProps.titleView) {
|
|
189
|
+
DaroMFabricSetValue(_nativeAdView, @"titleView", @(newComponentProps.titleView));
|
|
190
|
+
[changedProps addObject:@"titleView"];
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (oldComponentProps.bodyView != newComponentProps.bodyView) {
|
|
194
|
+
DaroMFabricSetValue(_nativeAdView, @"bodyView", @(newComponentProps.bodyView));
|
|
195
|
+
[changedProps addObject:@"bodyView"];
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (oldComponentProps.callToActionView != newComponentProps.callToActionView) {
|
|
199
|
+
DaroMFabricSetValue(_nativeAdView, @"callToActionView", @(newComponentProps.callToActionView));
|
|
200
|
+
[changedProps addObject:@"callToActionView"];
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (oldComponentProps.iconView != newComponentProps.iconView) {
|
|
204
|
+
DaroMFabricSetValue(_nativeAdView, @"iconView", @(newComponentProps.iconView));
|
|
205
|
+
[changedProps addObject:@"iconView"];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (oldComponentProps.mediaView != newComponentProps.mediaView) {
|
|
209
|
+
DaroMFabricSetValue(_nativeAdView, @"mediaView", @(newComponentProps.mediaView));
|
|
210
|
+
[changedProps addObject:@"mediaView"];
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
if (oldComponentProps.titleViewStyleProps != newComponentProps.titleViewStyleProps) {
|
|
214
|
+
DaroMFabricSetValue(_nativeAdView, @"titleViewStyleProps", DaroMFabricIdFromDynamic(newComponentProps.titleViewStyleProps));
|
|
215
|
+
[changedProps addObject:@"titleViewStyleProps"];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
if (oldComponentProps.bodyViewStyleProps != newComponentProps.bodyViewStyleProps) {
|
|
219
|
+
DaroMFabricSetValue(_nativeAdView, @"bodyViewStyleProps", DaroMFabricIdFromDynamic(newComponentProps.bodyViewStyleProps));
|
|
220
|
+
[changedProps addObject:@"bodyViewStyleProps"];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (oldComponentProps.callToActionViewStyleProps != newComponentProps.callToActionViewStyleProps) {
|
|
224
|
+
DaroMFabricSetValue(
|
|
225
|
+
_nativeAdView, @"callToActionViewStyleProps", DaroMFabricIdFromDynamic(newComponentProps.callToActionViewStyleProps));
|
|
226
|
+
[changedProps addObject:@"callToActionViewStyleProps"];
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (oldComponentProps.iconViewStyleProps != newComponentProps.iconViewStyleProps) {
|
|
230
|
+
DaroMFabricSetValue(_nativeAdView, @"iconViewStyleProps", DaroMFabricIdFromDynamic(newComponentProps.iconViewStyleProps));
|
|
231
|
+
[changedProps addObject:@"iconViewStyleProps"];
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if (oldComponentProps.mediaViewStyleProps != newComponentProps.mediaViewStyleProps) {
|
|
235
|
+
DaroMFabricSetValue(_nativeAdView, @"mediaViewStyleProps", DaroMFabricIdFromDynamic(newComponentProps.mediaViewStyleProps));
|
|
236
|
+
[changedProps addObject:@"mediaViewStyleProps"];
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
[super updateProps:props oldProps:oldProps];
|
|
240
|
+
|
|
241
|
+
DaroMFabricPerformSelectorWithObject(_nativeAdView, NSSelectorFromString(@"applyReactProps:"), changedProps);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
- (void)updateLayoutMetrics:(const LayoutMetrics &)layoutMetrics oldLayoutMetrics:(const LayoutMetrics &)oldLayoutMetrics
|
|
245
|
+
{
|
|
246
|
+
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
|
|
247
|
+
_nativeAdView.frame = self.bounds;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
|
251
|
+
{
|
|
252
|
+
DaroMFabricPerformSelectorWithTwoObjects(
|
|
253
|
+
_nativeAdView, NSSelectorFromString(@"insertMountedSubview:atIndex:"), childComponentView, @(index));
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
|
|
257
|
+
{
|
|
258
|
+
[childComponentView removeFromSuperview];
|
|
259
|
+
DaroMFabricPerformSelector(_nativeAdView, NSSelectorFromString(@"refreshMountedAssetViews"));
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
- (void)loadAd
|
|
263
|
+
{
|
|
264
|
+
DaroMFabricPerformSelector(_nativeAdView, NSSelectorFromString(@"loadAd"));
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
- (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
|
|
268
|
+
{
|
|
269
|
+
RCTDaroMNativeAdViewHandleCommand(self, commandName, args);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
- (void)prepareForRecycle
|
|
273
|
+
{
|
|
274
|
+
[super prepareForRecycle];
|
|
275
|
+
DaroMFabricSetValue(_nativeAdView, @"onAdLoadedEvent", nil);
|
|
276
|
+
DaroMFabricSetValue(_nativeAdView, @"onAdLoadFailedEvent", nil);
|
|
277
|
+
DaroMFabricSetValue(_nativeAdView, @"onAdClickedEvent", nil);
|
|
278
|
+
DaroMFabricSetValue(_nativeAdView, @"onAdImpressionRecordedEvent", nil);
|
|
279
|
+
DaroMFabricPerformSelectorWithObject(_nativeAdView, NSSelectorFromString(@"setAssetSearchRootView:"), nil);
|
|
280
|
+
DaroMFabricPerformSelector(_nativeAdView, NSSelectorFromString(@"prepareForReuse"));
|
|
281
|
+
DaroMFabricPerformSelectorWithObject(_nativeAdView, NSSelectorFromString(@"setAssetSearchRootView:"), _nativeAdView);
|
|
282
|
+
[self installEventHandlers];
|
|
283
|
+
static const auto defaultProps = std::make_shared<const DaroMNativeAdViewProps>();
|
|
284
|
+
_props = defaultProps;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@end
|
|
288
|
+
|
|
289
|
+
Class<RCTComponentViewProtocol> DaroMNativeAdViewCls(void)
|
|
290
|
+
{
|
|
291
|
+
return DaroMNativeAdViewComponentView.class;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
#endif
|
|
@@ -4,12 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
RCT_EXPORT_VIEW_PROPERTY(adUnitId, NSString)
|
|
6
6
|
RCT_EXPORT_VIEW_PROPERTY(adFormat, NSString)
|
|
7
|
+
RCT_EXPORT_VIEW_PROPERTY(loadOnMount, BOOL)
|
|
8
|
+
RCT_EXPORT_VIEW_PROPERTY(isVisible, BOOL)
|
|
7
9
|
|
|
8
10
|
RCT_EXPORT_VIEW_PROPERTY(onAdLoadedEvent, RCTDirectEventBlock)
|
|
9
11
|
RCT_EXPORT_VIEW_PROPERTY(onAdLoadFailedEvent, RCTDirectEventBlock)
|
|
10
12
|
RCT_EXPORT_VIEW_PROPERTY(onAdClickedEvent, RCTDirectEventBlock)
|
|
11
13
|
RCT_EXPORT_VIEW_PROPERTY(onAdImpressionRecordedEvent, RCTDirectEventBlock)
|
|
12
14
|
|
|
13
|
-
RCT_EXTERN_METHOD(loadAd)
|
|
15
|
+
RCT_EXTERN_METHOD(loadAd : (nonnull NSNumber *)viewTag)
|
|
14
16
|
|
|
15
17
|
@end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React
|
|
2
|
+
|
|
3
|
+
@objc(DaroMAdBannerViewManager)
|
|
4
|
+
class DaroMAdBannerViewManager: RCTViewManager {
|
|
5
|
+
override func view() -> DaroMAdBannerView {
|
|
6
|
+
DaroMAdBannerView()
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
10
|
+
false
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@objc(loadAd:)
|
|
14
|
+
func loadAd(viewTag: NSNumber) {
|
|
15
|
+
bridge?.uiManager.addUIBlock({ _, viewRegistry in
|
|
16
|
+
if let view = viewRegistry?[viewTag] as? DaroMAdBannerView {
|
|
17
|
+
view.loadAd()
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -3,12 +3,13 @@
|
|
|
3
3
|
@interface RCT_EXTERN_MODULE (DaroMNativeAdViewManager, RCTViewManager)
|
|
4
4
|
|
|
5
5
|
RCT_EXPORT_VIEW_PROPERTY(adUnitId, NSString)
|
|
6
|
+
RCT_EXPORT_VIEW_PROPERTY(loadOnMount, BOOL)
|
|
7
|
+
RCT_EXPORT_VIEW_PROPERTY(adChoicesPosition, NSString)
|
|
6
8
|
|
|
7
9
|
RCT_EXPORT_VIEW_PROPERTY(titleView, NSNumber)
|
|
8
10
|
RCT_EXPORT_VIEW_PROPERTY(bodyView, NSNumber)
|
|
9
11
|
RCT_EXPORT_VIEW_PROPERTY(callToActionView, NSNumber)
|
|
10
12
|
RCT_EXPORT_VIEW_PROPERTY(iconView, NSNumber)
|
|
11
|
-
RCT_EXPORT_VIEW_PROPERTY(optionsView, NSNumber)
|
|
12
13
|
RCT_EXPORT_VIEW_PROPERTY(mediaView, NSNumber)
|
|
13
14
|
|
|
14
15
|
RCT_EXPORT_VIEW_PROPERTY(titleViewStyleProps, NSDictionary)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
@objc(DaroMNativeAdViewManager)
|
|
5
|
+
class DaroMNativeAdViewManager: RCTViewManager {
|
|
6
|
+
override func view() -> RNDaroMNativeAdView {
|
|
7
|
+
RNDaroMNativeAdView(assetResolver: DaroMBridgeNativeAssetResolver(bridge: bridge))
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@objc override static func requiresMainQueueSetup() -> Bool {
|
|
11
|
+
false
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@objc(loadAd:)
|
|
15
|
+
func loadAd(viewTag: NSNumber) {
|
|
16
|
+
bridge?.uiManager.addUIBlock({ _, viewRegistry in
|
|
17
|
+
if let view = viewRegistry?[viewTag] as? RNDaroMNativeAdView {
|
|
18
|
+
view.loadAd()
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import React
|
|
2
|
+
|
|
3
|
+
final class DaroMAdEventSink {
|
|
4
|
+
var onAdLoadedEvent: RCTDirectEventBlock?
|
|
5
|
+
var onAdLoadFailedEvent: RCTDirectEventBlock?
|
|
6
|
+
var onAdClickedEvent: RCTDirectEventBlock?
|
|
7
|
+
var onAdImpressionRecordedEvent: RCTDirectEventBlock?
|
|
8
|
+
|
|
9
|
+
func emitAdLoaded(_ body: [AnyHashable: Any]?) {
|
|
10
|
+
onAdLoadedEvent?(body)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
func emitAdLoadFailed(_ body: [AnyHashable: Any]?) {
|
|
14
|
+
onAdLoadFailedEvent?(body)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
func emitAdClicked(_ body: [AnyHashable: Any]?) {
|
|
18
|
+
onAdClickedEvent?(body)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func emitAdImpressionRecorded(_ body: [AnyHashable: Any]?) {
|
|
22
|
+
onAdImpressionRecordedEvent?(body)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
import React
|
|
2
|
+
import UIKit
|
|
3
|
+
|
|
4
|
+
private enum DaroMBannerLoadRequest: Equatable {
|
|
5
|
+
case automatic
|
|
6
|
+
case explicit
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
@objc(DaroMAdBannerView)
|
|
10
|
+
final class DaroMAdBannerView: UIView {
|
|
11
|
+
|
|
12
|
+
var adBannerView: DaroAdBannerView?
|
|
13
|
+
private let eventSink = DaroMAdEventSink()
|
|
14
|
+
private var hasRequestedInitialLoad = false
|
|
15
|
+
private var pendingLoadRequest: DaroMBannerLoadRequest?
|
|
16
|
+
|
|
17
|
+
@objc var adUnitId: String?
|
|
18
|
+
@objc var adFormat: String = DaroMModule.Constants.bannerAdFormatLabel.value
|
|
19
|
+
@objc var loadOnMount: Bool = true
|
|
20
|
+
@objc var isVisible: Bool = true {
|
|
21
|
+
didSet {
|
|
22
|
+
setAdVisibility(isVisible)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@objc var onAdLoadedEvent: RCTDirectEventBlock? {
|
|
27
|
+
get { eventSink.onAdLoadedEvent }
|
|
28
|
+
set { eventSink.onAdLoadedEvent = newValue }
|
|
29
|
+
}
|
|
30
|
+
@objc var onAdLoadFailedEvent: RCTDirectEventBlock? {
|
|
31
|
+
get { eventSink.onAdLoadFailedEvent }
|
|
32
|
+
set { eventSink.onAdLoadFailedEvent = newValue }
|
|
33
|
+
}
|
|
34
|
+
@objc var onAdClickedEvent: RCTDirectEventBlock? {
|
|
35
|
+
get { eventSink.onAdClickedEvent }
|
|
36
|
+
set { eventSink.onAdClickedEvent = newValue }
|
|
37
|
+
}
|
|
38
|
+
@objc var onAdImpressionRecordedEvent: RCTDirectEventBlock? {
|
|
39
|
+
get { eventSink.onAdImpressionRecordedEvent }
|
|
40
|
+
set { eventSink.onAdImpressionRecordedEvent = newValue }
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
init() {
|
|
44
|
+
super.init(frame: CGRect.zero)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
required init?(coder: NSCoder) {
|
|
48
|
+
fatalError("init(coder:) has not been implemented")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
override func didSetProps(_ changedProps: [String]!) {
|
|
52
|
+
applyReactProps(changedProps)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@objc(applyReactProps:)
|
|
56
|
+
func applyReactProps(_ changedProps: [String]!) {
|
|
57
|
+
guard let changedProps, changedProps.isEmpty == false else { return }
|
|
58
|
+
guard let adUnitId, adUnitId.isEmpty == false else {
|
|
59
|
+
if changedProps.contains("adUnitId") {
|
|
60
|
+
DaroMModule.logger.warning("AdUnitId is required")
|
|
61
|
+
}
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
cancelAutomaticLoadIfNeeded(changedProps)
|
|
65
|
+
initialize()
|
|
66
|
+
requestInitialLoadIfNeeded()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@objc
|
|
70
|
+
func loadAd() {
|
|
71
|
+
requestLoad(.explicit)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
@objc(prepareForReuse)
|
|
75
|
+
func prepareForReuse() {
|
|
76
|
+
resetAdState()
|
|
77
|
+
adUnitId = nil
|
|
78
|
+
adFormat = DaroMModule.Constants.bannerAdFormatLabel.value
|
|
79
|
+
loadOnMount = true
|
|
80
|
+
isVisible = true
|
|
81
|
+
isHidden = false
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
private func requestLoad(_ request: DaroMBannerLoadRequest) {
|
|
85
|
+
initialize()
|
|
86
|
+
|
|
87
|
+
guard let adBannerView else { return }
|
|
88
|
+
guard isVisible else {
|
|
89
|
+
pendingLoadRequest = request
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
pendingLoadRequest = nil
|
|
94
|
+
hasRequestedInitialLoad = true
|
|
95
|
+
adBannerView.loadAd()
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
@objc(initialize)
|
|
99
|
+
func initialize() {
|
|
100
|
+
guard adBannerView == nil else {
|
|
101
|
+
return
|
|
102
|
+
}
|
|
103
|
+
guard let adUnitId, adUnitId.isEmpty == false else {
|
|
104
|
+
DaroMModule.logger.warning("AdUnitId is required")
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
let bannerSize = adFormat == DaroMModule.Constants.bannerAdFormatLabel.value ? DaroAdBannerSize.banner : DaroAdBannerSize.MREC
|
|
109
|
+
let adUnit = DaroAdUnit(unitId: adUnitId)
|
|
110
|
+
let adBannerView = DaroAdBannerView(unit: adUnit, bannerSize: bannerSize, autoLoad: false)
|
|
111
|
+
setupBannerListener(for: adBannerView)
|
|
112
|
+
|
|
113
|
+
adBannerView.isHidden = !isVisible
|
|
114
|
+
adBannerView.translatesAutoresizingMaskIntoConstraints = false
|
|
115
|
+
addSubview(adBannerView)
|
|
116
|
+
self.adBannerView = adBannerView
|
|
117
|
+
|
|
118
|
+
NSLayoutConstraint.activate([
|
|
119
|
+
adBannerView.widthAnchor.constraint(equalToConstant: bannerSize.width),
|
|
120
|
+
adBannerView.heightAnchor.constraint(equalToConstant: bannerSize.height),
|
|
121
|
+
adBannerView.centerXAnchor.constraint(equalTo: self.centerXAnchor),
|
|
122
|
+
adBannerView.centerYAnchor.constraint(equalTo: self.centerYAnchor),
|
|
123
|
+
])
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
private func requestInitialLoadIfNeeded() {
|
|
127
|
+
guard loadOnMount, !hasRequestedInitialLoad, pendingLoadRequest == nil else { return }
|
|
128
|
+
requestLoad(.automatic)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private func loadPendingAdIfReady() {
|
|
132
|
+
guard let pendingLoadRequest, isVisible else { return }
|
|
133
|
+
guard pendingLoadRequest != .automatic || loadOnMount else {
|
|
134
|
+
self.pendingLoadRequest = nil
|
|
135
|
+
return
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
requestLoad(pendingLoadRequest)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
private func cancelAutomaticLoadIfNeeded(_ changedProps: [String]) {
|
|
142
|
+
guard changedProps.contains("loadOnMount"),
|
|
143
|
+
!loadOnMount,
|
|
144
|
+
pendingLoadRequest == .automatic else {
|
|
145
|
+
return
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
pendingLoadRequest = nil
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
private func setAdVisibility(_ visible: Bool) {
|
|
152
|
+
isHidden = !visible
|
|
153
|
+
adBannerView?.isHidden = !visible
|
|
154
|
+
|
|
155
|
+
if visible {
|
|
156
|
+
loadPendingAdIfReady()
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private func setupBannerListener(for bannerView: DaroAdBannerView) {
|
|
161
|
+
bannerView.listener.onAdLoadSuccess = { [weak self] _, adInfo in
|
|
162
|
+
self?.eventSink.emitAdLoaded(adInfo?.toBody)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
bannerView.listener.onAdLoadFail = { [weak self] error in
|
|
166
|
+
self?.eventSink.emitAdLoadFailed(error.toBody)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
bannerView.listener.onAdImpression = { [weak self] adInfo in
|
|
170
|
+
self?.eventSink.emitAdImpressionRecorded(adInfo?.toBody)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
bannerView.listener.onAdClicked = { [weak self] adInfo in
|
|
174
|
+
self?.eventSink.emitAdClicked(adInfo?.toBody)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
private func resetAdState() {
|
|
179
|
+
pendingLoadRequest = nil
|
|
180
|
+
hasRequestedInitialLoad = false
|
|
181
|
+
adBannerView?.listener.onAdLoadSuccess = nil
|
|
182
|
+
adBannerView?.listener.onAdLoadFail = nil
|
|
183
|
+
adBannerView?.listener.onAdImpression = nil
|
|
184
|
+
adBannerView?.listener.onAdClicked = nil
|
|
185
|
+
adBannerView?.removeFromSuperview()
|
|
186
|
+
adBannerView = nil
|
|
187
|
+
}
|
|
188
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
|
|
3
|
+
enum DaroMNativeAdLoadRequest: Equatable {
|
|
4
|
+
case automatic
|
|
5
|
+
case explicit
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
final class DaroMNativeAdLoadCoordinator {
|
|
9
|
+
private var pendingRequest: DaroMNativeAdLoadRequest?
|
|
10
|
+
private var hasConsumedInitialLoad = false
|
|
11
|
+
|
|
12
|
+
var hasPendingLoad: Bool {
|
|
13
|
+
pendingRequest != nil
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
func requestAutomaticLoad(loadOnMount: Bool) {
|
|
17
|
+
guard loadOnMount, !hasConsumedInitialLoad, pendingRequest == nil else { return }
|
|
18
|
+
pendingRequest = .automatic
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
func requestExplicitLoad() {
|
|
22
|
+
pendingRequest = .explicit
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
func cancelAutomaticLoadIfNeeded(loadOnMount: Bool) {
|
|
26
|
+
guard !loadOnMount, pendingRequest == .automatic else { return }
|
|
27
|
+
pendingRequest = nil
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func consumePendingLoad(loadOnMount: Bool) -> DaroMNativeAdLoadRequest? {
|
|
31
|
+
guard let pendingRequest else { return nil }
|
|
32
|
+
|
|
33
|
+
if pendingRequest == .automatic {
|
|
34
|
+
guard loadOnMount, !hasConsumedInitialLoad else {
|
|
35
|
+
self.pendingRequest = nil
|
|
36
|
+
return nil
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
self.pendingRequest = nil
|
|
41
|
+
hasConsumedInitialLoad = true
|
|
42
|
+
return pendingRequest
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
func reset() {
|
|
46
|
+
pendingRequest = nil
|
|
47
|
+
hasConsumedInitialLoad = false
|
|
48
|
+
}
|
|
49
|
+
}
|