adwhale-sdk-react-native 2.7.100
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/AdwhaleSdkReactNative.podspec +20 -0
- package/LICENSE +20 -0
- package/README.md +121 -0
- package/android/build.gradle +135 -0
- package/android/gradle.properties +2 -0
- package/android/proguard-rules.pro +247 -0
- package/android/settings.gradle +71 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/adwhalesdkreactnative/AdwhaleSdkReactNativePackage.java +130 -0
- package/android/src/main/java/com/adwhalesdkreactnative/RNAdWhaleMediationAdSettingModule.java +64 -0
- package/android/src/main/java/com/adwhalesdkreactnative/RNAdWhaleMediationAdView.java +172 -0
- package/android/src/main/java/com/adwhalesdkreactnative/RNAdWhaleMediationCustomNativeAdView.java +197 -0
- package/android/src/main/java/com/adwhalesdkreactnative/RNAdWhaleMediationInterstitialAd.java +134 -0
- package/android/src/main/java/com/adwhalesdkreactnative/RNAdWhaleMediationLoggerModule.java +35 -0
- package/android/src/main/java/com/adwhalesdkreactnative/RNAdWhaleMediationRewardAd.java +151 -0
- package/android/src/main/java/com/adwhalesdkreactnative/RNAdWhaleMediationTemplateNativeAdView.java +317 -0
- package/android/src/main/java/com/adwhalesdkreactnative/RNWrapperView.java +48 -0
- package/android/src/main/res/layout/custom_native_ad_layout.xml +58 -0
- package/app.plugin.js +2 -0
- package/ios/AdwhaleSdkReactNative.h +5 -0
- package/ios/AdwhaleSdkReactNative.mm +21 -0
- package/lib/module/AdWhaleBannerView.js +20 -0
- package/lib/module/AdWhaleBannerView.js.map +1 -0
- package/lib/module/AdWhaleInterstitialAd.js +47 -0
- package/lib/module/AdWhaleInterstitialAd.js.map +1 -0
- package/lib/module/AdWhaleMediationSdk.js +48 -0
- package/lib/module/AdWhaleMediationSdk.js.map +1 -0
- package/lib/module/AdWhaleNativeCustomView.js +36 -0
- package/lib/module/AdWhaleNativeCustomView.js.map +1 -0
- package/lib/module/AdWhaleNativeTemplateView.js +40 -0
- package/lib/module/AdWhaleNativeTemplateView.js.map +1 -0
- package/lib/module/AdWhaleRewardAd.js +50 -0
- package/lib/module/AdWhaleRewardAd.js.map +1 -0
- package/lib/module/NativeAdwhaleSdkReactNative.js +5 -0
- package/lib/module/NativeAdwhaleSdkReactNative.js.map +1 -0
- package/lib/module/index.js +28 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/AdWhaleBannerView.d.ts +18 -0
- package/lib/typescript/src/AdWhaleBannerView.d.ts.map +1 -0
- package/lib/typescript/src/AdWhaleInterstitialAd.d.ts +19 -0
- package/lib/typescript/src/AdWhaleInterstitialAd.d.ts.map +1 -0
- package/lib/typescript/src/AdWhaleMediationSdk.d.ts +17 -0
- package/lib/typescript/src/AdWhaleMediationSdk.d.ts.map +1 -0
- package/lib/typescript/src/AdWhaleNativeCustomView.d.ts +19 -0
- package/lib/typescript/src/AdWhaleNativeCustomView.d.ts.map +1 -0
- package/lib/typescript/src/AdWhaleNativeTemplateView.d.ts +40 -0
- package/lib/typescript/src/AdWhaleNativeTemplateView.d.ts.map +1 -0
- package/lib/typescript/src/AdWhaleRewardAd.d.ts +24 -0
- package/lib/typescript/src/AdWhaleRewardAd.d.ts.map +1 -0
- package/lib/typescript/src/NativeAdwhaleSdkReactNative.d.ts +7 -0
- package/lib/typescript/src/NativeAdwhaleSdkReactNative.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +11 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/package.json +168 -0
- package/plugin/index.js +16 -0
- package/react-native.config.js +30 -0
- package/src/AdWhaleBannerView.tsx +53 -0
- package/src/AdWhaleInterstitialAd.ts +93 -0
- package/src/AdWhaleMediationSdk.ts +93 -0
- package/src/AdWhaleNativeCustomView.tsx +87 -0
- package/src/AdWhaleNativeTemplateView.tsx +119 -0
- package/src/AdWhaleRewardAd.ts +106 -0
- package/src/NativeAdwhaleSdkReactNative.ts +7 -0
- package/src/index.ts +61 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
package com.adwhalesdkreactnative;
|
|
2
|
+
|
|
3
|
+
import android.util.Log;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
|
|
7
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
9
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
10
|
+
import net.adwhale.sdk.utils.AdWhaleLog;
|
|
11
|
+
|
|
12
|
+
public class RNAdWhaleMediationLoggerModule extends ReactContextBaseJavaModule {
|
|
13
|
+
public static final String REACT_CLASS_NAME = RNAdWhaleMediationLoggerModule.class.getSimpleName();
|
|
14
|
+
|
|
15
|
+
public RNAdWhaleMediationLoggerModule(ReactApplicationContext reactContext) {
|
|
16
|
+
super(reactContext);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@NonNull
|
|
20
|
+
@Override
|
|
21
|
+
public String getName() {
|
|
22
|
+
return REACT_CLASS_NAME;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@ReactMethod
|
|
26
|
+
public void setLogLevel(boolean isEnabled) {
|
|
27
|
+
if (isEnabled) {
|
|
28
|
+
Log.d(REACT_CLASS_NAME, "로거가 활성화되었습니다.");
|
|
29
|
+
AdWhaleLog.setLogLevel(AdWhaleLog.LogLevel.Verbose);
|
|
30
|
+
} else {
|
|
31
|
+
Log.d(REACT_CLASS_NAME, "로거가 비활성화되었습니다.");
|
|
32
|
+
AdWhaleLog.setLogLevel(AdWhaleLog.LogLevel.None);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
package com.adwhalesdkreactnative;
|
|
2
|
+
|
|
3
|
+
import android.util.Log;
|
|
4
|
+
|
|
5
|
+
import androidx.annotation.NonNull;
|
|
6
|
+
import androidx.annotation.Nullable;
|
|
7
|
+
|
|
8
|
+
import com.facebook.react.bridge.Arguments;
|
|
9
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
|
10
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
11
|
+
import com.facebook.react.bridge.ReactMethod;
|
|
12
|
+
import com.facebook.react.bridge.UiThreadUtil;
|
|
13
|
+
import com.facebook.react.bridge.WritableMap;
|
|
14
|
+
import com.facebook.react.modules.core.DeviceEventManagerModule;
|
|
15
|
+
|
|
16
|
+
import net.adwhale.sdk.mediation.ads.AdWhaleMediationFullScreenContentCallback;
|
|
17
|
+
import net.adwhale.sdk.mediation.ads.AdWhaleMediationRewardAd;
|
|
18
|
+
import net.adwhale.sdk.mediation.ads.AdWhaleMediationRewardItem;
|
|
19
|
+
import net.adwhale.sdk.mediation.ads.AdWhaleMediationRewardedAdLoadCallback;
|
|
20
|
+
import net.adwhale.sdk.mediation.ads.AdWhaleMediationUserEarnedRewardListener;
|
|
21
|
+
|
|
22
|
+
import java.util.HashMap;
|
|
23
|
+
import java.util.Map;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Old Architecture 를 사용한다.
|
|
27
|
+
* JS <--> 네이티브 모듈 간 왕복 호출이 많지도 않고 성능 상 TurboModule이 꼭 필요하진 않음
|
|
28
|
+
*/
|
|
29
|
+
public class RNAdWhaleMediationRewardAd extends ReactContextBaseJavaModule implements AdWhaleMediationRewardedAdLoadCallback, AdWhaleMediationFullScreenContentCallback, AdWhaleMediationUserEarnedRewardListener {
|
|
30
|
+
|
|
31
|
+
public static final String REACT_CLASS_NAME = RNAdWhaleMediationRewardAd.class.getSimpleName();
|
|
32
|
+
private AdWhaleMediationRewardAd adWhaleMediationRewardAd;
|
|
33
|
+
private String placementUid;
|
|
34
|
+
private final ReactApplicationContext reactContext;
|
|
35
|
+
|
|
36
|
+
public RNAdWhaleMediationRewardAd(ReactApplicationContext context) {
|
|
37
|
+
super(context);
|
|
38
|
+
reactContext = context;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
@NonNull
|
|
43
|
+
@Override
|
|
44
|
+
public String getName() {
|
|
45
|
+
return REACT_CLASS_NAME;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@ReactMethod
|
|
49
|
+
public void loadAd(String placementUid) {
|
|
50
|
+
Log.e(REACT_CLASS_NAME, "loadAd()");
|
|
51
|
+
this.placementUid = placementUid;
|
|
52
|
+
adWhaleMediationRewardAd = new AdWhaleMediationRewardAd(placementUid);
|
|
53
|
+
adWhaleMediationRewardAd.setAdWhaleMediationFullScreenContentCallback(this);
|
|
54
|
+
|
|
55
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
56
|
+
adWhaleMediationRewardAd.loadAd(this);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@ReactMethod
|
|
61
|
+
public void showAd() {
|
|
62
|
+
Log.e(REACT_CLASS_NAME, "showAd()");
|
|
63
|
+
if (adWhaleMediationRewardAd == null) {
|
|
64
|
+
Log.e(REACT_CLASS_NAME, "adWhaleMediationRewardAd is null");
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
UiThreadUtil.runOnUiThread(() -> {
|
|
69
|
+
adWhaleMediationRewardAd.showAd(this);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
/// AdWhaleMediationFullScreenContentCallback
|
|
75
|
+
@Override
|
|
76
|
+
public void onAdClicked() {
|
|
77
|
+
Log.i(REACT_CLASS_NAME, "onAdClicked()");
|
|
78
|
+
sendEvnet("onRewardAdClicked", null);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@Override
|
|
82
|
+
public void onAdDismissed() {
|
|
83
|
+
Log.i(REACT_CLASS_NAME, "onAdDismissed()");
|
|
84
|
+
sendEvnet("onRewardAdDismissed", null);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@Override
|
|
88
|
+
public void onFailedToShow(int statusCode, String message) {
|
|
89
|
+
Log.i(REACT_CLASS_NAME, "onFailedToShow(" + statusCode + ", " + message + ")");
|
|
90
|
+
WritableMap params = Arguments.createMap();
|
|
91
|
+
params.putInt("statusCode", statusCode);
|
|
92
|
+
params.putString("message", message);
|
|
93
|
+
sendEvnet("onRewardAdFailedToShow", params);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@Override
|
|
97
|
+
public void onAdShowed() {
|
|
98
|
+
Log.i(REACT_CLASS_NAME, "onAdShowed()");
|
|
99
|
+
sendEvnet("onRewardAdShowed", null);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/// AdWhaleMediationRewardedAdLoadCallback
|
|
103
|
+
@Override
|
|
104
|
+
public void onAdLoaded(AdWhaleMediationRewardAd adWhaleMediationRewardAd, String message) {
|
|
105
|
+
Log.i(REACT_CLASS_NAME, "onAdLoaded(+ " + message + ")");
|
|
106
|
+
sendEvnet("onRewardAdLoaded", null);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
@Override
|
|
110
|
+
public void onAdFailedToLoad(int statusCode, String message) {
|
|
111
|
+
Log.i(REACT_CLASS_NAME, "onAdFailedToLoad(" + statusCode + ", " + message + ")");
|
|
112
|
+
WritableMap params = Arguments.createMap();
|
|
113
|
+
params.putInt("statusCode", statusCode);
|
|
114
|
+
params.putString("message", message);
|
|
115
|
+
sendEvnet("onRewardAdFailedToLoad", params);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
/// AdWhaleMediationUserEarnedRewardListener
|
|
120
|
+
@Override
|
|
121
|
+
public void onUserRewarded(AdWhaleMediationRewardItem adWhaleMediationRewardItem) {
|
|
122
|
+
Log.i(REACT_CLASS_NAME, "onUserRewarded(" + adWhaleMediationRewardItem.toString() + ")");
|
|
123
|
+
WritableMap params = Arguments.createMap();
|
|
124
|
+
params.putString("type", adWhaleMediationRewardItem.getRewardType());
|
|
125
|
+
params.putInt("amount", adWhaleMediationRewardItem.getRewardAmount());
|
|
126
|
+
sendEvnet("onUserRewarded", params);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Nullable
|
|
130
|
+
@Override
|
|
131
|
+
public Map<String, Object> getConstants() {
|
|
132
|
+
final Map<String, Object> constants = new HashMap<>();
|
|
133
|
+
return constants;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
private void sendEvnet(String eventName, @Nullable WritableMap params) {
|
|
137
|
+
getReactApplicationContext()
|
|
138
|
+
.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class)
|
|
139
|
+
.emit(eventName, params);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@ReactMethod
|
|
143
|
+
public void addListener(String eventName) {
|
|
144
|
+
//TODO NOTHING
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
@ReactMethod
|
|
148
|
+
public void removeListeners(Integer count) {
|
|
149
|
+
//TODO NOTHING
|
|
150
|
+
}
|
|
151
|
+
}
|
package/android/src/main/java/com/adwhalesdkreactnative/RNAdWhaleMediationTemplateNativeAdView.java
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
package com.adwhalesdkreactnative;
|
|
2
|
+
|
|
3
|
+
import android.os.Handler;
|
|
4
|
+
import android.os.Looper;
|
|
5
|
+
import android.util.Log;
|
|
6
|
+
import android.view.View;
|
|
7
|
+
import android.widget.RelativeLayout;
|
|
8
|
+
|
|
9
|
+
import androidx.annotation.NonNull;
|
|
10
|
+
import androidx.annotation.Nullable;
|
|
11
|
+
|
|
12
|
+
import com.facebook.react.bridge.Arguments;
|
|
13
|
+
import com.facebook.react.bridge.ReactContext;
|
|
14
|
+
import com.facebook.react.bridge.WritableMap;
|
|
15
|
+
import com.facebook.react.common.MapBuilder;
|
|
16
|
+
import com.facebook.react.bridge.ReadableMap;
|
|
17
|
+
import com.facebook.react.uimanager.SimpleViewManager;
|
|
18
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
19
|
+
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
20
|
+
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
21
|
+
|
|
22
|
+
import net.adwhale.sdk.mediation.ads.AdWhaleMediationNativeAdView;
|
|
23
|
+
import net.adwhale.sdk.mediation.ads.AdWhaleMediationNativeAdViewListener;
|
|
24
|
+
import net.adwhale.sdk.mediation.ads.ADWHALE_NATIVE_TEMPLATE;
|
|
25
|
+
import net.adwhale.sdk.mediation.ads.AdWhaleMediationNativeTemplateStyle;
|
|
26
|
+
import android.graphics.Color;
|
|
27
|
+
import android.graphics.Typeface;
|
|
28
|
+
import android.graphics.drawable.ColorDrawable;
|
|
29
|
+
|
|
30
|
+
import java.util.Map;
|
|
31
|
+
|
|
32
|
+
public class RNAdWhaleMediationTemplateNativeAdView extends SimpleViewManager<RNWrapperView> {
|
|
33
|
+
public static final String REACT_CLASS = RNAdWhaleMediationTemplateNativeAdView.class.getSimpleName();
|
|
34
|
+
|
|
35
|
+
public static final int COMMAND_LOAD_AD = 1;
|
|
36
|
+
public static final int COMMAND_SHOW_AD = 2;
|
|
37
|
+
|
|
38
|
+
private String placementUid = "";
|
|
39
|
+
private ADWHALE_NATIVE_TEMPLATE template = ADWHALE_NATIVE_TEMPLATE.SMALL;
|
|
40
|
+
private AdWhaleMediationNativeTemplateStyle templateStyle = null;
|
|
41
|
+
|
|
42
|
+
@NonNull
|
|
43
|
+
@Override
|
|
44
|
+
public String getName() {
|
|
45
|
+
return REACT_CLASS;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@NonNull
|
|
49
|
+
@Override
|
|
50
|
+
protected RNWrapperView createViewInstance(@NonNull ThemedReactContext reactContext) {
|
|
51
|
+
RNWrapperView wrapperView = new RNWrapperView(reactContext);
|
|
52
|
+
AdWhaleMediationNativeAdView adWhaleMediationNativeAdView = new AdWhaleMediationNativeAdView(reactContext);
|
|
53
|
+
wrapperView.addView(adWhaleMediationNativeAdView);
|
|
54
|
+
setAdListener(reactContext, wrapperView);
|
|
55
|
+
return wrapperView;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private void setAdListener(ThemedReactContext reactContext, RNWrapperView view) {
|
|
59
|
+
AdWhaleMediationNativeAdView adWhaleMediationNativeAdView = getAdWhaleMediationNativeAdView(view);
|
|
60
|
+
if (adWhaleMediationNativeAdView == null) return;
|
|
61
|
+
|
|
62
|
+
adWhaleMediationNativeAdView.setAdWhaleMediationNativeAdViewListener(new AdWhaleMediationNativeAdViewListener() {
|
|
63
|
+
@Override
|
|
64
|
+
public void onNativeAdLoaded() {
|
|
65
|
+
Log.d(REACT_CLASS, "onNativeAdLoaded");
|
|
66
|
+
dispatchEvent(reactContext, view, "onAdLoaded", null);
|
|
67
|
+
view.requestLayout();
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Override
|
|
71
|
+
public void onNativeAdFailedToLoad(int code, String message) {
|
|
72
|
+
Log.d(REACT_CLASS, "onNativeAdFailedToLoad: " + code + ", " + message);
|
|
73
|
+
WritableMap event = Arguments.createMap();
|
|
74
|
+
event.putInt("errorCode", code);
|
|
75
|
+
event.putString("errorMessage", message);
|
|
76
|
+
dispatchEvent(reactContext, view, "onAdFailedToLoad", event);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Override
|
|
80
|
+
public void onNativeAdShowFailed(int code, String message) {
|
|
81
|
+
Log.d(REACT_CLASS, "onNativeAdShowFailed: " + code + ", " + message);
|
|
82
|
+
WritableMap event = Arguments.createMap();
|
|
83
|
+
event.putInt("errorCode", code);
|
|
84
|
+
event.putString("errorMessage", message);
|
|
85
|
+
dispatchEvent(reactContext, view, "onAdShowFailed", event);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
@Override
|
|
89
|
+
public void onNativeAdClicked() {
|
|
90
|
+
// Not used in RN
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Override
|
|
94
|
+
public void onNativeAdClosed() {
|
|
95
|
+
// Not used in RN
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private void dispatchEvent(ThemedReactContext context, View view, String eventName, @Nullable WritableMap eventData) {
|
|
101
|
+
context.getJSModule(RCTEventEmitter.class).receiveEvent(
|
|
102
|
+
view.getId(),
|
|
103
|
+
eventName,
|
|
104
|
+
eventData
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
@Nullable
|
|
109
|
+
@Override
|
|
110
|
+
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
|
|
111
|
+
MapBuilder.Builder<String, Object> builder = MapBuilder.builder();
|
|
112
|
+
builder.put("onAdLoaded", MapBuilder.of("registrationName", "onAdLoaded"));
|
|
113
|
+
builder.put("onAdFailedToLoad", MapBuilder.of("registrationName", "onAdFailedToLoad"));
|
|
114
|
+
builder.put("onAdShowFailed", MapBuilder.of("registrationName", "onAdShowFailed"));
|
|
115
|
+
return builder.build();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@ReactProp(name = "templateStyle")
|
|
119
|
+
public void setTemplateStyle(RNWrapperView view, @Nullable ReadableMap styleMap) {
|
|
120
|
+
if (styleMap == null) {
|
|
121
|
+
this.templateStyle = null;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
AdWhaleMediationNativeTemplateStyle.Builder styleBuilder = new AdWhaleMediationNativeTemplateStyle.Builder();
|
|
126
|
+
|
|
127
|
+
if (styleMap.hasKey("mainBackgroundColor")) {
|
|
128
|
+
styleBuilder.withMainBackgroundColor(new ColorDrawable(parseColorString(styleMap.getString("mainBackgroundColor"))));
|
|
129
|
+
}
|
|
130
|
+
if (styleMap.hasKey("primaryTextTypefaceColor")) {
|
|
131
|
+
styleBuilder.withPrimaryTextTypefaceColor(parseColorString(styleMap.getString("primaryTextTypefaceColor")));
|
|
132
|
+
}
|
|
133
|
+
if (styleMap.hasKey("secondaryTextTypefaceColor")) {
|
|
134
|
+
styleBuilder.withSecondaryTextTypefaceColor(parseColorString(styleMap.getString("secondaryTextTypefaceColor")));
|
|
135
|
+
}
|
|
136
|
+
if (styleMap.hasKey("tertiaryTextTypefaceColor")) {
|
|
137
|
+
styleBuilder.withTertiaryTextTypefaceColor(parseColorString(styleMap.getString("tertiaryTextTypefaceColor")));
|
|
138
|
+
}
|
|
139
|
+
if (styleMap.hasKey("callToActionTypefaceColor")) {
|
|
140
|
+
styleBuilder.withCallToActionTypefaceColor(parseColorString(styleMap.getString("callToActionTypefaceColor")));
|
|
141
|
+
}
|
|
142
|
+
if (styleMap.hasKey("callToActionBackgroundColor")) {
|
|
143
|
+
styleBuilder.withCallToActionBackgroundColor(new ColorDrawable(parseColorString(styleMap.getString("callToActionBackgroundColor"))));
|
|
144
|
+
}
|
|
145
|
+
if (styleMap.hasKey("primaryTextSize")) {
|
|
146
|
+
styleBuilder.withPrimaryTextSize((float) styleMap.getDouble("primaryTextSize"));
|
|
147
|
+
}
|
|
148
|
+
if (styleMap.hasKey("secondaryTextSize")) {
|
|
149
|
+
styleBuilder.withSecondaryTextSize((float) styleMap.getDouble("secondaryTextSize"));
|
|
150
|
+
}
|
|
151
|
+
if (styleMap.hasKey("tertiaryTextSize")) {
|
|
152
|
+
styleBuilder.withTertiaryTextSize((float) styleMap.getDouble("tertiaryTextSize"));
|
|
153
|
+
}
|
|
154
|
+
if (styleMap.hasKey("callToActionTextSize")) {
|
|
155
|
+
styleBuilder.withCallToActionTextSize((float) styleMap.getDouble("callToActionTextSize"));
|
|
156
|
+
}
|
|
157
|
+
if (styleMap.hasKey("primaryTextBackgroundColor")) {
|
|
158
|
+
styleBuilder.withPrimaryTextBackgroundColor(new ColorDrawable(parseColorString(styleMap.getString("primaryTextBackgroundColor"))));
|
|
159
|
+
}
|
|
160
|
+
if (styleMap.hasKey("secondaryTextBackgroundColor")) {
|
|
161
|
+
styleBuilder.withSecondaryTextBackgroundColor(new ColorDrawable(parseColorString(styleMap.getString("secondaryTextBackgroundColor"))));
|
|
162
|
+
}
|
|
163
|
+
if (styleMap.hasKey("tertiaryTextBackgroundColor")) {
|
|
164
|
+
styleBuilder.withTertiaryTextBackgroundColor(new ColorDrawable(parseColorString(styleMap.getString("tertiaryTextBackgroundColor"))));
|
|
165
|
+
}
|
|
166
|
+
if (styleMap.hasKey("primaryTextTypeface")) {
|
|
167
|
+
styleBuilder.withPrimaryTextTypeface(getTypeface(styleMap.getString("primaryTextTypeface")));
|
|
168
|
+
}
|
|
169
|
+
if (styleMap.hasKey("secondaryTextTypeface")) {
|
|
170
|
+
styleBuilder.withSecondaryTextTypeface(getTypeface(styleMap.getString("secondaryTextTypeface")));
|
|
171
|
+
}
|
|
172
|
+
if (styleMap.hasKey("callToActionTextTypeface")) {
|
|
173
|
+
styleBuilder.withCallToActionTextTypeface(getTypeface(styleMap.getString("callToActionTextTypeface")));
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
this.templateStyle = styleBuilder.build();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
private int parseColorString(String colorString) {
|
|
180
|
+
if (colorString == null) {
|
|
181
|
+
return Color.TRANSPARENT;
|
|
182
|
+
}
|
|
183
|
+
switch (colorString.toLowerCase()) {
|
|
184
|
+
case "transparent":
|
|
185
|
+
return Color.TRANSPARENT;
|
|
186
|
+
case "black":
|
|
187
|
+
return Color.BLACK;
|
|
188
|
+
case "white":
|
|
189
|
+
return Color.WHITE;
|
|
190
|
+
case "red":
|
|
191
|
+
return Color.RED;
|
|
192
|
+
case "green":
|
|
193
|
+
return Color.GREEN;
|
|
194
|
+
case "blue":
|
|
195
|
+
return Color.BLUE;
|
|
196
|
+
case "yellow":
|
|
197
|
+
return Color.YELLOW;
|
|
198
|
+
case "cyan":
|
|
199
|
+
return Color.CYAN;
|
|
200
|
+
case "magenta":
|
|
201
|
+
return Color.MAGENTA;
|
|
202
|
+
case "gray":
|
|
203
|
+
return Color.GRAY;
|
|
204
|
+
default:
|
|
205
|
+
try {
|
|
206
|
+
return Color.parseColor(colorString);
|
|
207
|
+
} catch (IllegalArgumentException e) {
|
|
208
|
+
Log.e(REACT_CLASS, "Unknown color: " + colorString);
|
|
209
|
+
return Color.TRANSPARENT; // Fallback color
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
private Typeface getTypeface(String typeface) {
|
|
215
|
+
if (typeface == null) {
|
|
216
|
+
return null;
|
|
217
|
+
}
|
|
218
|
+
switch (typeface.toLowerCase()) {
|
|
219
|
+
case "bold":
|
|
220
|
+
return Typeface.DEFAULT_BOLD;
|
|
221
|
+
case "italic":
|
|
222
|
+
return Typeface.create(Typeface.DEFAULT, Typeface.ITALIC);
|
|
223
|
+
default:
|
|
224
|
+
return Typeface.DEFAULT;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
@Nullable
|
|
229
|
+
@Override
|
|
230
|
+
public Map<String, Integer> getCommandsMap() {
|
|
231
|
+
return MapBuilder.of(
|
|
232
|
+
"loadAd", COMMAND_LOAD_AD,
|
|
233
|
+
"showAd", COMMAND_SHOW_AD
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@Override
|
|
238
|
+
public void receiveCommand(@NonNull RNWrapperView view, int commandId, @Nullable com.facebook.react.bridge.ReadableArray args) {
|
|
239
|
+
super.receiveCommand(view, commandId, args);
|
|
240
|
+
switch (commandId) {
|
|
241
|
+
case COMMAND_LOAD_AD:
|
|
242
|
+
Log.d(REACT_CLASS, "Received loadAd command");
|
|
243
|
+
loadAd(view);
|
|
244
|
+
break;
|
|
245
|
+
case COMMAND_SHOW_AD:
|
|
246
|
+
Log.d(REACT_CLASS, "Received showAd command");
|
|
247
|
+
showAd(view);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
@ReactProp(name = "placementUid")
|
|
253
|
+
public void setPlacementUid(RNWrapperView view, String placementUid) {
|
|
254
|
+
this.placementUid = placementUid;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
@ReactProp(name = "template")
|
|
258
|
+
public void setTemplate(RNWrapperView view, String templateName) {
|
|
259
|
+
if ("SMALL".equalsIgnoreCase(templateName)) {
|
|
260
|
+
this.template = ADWHALE_NATIVE_TEMPLATE.SMALL;
|
|
261
|
+
} else if ("MEDIUM".equalsIgnoreCase(templateName)) {
|
|
262
|
+
this.template = ADWHALE_NATIVE_TEMPLATE.MEDIUM;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
private void loadAd(RNWrapperView view) {
|
|
267
|
+
new Handler(Looper.getMainLooper()).post(() -> {
|
|
268
|
+
AdWhaleMediationNativeAdView adWhaleMediationNativeAdView = getAdWhaleMediationNativeAdView(view);
|
|
269
|
+
if (adWhaleMediationNativeAdView != null) {
|
|
270
|
+
if (placementUid == null || placementUid.isEmpty()) {
|
|
271
|
+
Log.e(REACT_CLASS, "Placement UID is null or empty. Cannot load ad.");
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (template == null) {
|
|
275
|
+
Log.e(REACT_CLASS, "Template is null. Cannot load ad.");
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
Log.d(REACT_CLASS, "Placement UID: " + placementUid);
|
|
279
|
+
Log.d(REACT_CLASS, "Template: " + template.name());
|
|
280
|
+
adWhaleMediationNativeAdView.setPlacementUid(placementUid);
|
|
281
|
+
if (this.templateStyle != null) {
|
|
282
|
+
adWhaleMediationNativeAdView.setTemplateStyle(this.templateStyle);
|
|
283
|
+
}
|
|
284
|
+
adWhaleMediationNativeAdView.loadAdWithTemplate(template);
|
|
285
|
+
Log.d(REACT_CLASS, "Calling loadAdWithTemplate...");
|
|
286
|
+
} else {
|
|
287
|
+
Log.e(REACT_CLASS, "adWhaleMediationNativeAdView is null. Cannot load ad.");
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private void showAd(RNWrapperView view) {
|
|
293
|
+
AdWhaleMediationNativeAdView adWhaleMediationNativeAdView = getAdWhaleMediationNativeAdView(view);
|
|
294
|
+
if (adWhaleMediationNativeAdView != null) {
|
|
295
|
+
adWhaleMediationNativeAdView.show();
|
|
296
|
+
} else {
|
|
297
|
+
Log.e(REACT_CLASS, "adWhaleMediationNativeAdView is null. Cannot show ad.");
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
@Override
|
|
302
|
+
public void onDropViewInstance(@NonNull RNWrapperView view) {
|
|
303
|
+
super.onDropViewInstance(view);
|
|
304
|
+
Log.d(REACT_CLASS, "onDropViewInstance called");
|
|
305
|
+
AdWhaleMediationNativeAdView adWhaleMediationNativeAdView = getAdWhaleMediationNativeAdView(view);
|
|
306
|
+
if (adWhaleMediationNativeAdView != null) {
|
|
307
|
+
adWhaleMediationNativeAdView.destroy();
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
private AdWhaleMediationNativeAdView getAdWhaleMediationNativeAdView(RNWrapperView parent) {
|
|
312
|
+
if (parent != null && parent.getChildCount() > 0 && parent.getChildAt(0) instanceof AdWhaleMediationNativeAdView) {
|
|
313
|
+
return (AdWhaleMediationNativeAdView) parent.getChildAt(0);
|
|
314
|
+
}
|
|
315
|
+
return null;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
package com.adwhalesdkreactnative;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.view.View;
|
|
6
|
+
import android.widget.FrameLayout;
|
|
7
|
+
|
|
8
|
+
public class RNWrapperView extends FrameLayout {
|
|
9
|
+
|
|
10
|
+
public RNWrapperView(Context context) {
|
|
11
|
+
super(context);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
@Override
|
|
15
|
+
public void requestLayout() {
|
|
16
|
+
super.requestLayout();
|
|
17
|
+
post(measureAndLayout);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
private final Runnable measureAndLayout = () -> { // React의 App.Component 시작이랑 비슷하네?
|
|
22
|
+
measure(
|
|
23
|
+
MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
|
|
24
|
+
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
|
|
25
|
+
layout(getLeft(), getTop(), getRight(), getBottom());
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
@Override
|
|
29
|
+
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
30
|
+
int maxWidth = 0;
|
|
31
|
+
int maxHeight = 0;
|
|
32
|
+
|
|
33
|
+
for (int i = 0; i < getChildCount(); i++) {
|
|
34
|
+
View child = getChildAt(i);
|
|
35
|
+
if (child.getVisibility() != GONE) {
|
|
36
|
+
child.measure(widthMeasureSpec, MeasureSpec.UNSPECIFIED);
|
|
37
|
+
|
|
38
|
+
maxWidth = Math.max(maxWidth, child.getMeasuredWidth());
|
|
39
|
+
maxHeight = Math.max(maxHeight, child.getMeasuredHeight());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
int finalWidth = Math.max(maxWidth, getSuggestedMinimumWidth());
|
|
44
|
+
int finalHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
|
|
45
|
+
|
|
46
|
+
setMeasuredDimension(finalWidth, finalHeight);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
3
|
+
android:layout_width="match_parent"
|
|
4
|
+
android:layout_height="wrap_content"
|
|
5
|
+
android:background="#EAEAEA"
|
|
6
|
+
android:padding="8dp">
|
|
7
|
+
|
|
8
|
+
<ImageView
|
|
9
|
+
android:id="@+id/view_icon"
|
|
10
|
+
android:layout_width="60dp"
|
|
11
|
+
android:layout_height="60dp"
|
|
12
|
+
android:layout_alignParentStart="true"
|
|
13
|
+
android:layout_alignParentTop="true"
|
|
14
|
+
android:scaleType="centerCrop" />
|
|
15
|
+
|
|
16
|
+
<TextView
|
|
17
|
+
android:id="@+id/view_title"
|
|
18
|
+
android:layout_width="wrap_content"
|
|
19
|
+
android:layout_height="wrap_content"
|
|
20
|
+
android:layout_toEndOf="@id/view_icon"
|
|
21
|
+
android:layout_alignTop="@id/view_icon"
|
|
22
|
+
android:layout_marginStart="8dp"
|
|
23
|
+
android:textStyle="bold"
|
|
24
|
+
android:textSize="16sp"
|
|
25
|
+
android:textColor="#000000"
|
|
26
|
+
android:maxLines="1"
|
|
27
|
+
android:ellipsize="end" />
|
|
28
|
+
|
|
29
|
+
<TextView
|
|
30
|
+
android:id="@+id/view_body"
|
|
31
|
+
android:layout_width="wrap_content"
|
|
32
|
+
android:layout_height="wrap_content"
|
|
33
|
+
android:layout_toEndOf="@id/view_icon"
|
|
34
|
+
android:layout_below="@id/view_title"
|
|
35
|
+
android:layout_marginStart="8dp"
|
|
36
|
+
android:layout_marginTop="4dp"
|
|
37
|
+
android:textSize="12sp"
|
|
38
|
+
android:textColor="#333333"
|
|
39
|
+
android:maxLines="2"
|
|
40
|
+
android:ellipsize="end" />
|
|
41
|
+
|
|
42
|
+
<FrameLayout
|
|
43
|
+
android:id="@+id/view_media"
|
|
44
|
+
android:layout_width="match_parent"
|
|
45
|
+
android:layout_height="180dp"
|
|
46
|
+
android:layout_below="@id/view_icon"
|
|
47
|
+
android:layout_marginTop="8dp"
|
|
48
|
+
android:background="#CCCCCC" />
|
|
49
|
+
|
|
50
|
+
<Button
|
|
51
|
+
android:id="@+id/button_cta"
|
|
52
|
+
android:layout_width="match_parent"
|
|
53
|
+
android:layout_height="40dp"
|
|
54
|
+
android:layout_below="@id/view_media"
|
|
55
|
+
android:layout_marginTop="8dp"
|
|
56
|
+
android:text="Call to Action" />
|
|
57
|
+
|
|
58
|
+
</RelativeLayout>
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#import "AdwhaleSdkReactNative.h"
|
|
2
|
+
|
|
3
|
+
@implementation AdwhaleSdkReactNative
|
|
4
|
+
- (NSNumber *)multiply:(double)a b:(double)b {
|
|
5
|
+
NSNumber *result = @(a * b);
|
|
6
|
+
|
|
7
|
+
return result;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
11
|
+
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
12
|
+
{
|
|
13
|
+
return std::make_shared<facebook::react::NativeAdwhaleSdkReactNativeSpecJSI>(params);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
+ (NSString *)moduleName
|
|
17
|
+
{
|
|
18
|
+
return @"AdwhaleSdkReactNative";
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// src/AdWhaleBannerView.tsx
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { requireNativeComponent } from 'react-native';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
const RNAdWhaleMediationAdView = requireNativeComponent('RNAdWhaleMediationAdView');
|
|
8
|
+
export const AdWhaleBannerView = ({
|
|
9
|
+
onAdLoadFailed,
|
|
10
|
+
...restProps
|
|
11
|
+
}) => {
|
|
12
|
+
const handleAdLoadFailed = e => {
|
|
13
|
+
onAdLoadFailed?.(e.nativeEvent);
|
|
14
|
+
};
|
|
15
|
+
return /*#__PURE__*/_jsx(RNAdWhaleMediationAdView, {
|
|
16
|
+
...restProps,
|
|
17
|
+
onAdLoadFailed: onAdLoadFailed ? handleAdLoadFailed : undefined
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=AdWhaleBannerView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","requireNativeComponent","jsx","_jsx","RNAdWhaleMediationAdView","AdWhaleBannerView","onAdLoadFailed","restProps","handleAdLoadFailed","e","nativeEvent","undefined"],"sourceRoot":"../../src","sources":["AdWhaleBannerView.tsx"],"mappings":";;AAAA;AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,sBAAsB,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAiCtD,MAAMC,wBAAwB,GAC5BH,sBAAsB,CAAoB,0BAA0B,CAAC;AAEvE,OAAO,MAAMI,iBAAmD,GAAGA,CAAC;EAClEC,cAAc;EACd,GAAGC;AACL,CAAC,KAAK;EACJ,MAAMC,kBAAuD,GAAGC,CAAC,IAAI;IACnEH,cAAc,GAAGG,CAAC,CAACC,WAAW,CAAC;EACjC,CAAC;EAED,oBACEP,IAAA,CAACC,wBAAwB;IAAA,GACnBG,SAAS;IACbD,cAAc,EAAEA,cAAc,GAAGE,kBAAkB,GAAGG;EAAU,CACjE,CAAC;AAEN,CAAC","ignoreList":[]}
|