[英]Google IMA webview is not showing when used inside react native on android
簡而言之:我們使用Android上的reacte本機,並使用本機VideoView通過適用於Android的Google IMA SDK來顯示帶有廣告的視頻。 視頻播放,廣告播放,但是包含“閱讀更多”和“跳過廣告”的Web視圖不可見。 它已添加到視圖層次結構中,但是大小為0,0,並且沒有子級。 當我在本機應用程序中使用完全相同的代碼時。 一切正常。
更多背景信息:
來自React Native組件的相關代碼:
@SuppressLint("ViewConstructor")
public class ReactVideoViewWithAds extends FrameLayout implements
LifecycleEventListener {
private VideoPlayerWithAdPlayback mVideoPlayerWithAdPlayback;
private RelativeLayout mCompanionAdSlot;
private VideoPlayerController mVideoPlayerController;
public ReactVideoViewWithAds(ThemedReactContext themedReactContext) {
super(themedReactContext);
createViews();
themedReactContext.addLifecycleEventListener(this);
}
private void createViews() {
FrameLayout.LayoutParams companionAdLayoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
(int) (50 * getResources().getSystem().getDisplayMetrics().density));
companionAdLayoutParams.gravity = Gravity.CENTER_HORIZONTAL;
mCompanionAdSlot = new RelativeLayout(getContext());
mCompanionAdSlot.setBackgroundColor(Color.BLUE);
addView(mCompanionAdSlot, companionAdLayoutParams);
//player with ad playback
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT);
mVideoPlayerWithAdPlayback = new VideoPlayerWithAdPlayback(getContext());
addView(mVideoPlayerWithAdPlayback, layoutParams);
initPlayer();
}
private void initPlayer() {
mVideoPlayerController = new VideoPlayerController(
getContext(),
mVideoPlayerWithAdPlayback,
null,
null,
"nl",
mCompanionAdSlot,
null);
}
在本機組件中動態添加視圖時,您似乎需要手動觸發布局周期,以便react-native能夠獲取更改。 (可能與本機更新的影子視圖有關)
@Override
public void requestLayout() {
super.requestLayout();
post(measureAndLayout);
}
private final Runnable measureAndLayout = new Runnable() {
@Override
public void run() {
measure(
MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY),
MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY));
layout(getLeft(), getTop(), getRight(), getBottom());
}
};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.