diff --git a/Google/CHANGELOG.md b/Google/CHANGELOG.md index ee7a74d8f7..e0694a6722 100644 --- a/Google/CHANGELOG.md +++ b/Google/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 23.6.0.1 +* Fixed native ads to no longer require the media view in external plugins to be clickable. + ## 23.6.0.0 * Certified with Google SDK 23.6.0. diff --git a/Google/build.gradle.kts b/Google/build.gradle.kts index 1959cc01f3..552893e6a3 100644 --- a/Google/build.gradle.kts +++ b/Google/build.gradle.kts @@ -6,6 +6,6 @@ afterEvaluate { apply(plugin = "adapter-publish") } -val libraryVersionName by extra("23.6.0.0") +val libraryVersionName by extra("23.6.0.1") android.defaultConfig.minSdk = 21 diff --git a/Google/src/main/java/com/applovin/mediation/adapters/GoogleMediationAdapter.java b/Google/src/main/java/com/applovin/mediation/adapters/GoogleMediationAdapter.java index 467d83c508..4a3f4ca52f 100644 --- a/Google/src/main/java/com/applovin/mediation/adapters/GoogleMediationAdapter.java +++ b/Google/src/main/java/com/applovin/mediation/adapters/GoogleMediationAdapter.java @@ -1605,6 +1605,8 @@ else if ( mediaView instanceof ImageView ) // Plugins else { + View mediaView = null; + for ( View view : clickableViews ) { Object viewTag = view.getTag(); @@ -1632,60 +1634,71 @@ else if ( tag == ADVERTISER_VIEW_TAG ) { nativeAdView.setAdvertiserView( view ); } + else if ( tag == MEDIA_VIEW_CONTAINER_TAG ) + { + mediaView = getMediaView(); + } } // // Logic required for proper media view rendering in plugins (e.g. Flutter / React Native) // - View mediaView = getMediaView(); - if ( mediaView == null ) return true; - - ViewGroup pluginContainer = (ViewGroup) mediaView.getParent(); + ViewGroup pluginContainer = ( mediaView != null ) ? (ViewGroup) mediaView.getParent() : container; if ( pluginContainer == null ) return true; - // Re-parent mediaView - mediaView must be a child of nativeAdView for Google native ads - - // 1. Remove mediaView from the plugin - pluginContainer.removeView( mediaView ); - // NOTE: Will be false for React Native (will extend `ReactViewGroup`), but true for Flutter boolean hasPluginLayout = ( pluginContainer instanceof RelativeLayout || pluginContainer instanceof FrameLayout ); - if ( !hasPluginLayout ) + + // Handle re-parenting of mediaView for enabling clicks on other asset views + if ( mediaView != null ) { - if ( mediaView instanceof MediaView ) + // Remove mediaView from the plugin container + pluginContainer.removeView( mediaView ); + + // Special handling for Google MediaView on React Native + if ( !hasPluginLayout && mediaView instanceof MediaView ) { MediaView googleMediaView = (MediaView) mediaView; MediaContent googleMediaContent = googleMediaView.getMediaContent(); if ( googleMediaContent != null && googleMediaContent.hasVideoContent() ) { - mediaView = new AutoMeasuringMediaView( container.getContext() ); + mediaView = new AutoMeasuringMediaView( pluginContainer.getContext() ); googleMediaView.setMediaContent( nativeAd.getMediaContent() ); } } - } - // 2. Add mediaView to nativeAdView - ViewGroup.LayoutParams mediaViewLayout = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ); - nativeAdView.addView( mediaView, mediaViewLayout ); + // Add mediaView to the NativeAdView + ViewGroup.LayoutParams mediaViewLayout = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ); + nativeAdView.addView( mediaView, mediaViewLayout ); - // Set mediaView or imageView based on the instance type - if ( mediaView instanceof MediaView ) - { - nativeAdView.setMediaView( (MediaView) mediaView ); + // Set mediaView or imageView based on the instance type + if ( mediaView instanceof MediaView ) + { + nativeAdView.setMediaView( (MediaView) mediaView ); + } + else if ( mediaView instanceof ImageView ) + { + nativeAdView.setImageView( (ImageView) mediaView ); + } } - else if ( mediaView instanceof ImageView ) + // Insert a placeholder view for enabling clicks on other asset views + else { - nativeAdView.setImageView( (ImageView) mediaView ); + ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ); + View view = new View( pluginContainer.getContext() ); + + nativeAdView.addView( view, layoutParams ); + nativeAdView.setStoreView( view ); } nativeAdView.setNativeAd( nativeAd ); - // 3. Add nativeAdView to the plugin - ViewGroup.LayoutParams nativeAdViewLayout = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ); + // Add the NativeAdView back to the plugin container if ( hasPluginLayout ) { + ViewGroup.LayoutParams nativeAdViewLayout = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT ); pluginContainer.addView( nativeAdView, nativeAdViewLayout ); } else