marcojak / TestMTAdmob

Test project for the MTAdmob plugin
http://www.xamarinexpert.it
11 stars 2 forks source link

Toggling BannerAd Visibility sets Banner Ad Height to 1 #7

Open killer-frog opened 4 years ago

killer-frog commented 4 years ago

In my App, a user can take out a Pro subscription then choose to turn off adverts.

I have a banner add on my page:

<controls:MTAdView  PersonalizedAds="true" x:Name="AdView" Visual="None" 
                    PropertyChanged="AdView_OnPropertyChanged" 
                    IsVisible="{Binding ShowAdverts}"  />

When the IsVisiable property is bound to a property the height of the banner ad is set to one and never changes when an ad is loaded.

As a work around I have had to add the following code:


        private void AdView_OnPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Debug.WriteLine($"Property Changed {e.PropertyName}");

            if (e.PropertyName == nameof(IsVisible) && sender is MTAdView adview)
            {
                if (adview.IsVisible && adview.Height < 5)
                {
                    adview.HeightRequest = 50;
                }
            }
        }

This happened when testing on iOS (both device and Simulator)

Using