sbugert / react-native-admob

A react-native component for Google AdMob banners
BSD 2-Clause "Simplified" License
1.13k stars 530 forks source link

Ads refreshing when keyboard shows / dismisses #141

Open LandDragoon opened 7 years ago

LandDragoon commented 7 years ago

Whenever I click on a textInput and my keyboard shows up, the ad inside my bottom banner is refreshed. The same thing happens when the keyboard is dismissed. This started to happen after upgrading to RN @ 0.44. I'm using react-native-admod @ 1.3.0.

It seems that onSizeChange is called every time the keyboard shows up, even though there was no change in size. So I changed that function to only set the state variables when there was a difference, but this does not solve the issue as the component itself is still refreshed.

Any idea why this is happening and how it can be solved?

LandDragoon commented 7 years ago

It seems to be fixed when I change the following piece of code in RNAdMobBannerViewManager.java

if (left != oldLeft || right != oldRight || top != oldTop || bottom != oldBottom) {
    setBannerSize(mView, mSizeString);
}

to

if (left != oldLeft || right != oldRight) {
    setBannerSize(mView, mSizeString);
}

@sbugert Any reason why the top and bottom offset were also checked for changes? When the keyboard pop up my banner is pushed up, which is then seen as layout change and a new ad was (unnecessarily) loaded because of it.

koenpunt commented 7 years ago

Maybe @maraujop can elaborate on that, since he introduced that in https://github.com/sbugert/react-native-admob/pull/56

However, this check is no longer present in the 2.0.0 alpha version.

I would love to get some feedback on the changes I introduced in that version, so if you could give that a try, that would be great!

https://github.com/sbugert/react-native-admob/releases/tag/v2.0.0-alpha.4