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,122 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { RewardedAd } from '../RewardedAd';
3
+ import { AdEventType, RewardedAdEventType } from '../types/AdEvent';
4
+ import type {
5
+ AdDisplayFailedInfo,
6
+ AdInfo,
7
+ AdLoadFailedInfo,
8
+ AdRewardInfo,
9
+ } from '../types/AdInfo';
10
+
11
+ export type UseRewardedAdOptions = {
12
+ onLoaded?: (adInfo: AdInfo) => void;
13
+ onLoadFailed?: (error: AdLoadFailedInfo) => void;
14
+ onClicked?: (adInfo: AdInfo) => void;
15
+ onDisplayed?: (adInfo: AdInfo) => void;
16
+ onFailedToDisplay?: (error: AdDisplayFailedInfo) => void;
17
+ onHidden?: (adInfo: AdInfo) => void;
18
+ onImpressionRecorded?: (adInfo: AdInfo) => void;
19
+ onReceivedReward?: (reward: AdRewardInfo) => void;
20
+ };
21
+
22
+ export type UseRewardedAdResult = {
23
+ isLoaded: boolean;
24
+ isLoading: boolean;
25
+ load: () => void;
26
+ show: (customData?: string | null) => void;
27
+ isAdReady: () => Promise<boolean>;
28
+ };
29
+
30
+ export function useRewardedAd(
31
+ adUnitId: string | null,
32
+ options: UseRewardedAdOptions = {}
33
+ ): UseRewardedAdResult {
34
+ const adRef = useRef<RewardedAd | null>(null);
35
+ const optionsRef = useRef(options);
36
+ optionsRef.current = options;
37
+ const [state, setState] = useState({
38
+ isLoaded: false,
39
+ isLoading: false,
40
+ });
41
+
42
+ const load = useCallback(() => {
43
+ if (!adUnitId) {
44
+ return;
45
+ }
46
+
47
+ const ad = adRef.current;
48
+ if (!ad) {
49
+ return;
50
+ }
51
+
52
+ setState({ isLoaded: false, isLoading: true });
53
+ ad.load();
54
+ }, [adUnitId]);
55
+
56
+ const show = useCallback((customData?: string | null) => {
57
+ adRef.current?.show(customData);
58
+ }, []);
59
+
60
+ const isAdReady = useCallback(async () => {
61
+ const isLoaded = (await adRef.current?.isAdReady()) ?? false;
62
+ setState((prevState) => ({ ...prevState, isLoaded }));
63
+ return isLoaded;
64
+ }, []);
65
+
66
+ useEffect(() => {
67
+ adRef.current?.removeAllListeners();
68
+ adRef.current = null;
69
+ setState({ isLoaded: false, isLoading: false });
70
+
71
+ if (!adUnitId) {
72
+ return;
73
+ }
74
+
75
+ const ad = RewardedAd.createForAdRequest(adUnitId);
76
+ adRef.current = ad;
77
+
78
+ ad.addAdEventListener(AdEventType.LOADED, (info) => {
79
+ setState({ isLoaded: true, isLoading: false });
80
+ optionsRef.current.onLoaded?.(info);
81
+ });
82
+ ad.addAdEventListener(AdEventType.LOAD_FAILED, (error) => {
83
+ setState({ isLoaded: false, isLoading: false });
84
+ optionsRef.current.onLoadFailed?.(error);
85
+ });
86
+ ad.addAdEventListener(AdEventType.DISPLAYED, (info) => {
87
+ setState((prevState) => ({ ...prevState, isLoaded: false }));
88
+ optionsRef.current.onDisplayed?.(info);
89
+ });
90
+ ad.addAdEventListener(AdEventType.FAILED_TO_DISPLAY, (error) => {
91
+ setState({ isLoaded: false, isLoading: false });
92
+ optionsRef.current.onFailedToDisplay?.(error);
93
+ });
94
+ ad.addAdEventListener(AdEventType.HIDDEN, (info) => {
95
+ setState((prevState) => ({ ...prevState, isLoaded: false }));
96
+ optionsRef.current.onHidden?.(info);
97
+ });
98
+ ad.addAdEventListener(AdEventType.CLICKED, (info) => {
99
+ optionsRef.current.onClicked?.(info);
100
+ });
101
+ ad.addAdEventListener(AdEventType.IMPRESSION_RECORDED, (info) => {
102
+ optionsRef.current.onImpressionRecorded?.(info);
103
+ });
104
+ ad.addAdEventListener(RewardedAdEventType.RECEIVED_REWARD, (reward) => {
105
+ optionsRef.current.onReceivedReward?.(reward);
106
+ });
107
+
108
+ return () => {
109
+ ad.removeAllListeners();
110
+ if (adRef.current === ad) {
111
+ adRef.current = null;
112
+ }
113
+ };
114
+ }, [adUnitId]);
115
+
116
+ return {
117
+ ...state,
118
+ load,
119
+ show,
120
+ isAdReady,
121
+ };
122
+ }
package/src/index.tsx CHANGED
@@ -1,10 +1,26 @@
1
- import { NativeModules, Platform } from 'react-native';
1
+ import NativeDaroModule from './NativeDaroModule';
2
2
 
3
3
  export * from './AdBannerView';
4
4
  export * from './types';
5
5
  export { InterstitialAd } from './InterstitialAd';
6
+ export { useInterstitialAd } from './hooks/useInterstitialAd';
7
+ export type {
8
+ UseInterstitialAdOptions,
9
+ UseInterstitialAdResult,
10
+ } from './hooks/useInterstitialAd';
6
11
  export { RewardedAd } from './RewardedAd';
12
+ export { useRewardedAd } from './hooks/useRewardedAd';
13
+ export type {
14
+ UseRewardedAdOptions,
15
+ UseRewardedAdResult,
16
+ } from './hooks/useRewardedAd';
7
17
  export { LightPopupAd } from './LightPopupAd';
18
+ export { useLightPopupAd } from './hooks/useLightPopupAd';
19
+ export type {
20
+ UseLightPopupAdOptions,
21
+ UseLightPopupAdLoadOptions,
22
+ UseLightPopupAdResult,
23
+ } from './hooks/useLightPopupAd';
8
24
 
9
25
  export { NativeAdView } from './nativeAd/NativeAdView';
10
26
  export {
@@ -15,31 +31,14 @@ export {
15
31
  TitleView,
16
32
  } from './nativeAd/NativeAdViewComponents';
17
33
 
18
- const LINKING_ERROR =
19
- `The native module 'DaroMModule' doesn't seem to be linked. Make sure: \n\n` +
20
- Platform.select({ ios: "- You have run 'pod install'\n", default: '' }) +
21
- '- You rebuilt the app after installing the package\n' +
22
- '- You are not using Expo Go\n';
23
-
24
- const DaroMModule = NativeModules.DaroMModule
25
- ? NativeModules.DaroMModule
26
- : new Proxy(
27
- {},
28
- {
29
- get() {
30
- throw new Error(LINKING_ERROR);
31
- },
32
- }
33
- );
34
-
35
34
  export async function initialize() {
36
- await DaroMModule.initializeSdk();
35
+ await NativeDaroModule.initializeSdk();
37
36
  }
38
37
 
39
38
  export async function showMediationDebugger() {
40
- await DaroMModule.showMediationDebugger();
39
+ await NativeDaroModule.showMediationDebugger();
41
40
  }
42
41
 
43
- export async function setUserId(userId: String) {
44
- await DaroMModule.setUserId(userId);
42
+ export async function setUserId(userId: string) {
43
+ await NativeDaroModule.setUserId(userId);
45
44
  }
@@ -6,15 +6,13 @@ import {
6
6
  useImperativeHandle,
7
7
  useRef,
8
8
  useState,
9
+ type ElementRef,
9
10
  } from 'react';
10
- import {
11
- findNodeHandle,
12
- NativeModules,
13
- requireNativeComponent,
14
- UIManager,
15
- View,
16
- type ViewProps,
17
- } from 'react-native';
11
+ import { View, type ViewProps } from 'react-native';
12
+ import NativeAdViewNativeComponent, {
13
+ Commands,
14
+ } from '../DaroMNativeAdViewNativeComponent';
15
+ import NativeDaroModule from '../NativeDaroModule';
18
16
  import type { AdNativeEvent } from '../types/AdEvent';
19
17
  import type { AdInfo, AdLoadFailedInfo } from '../types/AdInfo';
20
18
  import type {
@@ -24,23 +22,9 @@ import type {
24
22
  import {
25
23
  NativeAdViewContext,
26
24
  NativeAdViewProvider,
27
- type NativeAdViewContextType,
28
- type NativeAdViewType,
29
25
  } from './NativeAdViewProvider';
30
26
 
31
- const { DaroMModule } = NativeModules;
32
-
33
- type NativeAdViewNativeEvents = {
34
- onAdLoadedEvent(event: AdNativeEvent<AdInfo>): void;
35
- onAdLoadFailedEvent(event: AdNativeEvent<AdLoadFailedInfo>): void;
36
- onAdClickedEvent(event: AdNativeEvent<AdInfo>): void;
37
- onAdImpressionRecordedEvent(event: AdNativeEvent<AdInfo>): void;
38
- };
39
-
40
- const ComponentName = 'DaroMNativeAdView';
41
- const NativeAdViewComponent = requireNativeComponent<
42
- NativeAdViewProps & ViewProps & NativeAdViewNativeEvents
43
- >(ComponentName);
27
+ type NativeAdViewElement = ElementRef<typeof NativeAdViewNativeComponent>;
44
28
 
45
29
  export const NativeAdView = forwardRef<
46
30
  NativeAdViewHandler,
@@ -50,7 +34,7 @@ export const NativeAdView = forwardRef<
50
34
 
51
35
  useEffect(() => {
52
36
  const checkInitialization = async () => {
53
- const result = await DaroMModule.isInitialized();
37
+ const result = await NativeDaroModule.isInitialized();
54
38
  setIsInitialized(result);
55
39
  if (!result) {
56
40
  console.warn(
@@ -87,47 +71,27 @@ const NativeAdViewImpl = forwardRef<
87
71
  children,
88
72
  style,
89
73
  loadOnMount = true,
74
+ adChoicesPosition = 'bottomRight',
90
75
  ...otherProps
91
76
  },
92
77
  ref
93
78
  ) {
94
- // Context provides functions to manage native ad and native ad view state
95
- const { setNativeAdView } = useContext(
96
- NativeAdViewContext
97
- ) as NativeAdViewContextType;
98
-
99
- const nativeAdViewRef = useRef<NativeAdViewType | null>(null);
79
+ const { nativeAdAssetRegistrations } = useContext(NativeAdViewContext);
80
+ const nativeAdViewRef = useRef<NativeAdViewElement | null>(null);
100
81
 
101
82
  // Load a new ad
102
83
  const loadAd = useCallback(() => {
103
84
  if (nativeAdViewRef.current) {
104
- const nodeHandle = findNodeHandle(nativeAdViewRef.current);
105
-
106
- if (typeof nodeHandle !== 'number') {
107
- return;
108
- }
109
-
110
- UIManager.dispatchViewManagerCommand(
111
- nodeHandle,
112
- // @ts-ignore: Issue in RN ts defs
113
- UIManager.getViewManagerConfig(ComponentName).Commands.loadAd,
114
- []
115
- );
85
+ Commands.loadAd(nativeAdViewRef.current);
116
86
  }
117
87
  }, []);
118
88
 
119
89
  useImperativeHandle(ref, () => ({ loadAd }), [loadAd]);
120
90
 
121
91
  // Save the DOM element reference
122
- const saveElement = useCallback(
123
- (element: NativeAdViewType | null) => {
124
- if (element) {
125
- nativeAdViewRef.current = element;
126
- setNativeAdView(element);
127
- }
128
- },
129
- [setNativeAdView]
130
- );
92
+ const saveElement = useCallback((element: NativeAdViewElement | null) => {
93
+ nativeAdViewRef.current = element;
94
+ }, []);
131
95
 
132
96
  const onAdLoadedEvent = useCallback(
133
97
  (event: AdNativeEvent<AdInfo>) => {
@@ -158,18 +122,41 @@ const NativeAdViewImpl = forwardRef<
158
122
  );
159
123
 
160
124
  return (
161
- <NativeAdViewComponent
125
+ <NativeAdViewNativeComponent
162
126
  ref={saveElement}
127
+ {...otherProps}
163
128
  adUnitId={adUnitId}
164
129
  loadOnMount={loadOnMount}
130
+ adChoicesPosition={adChoicesPosition}
131
+ titleView={nativeAdAssetRegistrations.titleView?.nativeTag ?? 0}
132
+ bodyView={nativeAdAssetRegistrations.bodyView?.nativeTag ?? 0}
133
+ callToActionView={
134
+ nativeAdAssetRegistrations.callToActionView?.nativeTag ?? 0
135
+ }
136
+ iconView={nativeAdAssetRegistrations.iconView?.nativeTag ?? 0}
137
+ mediaView={nativeAdAssetRegistrations.mediaView?.nativeTag ?? 0}
138
+ titleViewStyleProps={
139
+ nativeAdAssetRegistrations.titleView?.styleProps ?? null
140
+ }
141
+ bodyViewStyleProps={
142
+ nativeAdAssetRegistrations.bodyView?.styleProps ?? null
143
+ }
144
+ callToActionViewStyleProps={
145
+ nativeAdAssetRegistrations.callToActionView?.styleProps ?? null
146
+ }
147
+ iconViewStyleProps={
148
+ nativeAdAssetRegistrations.iconView?.styleProps ?? null
149
+ }
150
+ mediaViewStyleProps={
151
+ nativeAdAssetRegistrations.mediaView?.styleProps ?? null
152
+ }
165
153
  onAdLoadedEvent={onAdLoadedEvent}
166
154
  onAdLoadFailedEvent={onAdLoadFailedEvent}
167
155
  onAdClickedEvent={onAdClickedEvent}
168
156
  onAdImpressionRecordedEvent={onAdImpressionRecordedEvent}
169
157
  style={style}
170
- {...otherProps}
171
158
  >
172
159
  {children}
173
- </NativeAdViewComponent>
160
+ </NativeAdViewNativeComponent>
174
161
  );
175
162
  });
@@ -1,9 +1,8 @@
1
1
  import * as React from 'react';
2
2
  import {
3
3
  type ComponentRef,
4
- useCallback,
5
4
  useContext,
6
- useEffect,
5
+ useLayoutEffect,
7
6
  useMemo,
8
7
  useRef,
9
8
  } from 'react';
@@ -13,10 +12,25 @@ import type {
13
12
  TextProps,
14
13
  TextStyle,
15
14
  ImageStyle,
15
+ ViewStyle,
16
16
  ViewProps,
17
17
  } from 'react-native';
18
- import { findNodeHandle, Image, Platform, Text, View } from 'react-native';
19
- import { NativeAdViewContext } from './NativeAdViewProvider';
18
+ import {
19
+ findNodeHandle,
20
+ Image,
21
+ Platform,
22
+ StyleSheet,
23
+ Text,
24
+ UIManager,
25
+ View,
26
+ } from 'react-native';
27
+ import {
28
+ NativeAdViewContext,
29
+ type NativeAdViewAssetPropKey,
30
+ } from './NativeAdViewProvider';
31
+ import DaroMediaViewNativeComponent from '../DaroMediaViewNativeComponent';
32
+
33
+ const UNREGISTERED_NATIVE_TAG = 0;
20
34
 
21
35
  // 스타일 속성 추출을 위한 타입 정의
22
36
  type StyleProps = {
@@ -67,9 +81,13 @@ type StyleProps = {
67
81
  };
68
82
 
69
83
  // 스타일 속성 추출 커스텀 훅
70
- const useStyleProps = (style: StyleProp<TextStyle>): StyleProps => {
84
+ const useStyleProps = (
85
+ style: StyleProp<TextStyle | ViewStyle>,
86
+ textProps?: Pick<TextProps, 'numberOfLines' | 'ellipsizeMode'>
87
+ ): StyleProps => {
71
88
  return useMemo(() => {
72
- const styleObj = style as TextStyle;
89
+ const styleObj = (StyleSheet.flatten(style) ?? {}) as TextStyle & ViewStyle;
90
+
73
91
  return {
74
92
  // 1. 폰트 관련
75
93
  fontSize: styleObj.fontSize as number,
@@ -87,6 +105,8 @@ const useStyleProps = (style: StyleProp<TextStyle>): StyleProps => {
87
105
  | 'right'
88
106
  | 'center'
89
107
  | 'justify',
108
+ numberOfLines: textProps?.numberOfLines,
109
+ lineBreakMode: textProps?.ellipsizeMode as StyleProps['lineBreakMode'],
90
110
 
91
111
  // 6. 투명도
92
112
  opacity: styleObj.opacity as number,
@@ -127,8 +147,8 @@ const useStyleProps = (style: StyleProp<TextStyle>): StyleProps => {
127
147
  left: styleObj.left as number,
128
148
 
129
149
  // 15. 크기
130
- width: styleObj.width as number,
131
- height: styleObj.height as number,
150
+ width: styleObj.width as number | string,
151
+ height: styleObj.height as number | string,
132
152
 
133
153
  // 16. 변환
134
154
  transform: styleObj.transform as any[],
@@ -138,7 +158,7 @@ const useStyleProps = (style: StyleProp<TextStyle>): StyleProps => {
138
158
  overflow: styleObj.overflow as 'visible' | 'hidden' | 'scroll',
139
159
  backfaceVisibility: styleObj.backfaceVisibility as 'visible' | 'hidden',
140
160
  };
141
- }, [style]);
161
+ }, [style, textProps?.ellipsizeMode, textProps?.numberOfLines]);
142
162
  };
143
163
 
144
164
  // Image 스타일 속성을 위한 타입 정의 추가
@@ -157,7 +177,8 @@ type ImageStyleProps = StyleProps & {
157
177
  // Image 스타일 속성 추출 커스텀 훅
158
178
  const useImageStyleProps = (style: StyleProp<ImageStyle>): ImageStyleProps => {
159
179
  return useMemo(() => {
160
- const styleObj = style as ImageStyle;
180
+ const styleObj = StyleSheet.flatten(style) ?? {};
181
+
161
182
  return {
162
183
  // 기본 스타일 속성
163
184
  backgroundColor: styleObj.backgroundColor as string,
@@ -170,8 +191,8 @@ const useImageStyleProps = (style: StyleProp<ImageStyle>): ImageStyleProps => {
170
191
  shadowOpacity: styleObj.shadowOpacity as number,
171
192
  shadowRadius: styleObj.shadowRadius as number,
172
193
 
173
- width: styleObj.width as number,
174
- height: styleObj.height as number,
194
+ width: styleObj.width as number | string,
195
+ height: styleObj.height as number | string,
175
196
 
176
197
  // Image 전용 스타일 속성
177
198
  resizeMode: styleObj.resizeMode as
@@ -187,41 +208,47 @@ const useImageStyleProps = (style: StyleProp<ImageStyle>): ImageStyleProps => {
187
208
  }, [style]);
188
209
  };
189
210
 
190
- // 네이티브 속성 설정 커스텀 훅
191
- const useNativeAdViewProps = (
211
+ type NativeAdAssetStyleProps = StyleProps | ImageStyleProps;
212
+
213
+ // 네이티브 광고 자산 등록 커스텀 훅
214
+ const useNativeAdAssetRegistration = (
192
215
  ref: React.RefObject<any>,
193
- nativePropKey: string,
194
- styleProps?: StyleProps
216
+ nativePropKey: NativeAdViewAssetPropKey,
217
+ styleProps?: NativeAdAssetStyleProps
195
218
  ) => {
196
- const { nativeAdView } = useContext(NativeAdViewContext);
219
+ const { registerNativeAdAsset, unregisterNativeAdAsset } =
220
+ useContext(NativeAdViewContext);
197
221
 
198
- const setNativeProps = useCallback(() => {
199
- if (!ref.current) return;
200
- const props: any = {
201
- [nativePropKey]: findNodeHandle(ref.current),
202
- };
203
-
204
- if (styleProps) {
205
- props[`${nativePropKey}StyleProps`] = styleProps;
206
- }
222
+ useLayoutEffect(() => {
223
+ const nativeTag = ref.current
224
+ ? (findNodeHandle(ref.current) ?? UNREGISTERED_NATIVE_TAG)
225
+ : UNREGISTERED_NATIVE_TAG;
207
226
 
208
- nativeAdView?.setNativeProps(props);
209
- }, [nativeAdView, ref, nativePropKey, styleProps]);
227
+ registerNativeAdAsset(nativePropKey, nativeTag, styleProps ?? null);
228
+ }, [nativePropKey, ref, registerNativeAdAsset, styleProps]);
210
229
 
211
- useEffect(() => {
212
- setNativeProps();
213
- }, [setNativeProps]);
230
+ useLayoutEffect(() => {
231
+ return () => {
232
+ unregisterNativeAdAsset(nativePropKey);
233
+ };
234
+ }, [nativePropKey, unregisterNativeAdAsset]);
214
235
  };
215
236
 
216
237
  // 공통 Text 컴포넌트
217
- const AdTextView = (props: TextProps & { nativePropKey: string }) => {
218
- const { nativePropKey, ...restProps } = props;
238
+ const AdTextView = (
239
+ props: TextProps & { nativePropKey: NativeAdViewAssetPropKey }
240
+ ) => {
241
+ const { nativePropKey, children, ...restProps } = props;
219
242
  const textRef = useRef<ComponentRef<typeof Text> | null>(null);
220
- const styleProps = useStyleProps(props.style);
243
+ const styleProps = useStyleProps(props.style, props);
221
244
 
222
- useNativeAdViewProps(textRef, nativePropKey, styleProps);
245
+ useNativeAdAssetRegistration(textRef, nativePropKey, styleProps);
223
246
 
224
- return <Text {...restProps} ref={textRef} />;
247
+ return (
248
+ <Text {...restProps} ref={textRef}>
249
+ {children ?? (Platform.OS === 'android' ? ' ' : undefined)}
250
+ </Text>
251
+ );
225
252
  };
226
253
 
227
254
  export const TitleView = (props: TextProps) => {
@@ -233,14 +260,19 @@ export const BodyView = (props: TextProps) => {
233
260
  };
234
261
 
235
262
  export const CallToActionView = (props: TextProps) => {
263
+ const { children, ...restProps } = props;
236
264
  const callToActionRef = useRef<ComponentRef<typeof Text> | null>(null);
237
- const styleProps = useStyleProps(props.style);
265
+ const styleProps = useStyleProps(props.style, props);
238
266
 
239
- useNativeAdViewProps(callToActionRef, 'callToActionView', styleProps);
267
+ useNativeAdAssetRegistration(callToActionRef, 'callToActionView', styleProps);
240
268
 
241
269
  // TouchableOpacity disables clicking on certain Android devices.
242
270
  if (Platform.OS === 'android') {
243
- return <Text {...props} ref={callToActionRef} />;
271
+ return (
272
+ <Text {...restProps} ref={callToActionRef}>
273
+ {children ?? ' '}
274
+ </Text>
275
+ );
244
276
  } else {
245
277
  return (
246
278
  <View>
@@ -253,14 +285,20 @@ export const CallToActionView = (props: TextProps) => {
253
285
  export const IconView = (props: Omit<ImageProps, 'source'>) => {
254
286
  const imageRef = useRef<ComponentRef<typeof Image> | null>(null);
255
287
  const iconViewStyleProps = useImageStyleProps(props.style);
256
- useNativeAdViewProps(imageRef, 'iconView', iconViewStyleProps);
288
+ useNativeAdAssetRegistration(imageRef, 'iconView', iconViewStyleProps);
257
289
 
258
290
  return <Image {...props} ref={imageRef} source={0} />;
259
291
  };
260
292
 
293
+ const NativeMediaView =
294
+ Platform.OS === 'android' && UIManager.hasViewManagerConfig?.('DaroMediaView')
295
+ ? DaroMediaViewNativeComponent
296
+ : View;
297
+
261
298
  export const MediaView = (props: ViewProps) => {
262
299
  const viewRef = useRef<ComponentRef<typeof View> | null>(null);
263
- useNativeAdViewProps(viewRef, 'mediaView');
300
+ const mediaViewStyleProps = useStyleProps(props.style);
301
+ useNativeAdAssetRegistration(viewRef, 'mediaView', mediaViewStyleProps);
264
302
 
265
- return <View {...props} ref={viewRef} />;
303
+ return <NativeMediaView {...props} ref={viewRef} collapsable={false} />;
266
304
  };
@@ -1,37 +1,95 @@
1
1
  import type { ReactNode } from 'react';
2
2
  import * as React from 'react';
3
- import { createContext, useState } from 'react';
4
- import type { NativeMethods } from 'react-native';
5
- import type { NativeAdViewProps } from '../types/NativeAdViewProps';
3
+ import { createContext, useCallback, useMemo, useState } from 'react';
6
4
 
7
- export type NativeAdViewType = React.Component<NativeAdViewProps> &
8
- NativeMethods;
5
+ type NativeAdAssetStyleProps = object | null;
6
+
7
+ type NativeAdAssetRegistration = {
8
+ nativeTag: number;
9
+ styleProps: NativeAdAssetStyleProps;
10
+ };
11
+
12
+ export type NativeAdViewAssetPropKey =
13
+ | 'titleView'
14
+ | 'bodyView'
15
+ | 'callToActionView'
16
+ | 'iconView'
17
+ | 'mediaView';
18
+
19
+ export type NativeAdAssetRegistrations = Partial<
20
+ Record<NativeAdViewAssetPropKey, NativeAdAssetRegistration>
21
+ >;
9
22
 
10
23
  export type NativeAdViewContextType = {
11
- nativeAdView: NativeAdViewType | null;
12
- setNativeAdView: React.Dispatch<
13
- React.SetStateAction<NativeAdViewType | null>
14
- >;
24
+ nativeAdAssetRegistrations: NativeAdAssetRegistrations;
25
+ registerNativeAdAsset: (
26
+ assetKey: NativeAdViewAssetPropKey,
27
+ nativeTag: number,
28
+ styleProps: NativeAdAssetStyleProps
29
+ ) => void;
30
+ unregisterNativeAdAsset: (assetKey: NativeAdViewAssetPropKey) => void;
15
31
  };
16
32
 
17
33
  export const NativeAdViewContext = createContext<NativeAdViewContextType>({
18
- nativeAdView: null,
19
- setNativeAdView: () => {},
34
+ nativeAdAssetRegistrations: {},
35
+ registerNativeAdAsset: () => {},
36
+ unregisterNativeAdAsset: () => {},
20
37
  });
21
38
 
22
39
  export const NativeAdViewProvider: React.FC<{ children: ReactNode }> = ({
23
40
  children,
24
41
  }) => {
25
- const [nativeAdView, setNativeAdView] = useState<NativeAdViewType | null>(
26
- null
42
+ const [nativeAdAssetRegistrations, setNativeAdAssetRegistrations] =
43
+ useState<NativeAdAssetRegistrations>({});
44
+
45
+ const registerNativeAdAsset = useCallback(
46
+ (
47
+ assetKey: NativeAdViewAssetPropKey,
48
+ nativeTag: number,
49
+ styleProps: NativeAdAssetStyleProps
50
+ ) => {
51
+ setNativeAdAssetRegistrations((prev) => {
52
+ const current = prev[assetKey];
53
+
54
+ if (
55
+ current?.nativeTag === nativeTag &&
56
+ current?.styleProps === styleProps
57
+ ) {
58
+ return prev;
59
+ }
60
+
61
+ return {
62
+ ...prev,
63
+ [assetKey]: {
64
+ nativeTag,
65
+ styleProps,
66
+ },
67
+ };
68
+ });
69
+ },
70
+ []
71
+ );
72
+
73
+ const unregisterNativeAdAsset = useCallback(
74
+ (assetKey: NativeAdViewAssetPropKey) => {
75
+ setNativeAdAssetRegistrations((prev) => {
76
+ if (!prev[assetKey]) return prev;
77
+
78
+ const next = { ...prev };
79
+ delete next[assetKey];
80
+ return next;
81
+ });
82
+ },
83
+ []
27
84
  );
28
85
 
29
- const providerValue = React.useMemo(
86
+ const providerValue = useMemo(
30
87
  () => ({
31
- nativeAdView,
32
- setNativeAdView,
88
+ nativeAdAssetRegistrations,
89
+ registerNativeAdAsset,
90
+ unregisterNativeAdAsset,
33
91
  }),
34
- [nativeAdView]
92
+ [nativeAdAssetRegistrations, registerNativeAdAsset, unregisterNativeAdAsset]
35
93
  );
36
94
 
37
95
  return (
@@ -1,5 +1,11 @@
1
1
  import type { AdProps } from './AdProps';
2
2
 
3
+ export type AdChoicesPosition =
4
+ | 'topLeft'
5
+ | 'topRight'
6
+ | 'bottomRight'
7
+ | 'bottomLeft';
8
+
3
9
  /**
4
10
  * A handler of {@link NativeAdView}.
5
11
  */
@@ -15,4 +21,5 @@ export type NativeAdViewHandler = {
15
21
  */
16
22
  export type NativeAdViewProps = AdProps & {
17
23
  loadOnMount?: boolean;
24
+ adChoicesPosition?: AdChoicesPosition;
18
25
  };