react-native-daro 1.0.15 → 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.
Files changed (192) hide show
  1. package/android/build.gradle +11 -1
  2. package/android/src/main/java/com/daro/reactnative/DaroMAdBannerViewManager.kt +34 -11
  3. package/android/src/main/java/com/daro/reactnative/DaroMAdNativeViewManager.kt +79 -48
  4. package/android/src/main/java/com/daro/reactnative/DaroMModule.kt +80 -25
  5. package/android/src/main/java/com/daro/reactnative/DaroMPackage.kt +28 -4
  6. package/android/src/main/java/com/daro/reactnative/DaroMediaViewManager.kt +25 -0
  7. package/android/src/main/java/com/daro/reactnative/event/DaroMEvent.kt +18 -7
  8. package/android/src/main/java/com/daro/reactnative/util/EventEmitterUtil.kt +18 -5
  9. package/android/src/main/java/com/daro/reactnative/view/DaroMAdNativeViewContainer.kt +301 -52
  10. package/android/src/main/java/com/daro/reactnative/view/DaroMediaView.kt +123 -0
  11. package/android/src/newarch/java/com/daro/reactnative/DaroMModuleSpec.kt +6 -0
  12. package/android/src/oldarch/java/com/daro/reactnative/DaroMModuleSpec.kt +90 -0
  13. package/ios/DaroMModule+AppOpen.swift +13 -10
  14. package/ios/DaroMModule+Interstitial.swift +12 -9
  15. package/ios/DaroMModule+LightPopup.swift +16 -13
  16. package/ios/DaroMModule+Rewarded.swift +12 -9
  17. package/ios/DaroMModule.mm +45 -17
  18. package/ios/DaroMModule.swift +4 -4
  19. package/ios/Fabric/DaroMAdBannerComponentView.mm +207 -0
  20. package/ios/Fabric/DaroMFabricEventSink.mm +31 -0
  21. package/ios/Fabric/DaroMFabricPropApplier.mm +123 -0
  22. package/ios/Fabric/DaroMNativeAdComponentView.mm +294 -0
  23. package/ios/{DaroMAdBannerViewManager.m → Paper/DaroMAdBannerViewManager.m} +3 -1
  24. package/ios/Paper/DaroMAdBannerViewManager.swift +21 -0
  25. package/ios/{DaroMNativeAdViewManager.m → Paper/DaroMNativeAdViewManager.m} +2 -1
  26. package/ios/Paper/DaroMNativeAdViewManager.swift +22 -0
  27. package/ios/Shared/DaroMAdEventSink.swift +24 -0
  28. package/ios/Shared/DaroMBannerAdView.swift +188 -0
  29. package/ios/Shared/DaroMNativeAdLoadCoordinator.swift +49 -0
  30. package/ios/Shared/DaroMNativeAdView.swift +575 -0
  31. package/ios/Shared/DaroMNativeAssetResolver.swift +53 -0
  32. package/ios/mediation/admob/DaroMediationTypes.swift +1 -0
  33. package/lib/commonjs/AdBannerView.js +20 -39
  34. package/lib/commonjs/AdBannerView.js.map +1 -1
  35. package/lib/commonjs/AppOpenAd.js +43 -10
  36. package/lib/commonjs/AppOpenAd.js.map +1 -1
  37. package/lib/commonjs/DaroMAdBannerViewNativeComponent.ts +47 -0
  38. package/lib/commonjs/DaroMNativeAdViewNativeComponent.ts +62 -0
  39. package/lib/commonjs/DaroMediaViewNativeComponent.ts +9 -0
  40. package/lib/commonjs/EventEmitter.js +4 -5
  41. package/lib/commonjs/EventEmitter.js.map +1 -1
  42. package/lib/commonjs/InterstitialAd.js +9 -11
  43. package/lib/commonjs/InterstitialAd.js.map +1 -1
  44. package/lib/commonjs/LightPopupAd.js +11 -12
  45. package/lib/commonjs/LightPopupAd.js.map +1 -1
  46. package/lib/commonjs/NativeDaroModule.js +9 -0
  47. package/lib/commonjs/NativeDaroModule.js.map +1 -0
  48. package/lib/commonjs/RewardedAd.js +9 -11
  49. package/lib/commonjs/RewardedAd.js.map +1 -1
  50. package/lib/commonjs/codegen-env.d.js +2 -0
  51. package/lib/commonjs/codegen-env.d.js.map +1 -0
  52. package/lib/commonjs/hooks/useInterstitialAd.js +110 -0
  53. package/lib/commonjs/hooks/useInterstitialAd.js.map +1 -0
  54. package/lib/commonjs/hooks/useLightPopupAd.js +114 -0
  55. package/lib/commonjs/hooks/useLightPopupAd.js.map +1 -0
  56. package/lib/commonjs/hooks/useRewardedAd.js +113 -0
  57. package/lib/commonjs/hooks/useRewardedAd.js.map +1 -0
  58. package/lib/commonjs/index.js +29 -13
  59. package/lib/commonjs/index.js.map +1 -1
  60. package/lib/commonjs/nativeAd/NativeAdView.js +23 -22
  61. package/lib/commonjs/nativeAd/NativeAdView.js.map +1 -1
  62. package/lib/commonjs/nativeAd/NativeAdViewComponents.js +43 -31
  63. package/lib/commonjs/nativeAd/NativeAdViewComponents.js.map +1 -1
  64. package/lib/commonjs/nativeAd/NativeAdViewProvider.js +34 -7
  65. package/lib/commonjs/nativeAd/NativeAdViewProvider.js.map +1 -1
  66. package/lib/module/AdBannerView.js +19 -40
  67. package/lib/module/AdBannerView.js.map +1 -1
  68. package/lib/module/AppOpenAd.js +43 -11
  69. package/lib/module/AppOpenAd.js.map +1 -1
  70. package/lib/module/DaroMAdBannerViewNativeComponent.ts +47 -0
  71. package/lib/module/DaroMNativeAdViewNativeComponent.ts +62 -0
  72. package/lib/module/DaroMediaViewNativeComponent.ts +9 -0
  73. package/lib/module/EventEmitter.js +4 -6
  74. package/lib/module/EventEmitter.js.map +1 -1
  75. package/lib/module/InterstitialAd.js +8 -11
  76. package/lib/module/InterstitialAd.js.map +1 -1
  77. package/lib/module/LightPopupAd.js +11 -13
  78. package/lib/module/LightPopupAd.js.map +1 -1
  79. package/lib/module/NativeDaroModule.js +5 -0
  80. package/lib/module/NativeDaroModule.js.map +1 -0
  81. package/lib/module/RewardedAd.js +8 -11
  82. package/lib/module/RewardedAd.js.map +1 -1
  83. package/lib/module/codegen-env.d.js +2 -0
  84. package/lib/module/codegen-env.d.js.map +1 -0
  85. package/lib/module/hooks/useInterstitialAd.js +106 -0
  86. package/lib/module/hooks/useInterstitialAd.js.map +1 -0
  87. package/lib/module/hooks/useLightPopupAd.js +110 -0
  88. package/lib/module/hooks/useLightPopupAd.js.map +1 -0
  89. package/lib/module/hooks/useRewardedAd.js +109 -0
  90. package/lib/module/hooks/useRewardedAd.js.map +1 -0
  91. package/lib/module/index.js +7 -13
  92. package/lib/module/index.js.map +1 -1
  93. package/lib/module/nativeAd/NativeAdView.js +22 -23
  94. package/lib/module/nativeAd/NativeAdView.js.map +1 -1
  95. package/lib/module/nativeAd/NativeAdViewComponents.js +45 -34
  96. package/lib/module/nativeAd/NativeAdViewComponents.js.map +1 -1
  97. package/lib/module/nativeAd/NativeAdViewProvider.js +35 -8
  98. package/lib/module/nativeAd/NativeAdViewProvider.js.map +1 -1
  99. package/lib/typescript/commonjs/plugin/src/index.d.ts +1 -1
  100. package/lib/typescript/commonjs/plugin/src/index.d.ts.map +1 -1
  101. package/lib/typescript/commonjs/plugin/src/withAndroid.d.ts.map +1 -1
  102. package/lib/typescript/commonjs/plugin/src/withIos.d.ts.map +1 -1
  103. package/lib/typescript/commonjs/src/AdBannerView.d.ts +2 -2
  104. package/lib/typescript/commonjs/src/AdBannerView.d.ts.map +1 -1
  105. package/lib/typescript/commonjs/src/AppOpenAd.d.ts.map +1 -1
  106. package/lib/typescript/commonjs/src/DaroMAdBannerViewNativeComponent.d.ts +32 -0
  107. package/lib/typescript/commonjs/src/DaroMAdBannerViewNativeComponent.d.ts.map +1 -0
  108. package/lib/typescript/commonjs/src/DaroMNativeAdViewNativeComponent.d.ts +42 -0
  109. package/lib/typescript/commonjs/src/DaroMNativeAdViewNativeComponent.d.ts.map +1 -0
  110. package/lib/typescript/commonjs/src/DaroMediaViewNativeComponent.d.ts +6 -0
  111. package/lib/typescript/commonjs/src/DaroMediaViewNativeComponent.d.ts.map +1 -0
  112. package/lib/typescript/commonjs/src/EventEmitter.d.ts.map +1 -1
  113. package/lib/typescript/commonjs/src/InterstitialAd.d.ts.map +1 -1
  114. package/lib/typescript/commonjs/src/LightPopupAd.d.ts.map +1 -1
  115. package/lib/typescript/commonjs/src/NativeDaroModule.d.ts +61 -0
  116. package/lib/typescript/commonjs/src/NativeDaroModule.d.ts.map +1 -0
  117. package/lib/typescript/commonjs/src/RewardedAd.d.ts.map +1 -1
  118. package/lib/typescript/commonjs/src/hooks/useInterstitialAd.d.ts +19 -0
  119. package/lib/typescript/commonjs/src/hooks/useInterstitialAd.d.ts.map +1 -0
  120. package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts +23 -0
  121. package/lib/typescript/commonjs/src/hooks/useLightPopupAd.d.ts.map +1 -0
  122. package/lib/typescript/commonjs/src/hooks/useRewardedAd.d.ts +20 -0
  123. package/lib/typescript/commonjs/src/hooks/useRewardedAd.d.ts.map +1 -0
  124. package/lib/typescript/commonjs/src/index.d.ts +7 -1
  125. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  126. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts +1 -0
  127. package/lib/typescript/commonjs/src/nativeAd/NativeAdView.d.ts.map +1 -1
  128. package/lib/typescript/commonjs/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  129. package/lib/typescript/commonjs/src/nativeAd/NativeAdViewProvider.d.ts +11 -5
  130. package/lib/typescript/commonjs/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  131. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts +2 -0
  132. package/lib/typescript/commonjs/src/types/NativeAdViewProps.d.ts.map +1 -1
  133. package/lib/typescript/module/plugin/src/index.d.ts +1 -1
  134. package/lib/typescript/module/plugin/src/index.d.ts.map +1 -1
  135. package/lib/typescript/module/plugin/src/withAndroid.d.ts.map +1 -1
  136. package/lib/typescript/module/plugin/src/withIos.d.ts.map +1 -1
  137. package/lib/typescript/module/src/AdBannerView.d.ts +2 -2
  138. package/lib/typescript/module/src/AdBannerView.d.ts.map +1 -1
  139. package/lib/typescript/module/src/AppOpenAd.d.ts.map +1 -1
  140. package/lib/typescript/module/src/DaroMAdBannerViewNativeComponent.d.ts +32 -0
  141. package/lib/typescript/module/src/DaroMAdBannerViewNativeComponent.d.ts.map +1 -0
  142. package/lib/typescript/module/src/DaroMNativeAdViewNativeComponent.d.ts +42 -0
  143. package/lib/typescript/module/src/DaroMNativeAdViewNativeComponent.d.ts.map +1 -0
  144. package/lib/typescript/module/src/DaroMediaViewNativeComponent.d.ts +6 -0
  145. package/lib/typescript/module/src/DaroMediaViewNativeComponent.d.ts.map +1 -0
  146. package/lib/typescript/module/src/EventEmitter.d.ts.map +1 -1
  147. package/lib/typescript/module/src/InterstitialAd.d.ts.map +1 -1
  148. package/lib/typescript/module/src/LightPopupAd.d.ts.map +1 -1
  149. package/lib/typescript/module/src/NativeDaroModule.d.ts +61 -0
  150. package/lib/typescript/module/src/NativeDaroModule.d.ts.map +1 -0
  151. package/lib/typescript/module/src/RewardedAd.d.ts.map +1 -1
  152. package/lib/typescript/module/src/hooks/useInterstitialAd.d.ts +19 -0
  153. package/lib/typescript/module/src/hooks/useInterstitialAd.d.ts.map +1 -0
  154. package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts +23 -0
  155. package/lib/typescript/module/src/hooks/useLightPopupAd.d.ts.map +1 -0
  156. package/lib/typescript/module/src/hooks/useRewardedAd.d.ts +20 -0
  157. package/lib/typescript/module/src/hooks/useRewardedAd.d.ts.map +1 -0
  158. package/lib/typescript/module/src/index.d.ts +7 -1
  159. package/lib/typescript/module/src/index.d.ts.map +1 -1
  160. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts +1 -0
  161. package/lib/typescript/module/src/nativeAd/NativeAdView.d.ts.map +1 -1
  162. package/lib/typescript/module/src/nativeAd/NativeAdViewComponents.d.ts.map +1 -1
  163. package/lib/typescript/module/src/nativeAd/NativeAdViewProvider.d.ts +11 -5
  164. package/lib/typescript/module/src/nativeAd/NativeAdViewProvider.d.ts.map +1 -1
  165. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts +2 -0
  166. package/lib/typescript/module/src/types/NativeAdViewProps.d.ts.map +1 -1
  167. package/package.json +12 -5
  168. package/plugin/build/index.d.ts +1 -1
  169. package/plugin/build/withAndroid.js +99 -17
  170. package/plugin/build/withIos.js +4 -5
  171. package/react-native-daro.podspec +3 -0
  172. package/src/AdBannerView.tsx +24 -61
  173. package/src/AppOpenAd.ts +46 -9
  174. package/src/DaroMAdBannerViewNativeComponent.ts +47 -0
  175. package/src/DaroMNativeAdViewNativeComponent.ts +62 -0
  176. package/src/DaroMediaViewNativeComponent.ts +9 -0
  177. package/src/EventEmitter.ts +4 -5
  178. package/src/InterstitialAd.ts +8 -10
  179. package/src/LightPopupAd.ts +11 -12
  180. package/src/NativeDaroModule.ts +91 -0
  181. package/src/RewardedAd.ts +8 -10
  182. package/src/codegen-env.d.ts +45 -0
  183. package/src/hooks/useInterstitialAd.ts +117 -0
  184. package/src/hooks/useLightPopupAd.ts +132 -0
  185. package/src/hooks/useRewardedAd.ts +122 -0
  186. package/src/index.tsx +21 -22
  187. package/src/nativeAd/NativeAdView.tsx +41 -54
  188. package/src/nativeAd/NativeAdViewComponents.tsx +80 -42
  189. package/src/nativeAd/NativeAdViewProvider.tsx +75 -17
  190. package/src/types/NativeAdViewProps.ts +7 -0
  191. package/ios/DaroMAdBannerViewManager.swift +0 -91
  192. package/ios/DaroMNativeAdViewManager.swift +0 -291
@@ -0,0 +1,31 @@
1
+ #import <React/RCTDefines.h>
2
+
3
+ #ifdef RCT_NEW_ARCH_ENABLED
4
+
5
+ #import <Foundation/Foundation.h>
6
+ #include <string>
7
+
8
+ NSDictionary *DaroMFabricEventBody(NSDictionary *body)
9
+ {
10
+ return [body isKindOfClass:NSDictionary.class] ? body : @{};
11
+ }
12
+
13
+ std::string DaroMFabricEventString(NSDictionary *body, NSString *key)
14
+ {
15
+ id value = body[key];
16
+ return [value isKindOfClass:NSString.class] ? std::string([value UTF8String]) : "";
17
+ }
18
+
19
+ double DaroMFabricEventDouble(NSDictionary *body, NSString *key)
20
+ {
21
+ id value = body[key];
22
+ return [value respondsToSelector:@selector(doubleValue)] ? [value doubleValue] : 0;
23
+ }
24
+
25
+ int DaroMFabricEventInt(NSDictionary *body, NSString *key)
26
+ {
27
+ id value = body[key];
28
+ return [value respondsToSelector:@selector(intValue)] ? [value intValue] : 0;
29
+ }
30
+
31
+ #endif
@@ -0,0 +1,123 @@
1
+ #import <React/RCTDefines.h>
2
+
3
+ #ifdef RCT_NEW_ARCH_ENABLED
4
+
5
+ #import <React/RCTLog.h>
6
+ #import <UIKit/UIKit.h>
7
+ #include <folly/dynamic.h>
8
+ #include <string>
9
+
10
+ static NSString *DaroMFabricSetterNameForKey(NSString *key)
11
+ {
12
+ if (key.length == 0) {
13
+ return nil;
14
+ }
15
+
16
+ NSString *first = [[key substringToIndex:1] uppercaseString];
17
+ NSString *rest = [key substringFromIndex:1];
18
+ return [NSString stringWithFormat:@"set%@%@:", first, rest];
19
+ }
20
+
21
+ void DaroMFabricSetValue(UIView *view, NSString *key, id value)
22
+ {
23
+ SEL setter = NSSelectorFromString(DaroMFabricSetterNameForKey(key));
24
+ if (![view respondsToSelector:setter]) {
25
+ return;
26
+ }
27
+
28
+ [view setValue:value forKey:key];
29
+ }
30
+
31
+ void DaroMFabricPerformSelector(UIView *view, SEL selector)
32
+ {
33
+ if (![view respondsToSelector:selector]) {
34
+ return;
35
+ }
36
+
37
+ IMP imp = [view methodForSelector:selector];
38
+ auto function = reinterpret_cast<void (*)(id, SEL)>(imp);
39
+ function(view, selector);
40
+ }
41
+
42
+ void DaroMFabricPerformSelectorWithObject(UIView *view, SEL selector, id object)
43
+ {
44
+ if (![view respondsToSelector:selector]) {
45
+ return;
46
+ }
47
+
48
+ IMP imp = [view methodForSelector:selector];
49
+ auto function = reinterpret_cast<void (*)(id, SEL, id)>(imp);
50
+ function(view, selector, object);
51
+ }
52
+
53
+ void DaroMFabricPerformSelectorWithTwoObjects(UIView *view, SEL selector, id firstObject, id secondObject)
54
+ {
55
+ if (![view respondsToSelector:selector]) {
56
+ return;
57
+ }
58
+
59
+ IMP imp = [view methodForSelector:selector];
60
+ auto function = reinterpret_cast<void (*)(id, SEL, id, id)>(imp);
61
+ function(view, selector, firstObject, secondObject);
62
+ }
63
+
64
+ UIView *DaroMFabricCreateSwiftView(NSString *className)
65
+ {
66
+ Class viewClass = NSClassFromString(className);
67
+ if (![viewClass isSubclassOfClass:UIView.class]) {
68
+ RCTLogError(@"%@ is not available as a UIView subclass.", className);
69
+ return [UIView new];
70
+ }
71
+
72
+ return [[viewClass alloc] init];
73
+ }
74
+
75
+ NSString *DaroMFabricNSStringFromStdString(const std::string &value)
76
+ {
77
+ return [NSString stringWithUTF8String:value.c_str()];
78
+ }
79
+
80
+ static id DaroMFabricNSObjectFromDynamic(const folly::dynamic &value)
81
+ {
82
+ switch (value.type()) {
83
+ case folly::dynamic::NULLT:
84
+ return (id)kCFNull;
85
+ case folly::dynamic::BOOL:
86
+ return value.getBool() ? @YES : @NO;
87
+ case folly::dynamic::INT64:
88
+ return @(value.getInt());
89
+ case folly::dynamic::DOUBLE:
90
+ return @(value.getDouble());
91
+ case folly::dynamic::STRING:
92
+ return [[NSString alloc] initWithBytes:value.c_str() length:value.size() encoding:NSUTF8StringEncoding];
93
+ case folly::dynamic::ARRAY: {
94
+ NSMutableArray *array = [[NSMutableArray alloc] initWithCapacity:value.size()];
95
+ for (const auto &item : value) {
96
+ id converted = DaroMFabricNSObjectFromDynamic(item);
97
+ if (converted != nil) {
98
+ [array addObject:converted];
99
+ }
100
+ }
101
+ return array;
102
+ }
103
+ case folly::dynamic::OBJECT: {
104
+ NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithCapacity:value.size()];
105
+ for (const auto &item : value.items()) {
106
+ id key = DaroMFabricNSObjectFromDynamic(item.first);
107
+ id converted = DaroMFabricNSObjectFromDynamic(item.second);
108
+ if (key != nil && converted != nil && [key conformsToProtocol:@protocol(NSCopying)]) {
109
+ dictionary[key] = converted;
110
+ }
111
+ }
112
+ return dictionary;
113
+ }
114
+ }
115
+ }
116
+
117
+ id DaroMFabricIdFromDynamic(const folly::dynamic &value)
118
+ {
119
+ id converted = DaroMFabricNSObjectFromDynamic(value);
120
+ return converted == (id)kCFNull ? nil : converted;
121
+ }
122
+
123
+ #endif
@@ -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
+ }