@24jieqi/react-native-brayant-ad 0.1.9 → 0.1.11

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.
@@ -40,27 +40,31 @@ public class BannerAdView extends RelativeLayout {
40
40
  super(context);
41
41
  mContext = context.getCurrentActivity();
42
42
  reactContext = context;
43
- // 开始展开
43
+ Log.d(TAG, "[DEBUG] BannerAdView constructor - inflating feed_view.xml");
44
44
  inflate(context, R.layout.feed_view, this);
45
-
46
- // 这个函数很关键,不然不能触发再次渲染,让 view 在 RN 里渲染成功!!
47
45
  Utils.setupLayoutHack(this);
46
+
47
+ setLayoutParams(new RelativeLayout.LayoutParams(
48
+ RelativeLayout.LayoutParams.MATCH_PARENT,
49
+ RelativeLayout.LayoutParams.WRAP_CONTENT
50
+ ));
51
+ Log.d(TAG, "[DEBUG] BannerAdView constructor completed - LayoutParams set");
48
52
  }
49
53
 
50
54
  public void setWidth(int width) {
51
- Log.d(TAG, "setCodeId = " + _codeid + ", setWidth:" + width);
55
+ Log.d(TAG, "[DEBUG] setWidth called - codeid=" + _codeid + ", width=" + width + ", current height=" + _expectedHeight);
52
56
  _expectedWidth = width;
53
57
  showAd();
54
58
  }
55
59
 
56
60
  public void setHeight(int height) {
57
- Log.d(TAG, "setCodeId = " + _codeid + ", setHeight:" + height);
61
+ Log.d(TAG, "[DEBUG] setHeight called - codeid=" + _codeid + ", height=" + height + ", current width=" + _expectedWidth);
58
62
  _expectedHeight = height;
59
63
  showAd();
60
64
  }
61
65
 
62
66
  public void setCodeId(String codeId) {
63
- Log.d(TAG, "setCodeId: " + codeId + ", _expectedWidth:" + _expectedWidth);
67
+ Log.d(TAG, "[DEBUG] setCodeId called - codeid=" + codeId + ", _expectedWidth=" + _expectedWidth + ", _expectedHeight=" + _expectedHeight);
64
68
  _codeid = codeId;
65
69
  showAd();
66
70
  }
@@ -70,7 +74,7 @@ public class BannerAdView extends RelativeLayout {
70
74
  * @param visible true: 可见,false: 不可见
71
75
  */
72
76
  public void setVisibility(boolean visible) {
73
- Log.d(TAG, "setVisibility: " + visible);
77
+ Log.d(TAG, "[DEBUG] setVisibility called - visible=" + visible + ", current codeid=" + _codeid + ", SDK initialized=" + (DyADCore.TTAdSdk != null));
74
78
  if (visible) {
75
79
  super.setVisibility(View.VISIBLE);
76
80
  // 可见时尝试加载广告
@@ -81,10 +85,11 @@ public class BannerAdView extends RelativeLayout {
81
85
  }
82
86
 
83
87
  public void showAd() {
84
- Log.d(TAG, "showAd: width:" + _expectedWidth + " height:" + _expectedHeight + " codeid:" + _codeid);
88
+ Log.d(TAG, "[DEBUG] showAd called - width=" + _expectedWidth + ", height=" + _expectedHeight + ", codeid=" + _codeid + ", SDK initialized=" + (DyADCore.TTAdSdk != null));
85
89
 
86
90
  // 显示广告
87
91
  if (_expectedWidth <= 0 || _expectedHeight <= 0 || _codeid.isEmpty()) {
92
+ Log.w(TAG, "[DEBUG] showAd aborted - width=" + _expectedWidth + " (must >0), height=" + _expectedHeight + " (must >0), codeid=" + _codeid + " (must not be empty)");
88
93
  // 广告宽高未设置或 code id 未设置,停止显示广告
89
94
  return;
90
95
  }
@@ -92,6 +97,7 @@ public class BannerAdView extends RelativeLayout {
92
97
  // 在UI线程加载广告
93
98
  runOnUiThread(
94
99
  () -> {
100
+ Log.d(TAG, "[DEBUG] showAd - calling loadBannerAd on UI thread");
95
101
  loadBannerAd();
96
102
  }
97
103
  );
@@ -99,13 +105,16 @@ public class BannerAdView extends RelativeLayout {
99
105
 
100
106
  // 显示Banner广告
101
107
  public void loadBannerAd() {
108
+ Log.d(TAG, "[DEBUG] loadBannerAd called - SDK initialized=" + (DyADCore.TTAdSdk != null) + ", codeid=" + _codeid);
109
+
102
110
  if (DyADCore.TTAdSdk == null) {
103
- Log.e(TAG, "TTAdSdk 还没初始化");
111
+ Log.e(TAG, "[DEBUG] loadBannerAd aborted - TTAdSdk not initialized yet");
104
112
  return;
105
113
  }
106
114
 
107
115
  // 如果已有广告,先销毁
108
116
  if (mBannerAd != null) {
117
+ Log.d(TAG, "[DEBUG] loadBannerAd - destroying previous ad");
109
118
  mBannerAd.destroy();
110
119
  }
111
120
 
@@ -118,6 +127,8 @@ public class BannerAdView extends RelativeLayout {
118
127
  .setExpressViewAcceptedSize(_expectedWidth, _expectedHeight) // 期望模板广告view的size,单位dp
119
128
  .build();
120
129
 
130
+ Log.d(TAG, "[DEBUG] loadBannerAd - requesting ad with AdSlot: codeid=" + _codeid + ", width=" + _expectedWidth + ", height=" + _expectedHeight);
131
+
121
132
  // 请求广告
122
133
  final BannerAdView _this = this;
123
134
  DyADCore.TTAdSdk.loadBannerExpressAd(
@@ -126,6 +137,7 @@ public class BannerAdView extends RelativeLayout {
126
137
 
127
138
  @Override
128
139
  public void onError(int code, String message) {
140
+ Log.e(TAG, "[DEBUG] onError - code=" + code + ", message=" + message);
129
141
  message =
130
142
  "Banner ad error: " + code + ", " + message;
131
143
  Log.e(TAG, message);
@@ -134,13 +146,15 @@ public class BannerAdView extends RelativeLayout {
134
146
 
135
147
  @Override
136
148
  public void onNativeExpressAdLoad(java.util.List<TTNativeExpressAd> ads) {
137
- Log.d(TAG, "onNativeExpressAdLoad: Banner ad loaded!");
149
+ Log.d(TAG, "[DEBUG] onNativeExpressAdLoad - ads received=" + (ads != null ? ads.size() : "null"));
138
150
  if (ads == null || ads.isEmpty()) {
151
+ Log.e(TAG, "[DEBUG] onNativeExpressAdLoad - ads is null or empty");
139
152
  onAdError("Banner ad loaded but no content");
140
153
  return;
141
154
  }
142
155
 
143
156
  mBannerAd = ads.get(0);
157
+ Log.d(TAG, "[DEBUG] onNativeExpressAdLoad - calling _showBannerAd");
144
158
  _showBannerAd(mBannerAd);
145
159
  }
146
160
  }
@@ -183,13 +197,38 @@ public class BannerAdView extends RelativeLayout {
183
197
 
184
198
  @Override
185
199
  public void onRenderSuccess(View view, float width, float height) {
186
- Log.d(TAG, "Banner onRenderSuccess: " + width + ", " + height);
187
- // 在渲染成功回调时展示广告
200
+ Log.d(TAG, "[DEBUG] onRenderSuccess - adView width=" + width + ", adView height=" + height);
201
+
188
202
  RelativeLayout mExpressContainer = findViewById(R.id.feed_container);
189
- if (mExpressContainer != null) {
190
- mExpressContainer.removeAllViews();
191
- mExpressContainer.addView(view);
203
+
204
+ if (mExpressContainer == null) {
205
+ Log.e(TAG, "[DEBUG] onRenderSuccess - feed_container is null!");
206
+ onAdError("feed_container not found");
207
+ return;
192
208
  }
209
+
210
+ Log.d(TAG, "[DEBUG] onRenderSuccess - feed_container found, removing old views");
211
+ mExpressContainer.removeAllViews();
212
+
213
+ RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
214
+ RelativeLayout.LayoutParams.MATCH_PARENT,
215
+ RelativeLayout.LayoutParams.WRAP_CONTENT
216
+ );
217
+ mExpressContainer.addView(view, params);
218
+
219
+ Log.d(TAG, "[DEBUG] onRenderSuccess - adView added to feed_container");
220
+ Log.d(TAG, "[DEBUG] onRenderSuccess - BannerAdView size: width=" + BannerAdView.this.getWidth() + ", height=" + BannerAdView.this.getHeight());
221
+ Log.d(TAG, "[DEBUG] onRenderSuccess - feed_container size: width=" + mExpressContainer.getWidth() + ", height=" + mExpressContainer.getHeight());
222
+
223
+ view.setVisibility(View.VISIBLE);
224
+ mExpressContainer.setVisibility(View.VISIBLE);
225
+ BannerAdView.this.setVisibility(View.VISIBLE);
226
+
227
+ mExpressContainer.requestLayout();
228
+ BannerAdView.this.requestLayout();
229
+
230
+ Log.d(TAG, "[DEBUG] onRenderSuccess - layout requested, sending onAdRenderSuccess event");
231
+
193
232
  onAdRenderSuccess((int) width, (int) height);
194
233
  }
195
234
  }
@@ -2,8 +2,8 @@
2
2
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
3
  android:id="@+id/feed_container"
4
4
  android:layout_width="match_parent"
5
- android:layout_height="wrap_content"
6
- android:background="@drawable/shape_corner"
5
+ android:layout_height="280dp"
6
+ android:background="#FFFFFF"
7
7
  android:orientation="vertical"
8
8
  android:layout_gravity="center"
9
9
  >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@24jieqi/react-native-brayant-ad",
3
- "version": "0.1.9",
3
+ "version": "0.1.11",
4
4
  "description": "国内广告联盟sdk封装",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",