@@ -791,6 +791,9 @@ firebase.init = arg => {
791791 } ) ;
792792} ;
793793
794+ // helps global app behavior (ie: orientation handling)
795+ firebase . admob . bannerOptions = null ;
796+
794797firebase . admob . showBanner = arg => {
795798 return new Promise ( ( resolve , reject ) => {
796799 try {
@@ -806,6 +809,7 @@ firebase.admob.showBanner = arg => {
806809
807810 firebase . admob . defaults . view = iOSUtils . getter ( UIApplication , UIApplication . sharedApplication ) . keyWindow . rootViewController . view ;
808811 const settings = firebase . merge ( arg , firebase . admob . defaults ) ;
812+ firebase . admob . bannerOptions = settings ;
809813 const view = settings . view ;
810814 const bannerType = firebase . admob . _getBannerType ( settings . size ) ;
811815
@@ -848,14 +852,10 @@ firebase.admob.showBanner = arg => {
848852
849853 view . addSubview ( firebase . admob . adView ) ;
850854
851- // support rotation events (TODO we don't want to add multiple handlers, also: remove with .off!).. could also just have the app handle this
852- application . on ( application . orientationChangedEvent , data => {
853- if ( firebase . admob . adView !== null ) {
854- firebase . admob . hideBanner ( ) . then ( res => {
855- firebase . admob . createBanner ( arg ) ;
856- } ) ;
857- }
858- } ) ;
855+ // support rotation events
856+ // tear down first if this had been called already to avoid multiple event bindings
857+ application . off ( application . orientationChangedEvent , firebase . admob . orientationHandler ) ;
858+ application . on ( application . orientationChangedEvent , firebase . admob . orientationHandler ) ;
859859
860860 resolve ( ) ;
861861 } catch ( ex ) {
@@ -865,6 +865,20 @@ firebase.admob.showBanner = arg => {
865865 } ) ;
866866} ;
867867
868+ firebase . admob . orientationHandler = data => {
869+ if ( firebase . admob . adView !== null ) {
870+ firebase . admob . hideBanner ( ) . then ( res => {
871+ try {
872+ firebase . admob . showBanner ( firebase . admob . bannerOptions || firebase . admob . defaults ) ;
873+ } catch ( err ) {
874+ console . log ( "Error in orientationHandler - firebase.admob.showBanner: " + err ) ;
875+ }
876+ } , err => {
877+ console . log ( "Error in orientationHandler - firebase.admob.hideBanner: " + err ) ;
878+ } ) ;
879+ }
880+ } ;
881+
868882firebase . admob . showInterstitial = arg => {
869883 return new Promise ( ( resolve , reject ) => {
870884 try {
0 commit comments