Skip to content

Commit

Permalink
feat/add_support_for_bigoads_native_ads (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
alhiwatan authored Oct 23, 2024
1 parent 263dd11 commit 91542f2
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
2 changes: 2 additions & 0 deletions applovin_max/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Versions

## x.x.x
* Update IconView to support native ad icon image view, primarily for BigoAds native ads.
## 4.0.1
* Crash if plugin version is incompatible with native SDK version.
* Add support for Yandex native ads.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,10 @@ private void addTitleView(final MethodCall call, final MaxAd ad)
if ( titleView == null )
{
titleView = new FrameLayout( context );
titleView.setTag( TITLE_LABEL_TAG );
nativeAdView.addView( titleView );
}

titleView.setTag( TITLE_LABEL_TAG );
clickableViews.add( titleView );

updateViewLayout( nativeAdView, titleView, getRect( call ) );
Expand All @@ -329,10 +329,10 @@ private void addAdvertiserView(final MethodCall call, final MaxAd ad)
if ( advertiserView == null )
{
advertiserView = new FrameLayout( context );
advertiserView.setTag( ADVERTISER_VIEW_TAG );
nativeAdView.addView( advertiserView );
}

advertiserView.setTag( ADVERTISER_VIEW_TAG );
clickableViews.add( advertiserView );

updateViewLayout( nativeAdView, advertiserView, getRect( call ) );
Expand All @@ -347,10 +347,10 @@ private void addBodyView(final MethodCall call, final MaxAd ad)
if ( bodyView == null )
{
bodyView = new FrameLayout( context );
bodyView.setTag( BODY_VIEW_TAG );
nativeAdView.addView( bodyView );
}

bodyView.setTag( BODY_VIEW_TAG );
clickableViews.add( bodyView );

updateViewLayout( nativeAdView, bodyView, getRect( call ) );
Expand All @@ -365,10 +365,10 @@ private void addCallToActionView(final MethodCall call, final MaxAd ad)
if ( callToActionView == null )
{
callToActionView = new FrameLayout( context );
callToActionView.setTag( CALL_TO_ACTION_VIEW_TAG );
nativeAdView.addView( callToActionView );
}

callToActionView.setTag( CALL_TO_ACTION_VIEW_TAG );
clickableViews.add( callToActionView );

updateViewLayout( nativeAdView, callToActionView, getRect( call ) );
Expand All @@ -379,8 +379,9 @@ private void addIconView(final MethodCall call, final MaxAd ad)
if ( ad == null ) return;

MaxNativeAd.MaxNativeAdImage icon = ad.getNativeAd().getIcon();
ImageView iconImageView = (ImageView) ad.getNativeAd().getIconView();

if ( icon == null )
if ( icon == null && iconImageView == null )
{
if ( iconView != null )
{
Expand All @@ -393,21 +394,28 @@ private void addIconView(final MethodCall call, final MaxAd ad)
if ( iconView == null )
{
iconView = new ImageView( context );
iconView.setTag( ICON_VIEW_TAG );
nativeAdView.addView( iconView );
}

iconView.setTag( ICON_VIEW_TAG );
clickableViews.add( iconView );

updateViewLayout( nativeAdView, iconView, getRect( call ) );

if ( icon.getUri() != null )
if ( icon != null )
{
AppLovinSdkUtils.setImageUrl( icon.getUri().toString(), iconView, sdk );
if ( icon.getUri() != null )
{
AppLovinSdkUtils.setImageUrl( icon.getUri().toString(), iconView, sdk );
}
else if ( icon.getDrawable() != null )
{
iconView.setImageDrawable( icon.getDrawable() );
}
}
else if ( icon.getDrawable() != null )
else if ( iconImageView != null )
{
iconView.setImageDrawable( icon.getDrawable() );
iconView.setImageDrawable( iconImageView.getDrawable() );
}
}

Expand Down Expand Up @@ -447,10 +455,12 @@ private void addMediaView(final MethodCall call, final MaxAd ad)
mediaViewContainer = new RelativeLayout( context );
// Sets an identifier for the Google adapters to verify the view in the tree
mediaViewContainer.setId( MEDIA_VIEW_CONTAINER_TAG );
mediaViewContainer.setTag( MEDIA_VIEW_CONTAINER_TAG );
nativeAdView.addView( mediaViewContainer );
}

mediaViewContainer.setTag( MEDIA_VIEW_CONTAINER_TAG );
clickableViews.add( mediaViewContainer );

Rect rect = getRect( call );

if ( mediaView.getParent() == null )
Expand Down Expand Up @@ -533,7 +543,7 @@ private void sendAdLoadedReactNativeEventForAd(final MaxNativeAd ad)
nativeAdInfo.put( "mediaContentAspectRatio", ad.getMediaContentAspectRatio() );
}

nativeAdInfo.put( "isIconImageAvailable", ( ad.getIcon() != null ) );
nativeAdInfo.put( "isIconImageAvailable", ( ad.getIcon() != null || ad.getIconView() != null ) );
nativeAdInfo.put( "isOptionsViewAvailable", ( ad.getOptionsView() != null ) );
nativeAdInfo.put( "isMediaViewAvailable", ( ad.getMediaView() != null ) );

Expand Down
24 changes: 18 additions & 6 deletions applovin_max/ios/Classes/AppLovinMAXNativeAdView.m
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,9 @@ - (void)addCallToActionViewForCall:(FlutterMethodCall *)call
- (void)addIconViewForCall:(FlutterMethodCall *)call
{
MANativeAdImage *icon = self.nativeAd.nativeAd.icon;
if ( !icon )
UIView *iconImageView = self.nativeAd.nativeAd.iconView;

if ( !icon && !iconImageView )
{
self.iconView.image = nil;
return;
Expand All @@ -351,13 +353,21 @@ - (void)addIconViewForCall:(FlutterMethodCall *)call

self.iconView.frame = [self frameForCall: call];

if ( icon.URL )
if ( icon )
{
[self.iconView al_setImageWithURL: icon.URL];
if ( icon.URL )
{
[self.iconView al_setImageWithURL: icon.URL];
}
else if ( icon.image )
{
self.iconView.image = icon.image;
}
}
else if ( icon.image )
else if ( iconImageView )
{
self.iconView.image = icon.image;
[self.iconView addSubview: iconImageView];
[iconImageView al_pinToSuperview];
}
}

Expand Down Expand Up @@ -393,6 +403,8 @@ - (void)addMediaViewForCall:(FlutterMethodCall *)call
[self.nativeAdView addSubview: self.mediaViewContainer];
}

[self.clickableViews addObject: self.mediaViewContainer];

if ( !mediaView.superview )
{
[self.mediaViewContainer addSubview: mediaView];
Expand Down Expand Up @@ -460,7 +472,7 @@ - (void)sendAdLoadedReactNativeEventForAd:(MANativeAd *)ad
nativeAdInfo[@"mediaContentAspectRatio"] = @(ad.mediaContentAspectRatio);
}

nativeAdInfo[@"isIconImageAvailable"] = (ad.icon != nil) ? @YES : @NO;
nativeAdInfo[@"isIconImageAvailable"] = (ad.icon != nil || ad.iconView) ? @YES : @NO;
nativeAdInfo[@"isOptionsViewAvailable"] = (ad.optionsView != nil) ? @YES : @NO;
nativeAdInfo[@"isMediaViewAvailable"] = (ad.mediaView != nil) ? @YES : @NO;

Expand Down

0 comments on commit 91542f2

Please sign in to comment.