Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: banners not properly destroyed #508

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading