Skip to content

Commit

Permalink
fix: banners not properly destroyed
Browse files Browse the repository at this point in the history
  • Loading branch information
dylancom committed Dec 28, 2023
1 parent bfec491 commit bf0ebd2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,20 @@ public void onAfterUpdateTransaction(@NonNull ReactNativeAdView reactViewGroup)
reactViewGroup.setPropsChanged(false);
}

@Override
public void onDropViewInstance(@NonNull ReactNativeAdView reactViewGroup) {
BaseAdView adView = getAdView(reactViewGroup);
if (adView != null) {
adView.setAdListener(null);
if (adView instanceof AdManagerAdView) {
((AdManagerAdView) adView).setAppEventListener(null);
}
adView.destroy();
reactViewGroup.removeView(adView);
}
super.onDropViewInstance(reactViewGroup);
}

private BaseAdView initAdView(ReactNativeAdView reactViewGroup) {
BaseAdView oldAdView = getAdView(reactViewGroup);
if (oldAdView != null) {
Expand Down
7 changes: 7 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@

@implementation RNGoogleMobileAdsBannerComponent

- (void)dealloc {
if (_banner) {
[_banner removeFromSuperview];
_banner = nil;
}
}

- (void)didSetProps:(NSArray<NSString *> *)changedProps {
if (_propsChanged) {
[self requestAd];
Expand Down
7 changes: 7 additions & 0 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsBannerView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
[super updateProps:props oldProps:oldProps];
}

- (void)dealloc {
if (_banner) {
[_banner removeFromSuperview];
_banner = nil;
}
}

#pragma mark - Methods

- (void)initBanner:(GADAdSize)adSize {
Expand Down

0 comments on commit bf0ebd2

Please sign in to comment.