@24jieqi/react-native-brayant-ad 0.1.29 → 0.1.30
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/android/src/main/java/com/brayantad/dy/banner/BannerAdModule.java +0 -4
- package/android/src/main/java/com/brayantad/dy/banner/BannerAdViewManager.java +2 -2
- package/android/src/main/java/com/brayantad/dy/banner/view/BannerAdView.java +1 -50
- package/lib/commonjs/dy/component/BannerAd.js +6 -7
- package/lib/commonjs/dy/component/BannerAd.js.map +1 -1
- package/lib/module/dy/component/BannerAd.js +6 -7
- package/lib/module/dy/component/BannerAd.js.map +1 -1
- package/lib/typescript/src/dy/component/BannerAd.d.ts +1 -1
- package/lib/typescript/src/dy/component/BannerAd.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/dy/component/BannerAd.tsx +7 -8
|
@@ -128,16 +128,12 @@ public class BannerAdModule extends ReactContextBaseJavaModule {
|
|
|
128
128
|
* @return 缓存的广告,如果没有则返回 null
|
|
129
129
|
*/
|
|
130
130
|
public static TTNativeExpressAd getCachedBannerAd(String codeId) {
|
|
131
|
-
Log.d(TAG, "getCachedBannerAd called with codeId: " + codeId + ", cachedCodeId: " + bannerAdCacheCodeId);
|
|
132
|
-
Log.d(TAG, "cache status - cache null: " + (bannerAdCache == null) + ", codeId null: " + (bannerAdCacheCodeId == null));
|
|
133
131
|
if (hasValidCache(codeId)) {
|
|
134
|
-
Log.d(TAG, "getCachedBannerAd - cache hit!");
|
|
135
132
|
TTNativeExpressAd cachedAd = bannerAdCache;
|
|
136
133
|
// 使用后清除缓存,避免重复使用
|
|
137
134
|
clearCache();
|
|
138
135
|
return cachedAd;
|
|
139
136
|
}
|
|
140
|
-
Log.d(TAG, "getCachedBannerAd - cache miss");
|
|
141
137
|
return null;
|
|
142
138
|
}
|
|
143
139
|
|
|
@@ -52,8 +52,8 @@ public class BannerAdViewManager extends ViewGroupManager<BannerAdView> {
|
|
|
52
52
|
view.setHeight(adHeight);
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
@ReactProp(name = "
|
|
56
|
-
public void
|
|
55
|
+
@ReactProp(name = "visible")
|
|
56
|
+
public void setVisible(BannerAdView view, boolean visible) {
|
|
57
57
|
view.setVisibility(visible);
|
|
58
58
|
}
|
|
59
59
|
|
|
@@ -3,7 +3,6 @@ package com.brayantad.dy.banner.view;
|
|
|
3
3
|
import static com.facebook.react.bridge.UiThreadUtil.runOnUiThread;
|
|
4
4
|
|
|
5
5
|
import android.app.Activity;
|
|
6
|
-
import android.util.Log;
|
|
7
6
|
import android.view.View;
|
|
8
7
|
import android.view.ViewGroup;
|
|
9
8
|
import android.widget.RelativeLayout;
|
|
@@ -22,7 +21,6 @@ import com.facebook.react.bridge.WritableMap;
|
|
|
22
21
|
import com.facebook.react.uimanager.events.RCTEventEmitter;
|
|
23
22
|
|
|
24
23
|
public class BannerAdView extends RelativeLayout {
|
|
25
|
-
public static final String TAG = "BannerAdView";
|
|
26
24
|
private Activity mActivity;
|
|
27
25
|
private ReactContext mReactContext;
|
|
28
26
|
private String mCodeId;
|
|
@@ -35,7 +33,6 @@ public class BannerAdView extends RelativeLayout {
|
|
|
35
33
|
|
|
36
34
|
public BannerAdView(ReactContext context) {
|
|
37
35
|
super(context);
|
|
38
|
-
Log.d(TAG, "BannerAdView constructor called");
|
|
39
36
|
mReactContext = context;
|
|
40
37
|
mActivity = context.getCurrentActivity();
|
|
41
38
|
|
|
@@ -49,18 +46,15 @@ public class BannerAdView extends RelativeLayout {
|
|
|
49
46
|
mExpectedHeight
|
|
50
47
|
);
|
|
51
48
|
setLayoutParams(params);
|
|
52
|
-
Log.d(TAG, "BannerAdView constructor completed");
|
|
53
49
|
}
|
|
54
50
|
|
|
55
51
|
public void setWidth(int width) {
|
|
56
52
|
mExpectedWidth = width;
|
|
57
|
-
Log.d(TAG, "setWidth called: " + width + ", current state - width:" + mExpectedWidth + " height:" + mExpectedHeight + " codeId:" + mCodeId);
|
|
58
53
|
showAd();
|
|
59
54
|
}
|
|
60
55
|
|
|
61
56
|
public void setHeight(int height) {
|
|
62
57
|
mExpectedHeight = height;
|
|
63
|
-
Log.d(TAG, "setHeight called: " + height + ", current state - width:" + mExpectedWidth + " height:" + mExpectedHeight + " codeId:" + mCodeId);
|
|
64
58
|
|
|
65
59
|
ViewGroup.LayoutParams params = getLayoutParams();
|
|
66
60
|
if (params != null) {
|
|
@@ -73,7 +67,6 @@ public class BannerAdView extends RelativeLayout {
|
|
|
73
67
|
|
|
74
68
|
public void setCodeId(String codeId) {
|
|
75
69
|
mCodeId = codeId;
|
|
76
|
-
Log.d(TAG, "setCodeId called: " + codeId + ", current state - width:" + mExpectedWidth + " height:" + mExpectedHeight + " codeId:" + mCodeId);
|
|
77
70
|
showAd();
|
|
78
71
|
}
|
|
79
72
|
|
|
@@ -82,7 +75,6 @@ public class BannerAdView extends RelativeLayout {
|
|
|
82
75
|
* @param visible true: 可见,false: 不可见
|
|
83
76
|
*/
|
|
84
77
|
public void setVisibility(boolean visible) {
|
|
85
|
-
Log.d(TAG, "setVisibility called: " + visible + ", current state - width:" + mExpectedWidth + " height:" + mExpectedHeight + " codeId:" + mCodeId);
|
|
86
78
|
if (visible) {
|
|
87
79
|
// 触发加载,但暂不显示(等待渲染成功)
|
|
88
80
|
showAd();
|
|
@@ -92,41 +84,34 @@ public class BannerAdView extends RelativeLayout {
|
|
|
92
84
|
}
|
|
93
85
|
|
|
94
86
|
public void showAd() {
|
|
95
|
-
Log.d(TAG, "showAd called - width:" + mExpectedWidth + " height:" + mExpectedHeight + " codeId:" + mCodeId + " isLoading:" + mIsAdLoading);
|
|
96
87
|
// 参数校验
|
|
97
88
|
if (mExpectedWidth <= 0 || mExpectedHeight <= 0 || mCodeId == null || mCodeId.isEmpty()) {
|
|
98
|
-
Log.d(TAG, "showAd skipped - params not ready");
|
|
99
89
|
return;
|
|
100
90
|
}
|
|
101
91
|
|
|
102
92
|
// 防止重复加载
|
|
103
93
|
if (mIsAdLoading) {
|
|
104
|
-
Log.d(TAG, "showAd skipped - already loading");
|
|
105
94
|
return;
|
|
106
95
|
}
|
|
107
96
|
|
|
108
97
|
// 检查 SDK 初始化
|
|
109
98
|
if (DyADCore.TTAdSdk == null) {
|
|
110
|
-
Log.d(TAG, "showAd skipped - SDK not initialized");
|
|
111
99
|
return;
|
|
112
100
|
}
|
|
113
101
|
|
|
114
102
|
// 在UI线程加载广告
|
|
115
|
-
Log.d(TAG, "showAd starting loadBannerAd");
|
|
116
103
|
mIsAdLoading = true;
|
|
117
104
|
runOnUiThread(this::loadBannerAd);
|
|
118
105
|
}
|
|
119
106
|
|
|
120
107
|
// 显示Banner广告
|
|
121
108
|
private void loadBannerAd() {
|
|
122
|
-
Log.d(TAG, "loadBannerAd called for codeId: " + mCodeId);
|
|
123
109
|
if (mBannerAd != null) {
|
|
124
110
|
mBannerAd.destroy();
|
|
125
111
|
}
|
|
126
112
|
|
|
127
113
|
// 先检查是否有预加载的缓存广告
|
|
128
114
|
TTNativeExpressAd cachedAd = BannerAdModule.getCachedBannerAd(mCodeId);
|
|
129
|
-
Log.d(TAG, "loadBannerAd - cachedAd: " + (cachedAd != null ? "found" : "not found"));
|
|
130
115
|
if (cachedAd != null) {
|
|
131
116
|
mBannerAd = cachedAd;
|
|
132
117
|
showBannerAd(mBannerAd);
|
|
@@ -135,7 +120,6 @@ public class BannerAdView extends RelativeLayout {
|
|
|
135
120
|
}
|
|
136
121
|
|
|
137
122
|
// 没有缓存,正常加载
|
|
138
|
-
Log.d(TAG, "loadBannerAd - loading from network");
|
|
139
123
|
// 创建广告请求参数AdSlot
|
|
140
124
|
mAdSlot =
|
|
141
125
|
new AdSlot.Builder()
|
|
@@ -151,7 +135,6 @@ public class BannerAdView extends RelativeLayout {
|
|
|
151
135
|
|
|
152
136
|
@Override
|
|
153
137
|
public void onError(int code, String message) {
|
|
154
|
-
Log.d(TAG, "loadBannerAd - onError: " + code + ", " + message);
|
|
155
138
|
mIsAdLoading = false;
|
|
156
139
|
String errorMsg = "Banner ad error: " + code + ", " + message;
|
|
157
140
|
onAdError(errorMsg);
|
|
@@ -159,13 +142,13 @@ public class BannerAdView extends RelativeLayout {
|
|
|
159
142
|
|
|
160
143
|
@Override
|
|
161
144
|
public void onNativeExpressAdLoad(java.util.List<TTNativeExpressAd> ads) {
|
|
162
|
-
Log.d(TAG, "loadBannerAd - onNativeExpressAdLoad, ads count: " + (ads != null ? ads.size() : 0));
|
|
163
145
|
if (ads == null || ads.isEmpty()) {
|
|
164
146
|
mIsAdLoading = false;
|
|
165
147
|
onAdError("Banner ad loaded but no content");
|
|
166
148
|
return;
|
|
167
149
|
}
|
|
168
150
|
|
|
151
|
+
mIsAdLoading = false;
|
|
169
152
|
mBannerAd = ads.get(0);
|
|
170
153
|
showBannerAd(mBannerAd);
|
|
171
154
|
}
|
|
@@ -175,23 +158,12 @@ public class BannerAdView extends RelativeLayout {
|
|
|
175
158
|
|
|
176
159
|
// 显示广告
|
|
177
160
|
private void showBannerAd(final TTNativeExpressAd ad) {
|
|
178
|
-
Log.d(TAG, "showBannerAd - checking Activity");
|
|
179
|
-
// 延迟获取 Activity,因为构造函数中可能还未 attach
|
|
180
|
-
if (mActivity == null) {
|
|
181
|
-
mActivity = mReactContext.getCurrentActivity();
|
|
182
|
-
}
|
|
183
161
|
if (mActivity == null) {
|
|
184
|
-
Log.d(TAG, "showBannerAd - Activity is null, delaying...");
|
|
185
|
-
// 延迟重试,最多重试5次
|
|
186
|
-
postDelayed(() -> showBannerAd(ad), 200);
|
|
187
162
|
return;
|
|
188
163
|
}
|
|
189
|
-
Log.d(TAG, "showBannerAd - Activity available, proceeding");
|
|
190
164
|
mActivity.runOnUiThread(() -> {
|
|
191
165
|
bindAdListener(ad);
|
|
192
|
-
Log.d(TAG, "showBannerAd - calling ad.render()");
|
|
193
166
|
ad.render();
|
|
194
|
-
Log.d(TAG, "showBannerAd - ad.render() called");
|
|
195
167
|
});
|
|
196
168
|
}
|
|
197
169
|
|
|
@@ -199,25 +171,10 @@ public class BannerAdView extends RelativeLayout {
|
|
|
199
171
|
private final void bindAdListener(TTNativeExpressAd ad) {
|
|
200
172
|
final RelativeLayout mExpressContainer = findViewById(R.id.feed_container);
|
|
201
173
|
if (mExpressContainer == null) {
|
|
202
|
-
Log.d(TAG, "bindAdListener - feed_container not found");
|
|
203
|
-
mIsAdLoading = false;
|
|
204
174
|
onAdError("feed_container not found");
|
|
205
175
|
return;
|
|
206
176
|
}
|
|
207
177
|
|
|
208
|
-
// 确保 Activity 可用
|
|
209
|
-
if (mActivity == null) {
|
|
210
|
-
mActivity = mReactContext.getCurrentActivity();
|
|
211
|
-
}
|
|
212
|
-
if (mActivity == null) {
|
|
213
|
-
Log.d(TAG, "bindAdListener - Activity is null");
|
|
214
|
-
mIsAdLoading = false;
|
|
215
|
-
onAdError("Activity is null");
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
Log.d(TAG, "bindAdListener - setting up listeners");
|
|
220
|
-
|
|
221
178
|
ad.setExpressInteractionListener(
|
|
222
179
|
new TTNativeExpressAd.ExpressAdInteractionListener() {
|
|
223
180
|
|
|
@@ -233,16 +190,11 @@ public class BannerAdView extends RelativeLayout {
|
|
|
233
190
|
|
|
234
191
|
@Override
|
|
235
192
|
public void onRenderFail(View view, String msg, int code) {
|
|
236
|
-
Log.d(TAG, "onRenderFail - code: " + code + ", msg: " + msg);
|
|
237
|
-
mIsAdLoading = false;
|
|
238
193
|
onAdError("渲染失败: " + msg);
|
|
239
194
|
}
|
|
240
195
|
|
|
241
196
|
@Override
|
|
242
197
|
public void onRenderSuccess(View view, float width, float height) {
|
|
243
|
-
Log.d(TAG, "onRenderSuccess - width: " + width + ", height: " + height);
|
|
244
|
-
mIsAdLoading = false;
|
|
245
|
-
|
|
246
198
|
mExpressContainer.removeAllViews();
|
|
247
199
|
|
|
248
200
|
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
|
|
@@ -272,7 +224,6 @@ public class BannerAdView extends RelativeLayout {
|
|
|
272
224
|
mExpressContainer.requestLayout();
|
|
273
225
|
BannerAdView.this.requestLayout();
|
|
274
226
|
|
|
275
|
-
Log.d(TAG, "onRenderSuccess - view is now visible");
|
|
276
227
|
onAdRenderSuccess((int) width, (int) height);
|
|
277
228
|
}
|
|
278
229
|
}
|
|
@@ -42,7 +42,7 @@ const BannerAdView = props => {
|
|
|
42
42
|
onAdClick,
|
|
43
43
|
onAdShow,
|
|
44
44
|
onAdDislike,
|
|
45
|
-
|
|
45
|
+
visible = true
|
|
46
46
|
} = props;
|
|
47
47
|
|
|
48
48
|
// All hooks must be called at the top level, unconditionally
|
|
@@ -50,17 +50,17 @@ const BannerAdView = props => {
|
|
|
50
50
|
const [height, setHeight] = (0, _react.useState)(adHeight);
|
|
51
51
|
const heightInitialized = (0, _react.useRef)(false);
|
|
52
52
|
|
|
53
|
-
// Reset state when
|
|
53
|
+
// Reset state when visible changes from false to true to allow re-display
|
|
54
54
|
(0, _react.useEffect)(() => {
|
|
55
|
-
if (
|
|
55
|
+
if (visible) {
|
|
56
56
|
setDismissed(false);
|
|
57
57
|
heightInitialized.current = false;
|
|
58
58
|
setHeight(adHeight);
|
|
59
59
|
}
|
|
60
|
-
}, [
|
|
60
|
+
}, [visible, adHeight]);
|
|
61
61
|
|
|
62
62
|
// Early returns after all hooks
|
|
63
|
-
if (_reactNative.Platform.OS !== 'android' || !
|
|
63
|
+
if (_reactNative.Platform.OS !== 'android' || !visible || dismissed) {
|
|
64
64
|
return null;
|
|
65
65
|
}
|
|
66
66
|
const NativeComponent = getBannerAdComponent();
|
|
@@ -71,7 +71,6 @@ const BannerAdView = props => {
|
|
|
71
71
|
codeid: codeid,
|
|
72
72
|
adWidth: adWidth,
|
|
73
73
|
adHeight: height,
|
|
74
|
-
adVisible: adVisible,
|
|
75
74
|
style: {
|
|
76
75
|
width: adWidth,
|
|
77
76
|
height,
|
|
@@ -99,6 +98,6 @@ const BannerAdView = props => {
|
|
|
99
98
|
});
|
|
100
99
|
};
|
|
101
100
|
var _default = exports.default = /*#__PURE__*/_react.default.memo(BannerAdView, (prevProps, nextProps) => {
|
|
102
|
-
return prevProps.codeid === nextProps.codeid && prevProps.
|
|
101
|
+
return prevProps.codeid === nextProps.codeid && prevProps.visible === nextProps.visible && prevProps.adWidth === nextProps.adWidth && prevProps.adHeight === nextProps.adHeight;
|
|
103
102
|
});
|
|
104
103
|
//# sourceMappingURL=BannerAd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ComponentName","Platform","select","android","ios","undefined","LINKING_ERROR","BannerAdNativeComponent","getBannerAdComponent","UIManager","getViewManagerConfig","requireNativeComponent","BannerAdView","props","codeid","style","adWidth","adHeight","onAdRenderSuccess","onAdError","onAdDismiss","onAdClick","onAdShow","onAdDislike","
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ComponentName","Platform","select","android","ios","undefined","LINKING_ERROR","BannerAdNativeComponent","getBannerAdComponent","UIManager","getViewManagerConfig","requireNativeComponent","BannerAdView","props","codeid","style","adWidth","adHeight","onAdRenderSuccess","onAdError","onAdDismiss","onAdClick","onAdShow","onAdDislike","visible","dismissed","setDismissed","useState","height","setHeight","heightInitialized","useRef","useEffect","current","OS","NativeComponent","Error","createElement","width","nativeEvent","newHeight","_default","exports","React","memo","prevProps","nextProps"],"sourceRoot":"../../../../src","sources":["dy/component/BannerAd.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAA2E,SAAAD,wBAAAG,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,C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,CAAC;AAEN,CAAC;AAAC,IAAAE,QAAA,GAAAC,OAAA,CAAAnD,OAAA,gBAEaoD,cAAK,CAACC,IAAI,CAAChC,YAAY,EAAE,CAACiC,SAAS,EAAEC,SAAS,KAAK;EAChE,OACED,SAAS,CAAC/B,MAAM,KAAKgC,SAAS,CAAChC,MAAM,IACrC+B,SAAS,CAACrB,OAAO,KAAKsB,SAAS,CAACtB,OAAO,IACvCqB,SAAS,CAAC7B,OAAO,KAAK8B,SAAS,CAAC9B,OAAO,IACvC6B,SAAS,CAAC5B,QAAQ,KAAK6B,SAAS,CAAC7B,QAAQ;AAE7C,CAAC,CAAC","ignoreList":[]}
|
|
@@ -35,7 +35,7 @@ const BannerAdView = props => {
|
|
|
35
35
|
onAdClick,
|
|
36
36
|
onAdShow,
|
|
37
37
|
onAdDislike,
|
|
38
|
-
|
|
38
|
+
visible = true
|
|
39
39
|
} = props;
|
|
40
40
|
|
|
41
41
|
// All hooks must be called at the top level, unconditionally
|
|
@@ -43,17 +43,17 @@ const BannerAdView = props => {
|
|
|
43
43
|
const [height, setHeight] = useState(adHeight);
|
|
44
44
|
const heightInitialized = useRef(false);
|
|
45
45
|
|
|
46
|
-
// Reset state when
|
|
46
|
+
// Reset state when visible changes from false to true to allow re-display
|
|
47
47
|
useEffect(() => {
|
|
48
|
-
if (
|
|
48
|
+
if (visible) {
|
|
49
49
|
setDismissed(false);
|
|
50
50
|
heightInitialized.current = false;
|
|
51
51
|
setHeight(adHeight);
|
|
52
52
|
}
|
|
53
|
-
}, [
|
|
53
|
+
}, [visible, adHeight]);
|
|
54
54
|
|
|
55
55
|
// Early returns after all hooks
|
|
56
|
-
if (Platform.OS !== 'android' || !
|
|
56
|
+
if (Platform.OS !== 'android' || !visible || dismissed) {
|
|
57
57
|
return null;
|
|
58
58
|
}
|
|
59
59
|
const NativeComponent = getBannerAdComponent();
|
|
@@ -64,7 +64,6 @@ const BannerAdView = props => {
|
|
|
64
64
|
codeid: codeid,
|
|
65
65
|
adWidth: adWidth,
|
|
66
66
|
adHeight: height,
|
|
67
|
-
adVisible: adVisible,
|
|
68
67
|
style: {
|
|
69
68
|
width: adWidth,
|
|
70
69
|
height,
|
|
@@ -92,6 +91,6 @@ const BannerAdView = props => {
|
|
|
92
91
|
});
|
|
93
92
|
};
|
|
94
93
|
export default /*#__PURE__*/React.memo(BannerAdView, (prevProps, nextProps) => {
|
|
95
|
-
return prevProps.codeid === nextProps.codeid && prevProps.
|
|
94
|
+
return prevProps.codeid === nextProps.codeid && prevProps.visible === nextProps.visible && prevProps.adWidth === nextProps.adWidth && prevProps.adHeight === nextProps.adHeight;
|
|
96
95
|
});
|
|
97
96
|
//# sourceMappingURL=BannerAd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useState","useRef","useEffect","Platform","requireNativeComponent","UIManager","ComponentName","select","android","ios","undefined","LINKING_ERROR","default","BannerAdNativeComponent","getBannerAdComponent","getViewManagerConfig","BannerAdView","props","codeid","style","adWidth","adHeight","onAdRenderSuccess","onAdError","onAdDismiss","onAdClick","onAdShow","onAdDislike","
|
|
1
|
+
{"version":3,"names":["React","useState","useRef","useEffect","Platform","requireNativeComponent","UIManager","ComponentName","select","android","ios","undefined","LINKING_ERROR","default","BannerAdNativeComponent","getBannerAdComponent","getViewManagerConfig","BannerAdView","props","codeid","style","adWidth","adHeight","onAdRenderSuccess","onAdError","onAdDismiss","onAdClick","onAdShow","onAdDislike","visible","dismissed","setDismissed","height","setHeight","heightInitialized","current","OS","NativeComponent","Error","createElement","width","e","nativeEvent","newHeight","memo","prevProps","nextProps"],"sourceRoot":"../../../../src","sources":["dy/component/BannerAd.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,EAAEC,SAAS,QAAQ,OAAO;AAC1D,SAASC,QAAQ,EAAEC,sBAAsB,EAAEC,SAAS,QAAQ,cAAc;AAG1E;AACA,MAAMC,aAAa,GAAGH,QAAQ,CAACI,MAAM,CAAC;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AjBA,iBAAiB,CAAGkB,CAAC,CAACC,WAAW,CAAC;IACpC,CAAE;IACFd,WAAW,EAAGa,CAAM,IAAK;MACvBV,YAAY,CAAC,IAAI,CAAC;MAClBH,WAAW,aAAXA,WAAW,eAAXA,WAAW,CAAGa,CAAC,CAACC,WAAW,CAAC;IAC9B;EAAE,CACH,CAAC;AAEN,CAAC;AAED,4BAAe1C,KAAK,CAAC4C,IAAI,CAAC3B,YAAY,EAAE,CAAC4B,SAAS,EAAEC,SAAS,KAAK;EAChE,OACED,SAAS,CAAC1B,MAAM,KAAK2B,SAAS,CAAC3B,MAAM,IACrC0B,SAAS,CAAChB,OAAO,KAAKiB,SAAS,CAACjB,OAAO,IACvCgB,SAAS,CAACxB,OAAO,KAAKyB,SAAS,CAACzB,OAAO,IACvCwB,SAAS,CAACvB,QAAQ,KAAKwB,SAAS,CAACxB,QAAQ;AAE7C,CAAC,CAAC","ignoreList":[]}
|
|
@@ -11,7 +11,7 @@ export interface BannerAdProps {
|
|
|
11
11
|
style?: ViewStyle;
|
|
12
12
|
adWidth?: number;
|
|
13
13
|
adHeight?: number;
|
|
14
|
-
|
|
14
|
+
visible?: boolean;
|
|
15
15
|
onAdRenderSuccess?: (event: BannerAdEvent) => void;
|
|
16
16
|
onAdError?: (event: BannerAdEvent) => void;
|
|
17
17
|
onAdDismiss?: (event: BannerAdEvent) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BannerAd.d.ts","sourceRoot":"","sources":["../../../../../src/dy/component/BannerAd.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQ9C,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,
|
|
1
|
+
{"version":3,"file":"BannerAd.d.ts","sourceRoot":"","sources":["../../../../../src/dy/component/BannerAd.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAsC,MAAM,OAAO,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAQ9C,MAAM,WAAW,aAAa;IAC5B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,iBAAiB,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IACnD,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC3C,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7C,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC3C,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;CAC9C;0DA4B4B,aAAa;AAqE1C,wBAOG"}
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ export interface BannerAdProps {
|
|
|
20
20
|
style?: ViewStyle;
|
|
21
21
|
adWidth?: number;
|
|
22
22
|
adHeight?: number;
|
|
23
|
-
|
|
23
|
+
visible?: boolean;
|
|
24
24
|
onAdRenderSuccess?: (event: BannerAdEvent) => void;
|
|
25
25
|
onAdError?: (event: BannerAdEvent) => void;
|
|
26
26
|
onAdDismiss?: (event: BannerAdEvent) => void;
|
|
@@ -67,7 +67,7 @@ const BannerAdView = (props: BannerAdProps) => {
|
|
|
67
67
|
onAdClick,
|
|
68
68
|
onAdShow,
|
|
69
69
|
onAdDislike,
|
|
70
|
-
|
|
70
|
+
visible = true,
|
|
71
71
|
} = props;
|
|
72
72
|
|
|
73
73
|
// All hooks must be called at the top level, unconditionally
|
|
@@ -75,17 +75,17 @@ const BannerAdView = (props: BannerAdProps) => {
|
|
|
75
75
|
const [height, setHeight] = useState(adHeight);
|
|
76
76
|
const heightInitialized = useRef(false);
|
|
77
77
|
|
|
78
|
-
// Reset state when
|
|
78
|
+
// Reset state when visible changes from false to true to allow re-display
|
|
79
79
|
useEffect(() => {
|
|
80
|
-
if (
|
|
80
|
+
if (visible) {
|
|
81
81
|
setDismissed(false);
|
|
82
82
|
heightInitialized.current = false;
|
|
83
83
|
setHeight(adHeight);
|
|
84
84
|
}
|
|
85
|
-
}, [
|
|
85
|
+
}, [visible, adHeight]);
|
|
86
86
|
|
|
87
87
|
// Early returns after all hooks
|
|
88
|
-
if (Platform.OS !== 'android' || !
|
|
88
|
+
if (Platform.OS !== 'android' || !visible || dismissed) {
|
|
89
89
|
return null;
|
|
90
90
|
}
|
|
91
91
|
|
|
@@ -100,7 +100,6 @@ const BannerAdView = (props: BannerAdProps) => {
|
|
|
100
100
|
codeid={codeid}
|
|
101
101
|
adWidth={adWidth}
|
|
102
102
|
adHeight={height}
|
|
103
|
-
adVisible={adVisible}
|
|
104
103
|
style={{ width: adWidth, height, ...style }}
|
|
105
104
|
onAdError={(e: any) => onAdError?.(e.nativeEvent)}
|
|
106
105
|
onAdClick={(e: any) => onAdClick?.(e.nativeEvent)}
|
|
@@ -128,7 +127,7 @@ const BannerAdView = (props: BannerAdProps) => {
|
|
|
128
127
|
export default React.memo(BannerAdView, (prevProps, nextProps) => {
|
|
129
128
|
return (
|
|
130
129
|
prevProps.codeid === nextProps.codeid &&
|
|
131
|
-
prevProps.
|
|
130
|
+
prevProps.visible === nextProps.visible &&
|
|
132
131
|
prevProps.adWidth === nextProps.adWidth &&
|
|
133
132
|
prevProps.adHeight === nextProps.adHeight
|
|
134
133
|
);
|