Skip to content

Commit

Permalink
Fullscreen close button (#663)
Browse files Browse the repository at this point in the history
* Hide status bar when showing full screen ad on iOS. Fix for #191
  • Loading branch information
jjliu15 authored Oct 11, 2022
1 parent ef8df97 commit 7e00b0d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/google_mobile_ads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
cd packages/google_mobile_ads/ios
pod lib lint --allow-warnings
env:
DEVELOPER_DIR: /Applications/Xcode_13.4.1.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.0.1.app/Contents/Developer

flutter:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/scripts/build-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ fi

if [ "$ACTION" == "ios" ]
then
flutter pub get;
pod repo update;
melos exec -c 1 --scope="$GOOGLEMOBILEADS_PLUGIN_SCOPE_EXAMPLE" -- \
flutter build ios --no-codesign --simulator --debug --target="$TARGET_FILE" --dart-define=CI=true
exit
Expand Down
1 change: 1 addition & 0 deletions packages/google_mobile_ads/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* adSourceInstanceId
* adSourceInstanceName
* adSourceName
* Fixes [close button issue on iOS](https://github.com/googleads/googleads-mobile-flutter/issues/191)
## 2.0.1
* Bug fix for [issue 580](https://github.com/googleads/googleads-mobile-flutter/issues/580).
Adds a workaround on Android to wait for the ad widget to become visible
Expand Down
17 changes: 16 additions & 1 deletion packages/google_mobile_ads/ios/Classes/FLTAd_Internal.m
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,9 @@ - (void)adView:(nonnull GADBannerView *)banner

#pragma mark - FLTFullScreenAd

@implementation FLTFullScreenAd
@implementation FLTFullScreenAd {
BOOL _statusBarVisibilityBeforeAdShow;
}

@synthesize manager;

Expand All @@ -616,6 +618,14 @@ - (void)ad:(nonnull id<GADFullScreenPresentingAd>)ad

- (void)adWillPresentFullScreenContent:
(nonnull id<GADFullScreenPresentingAd>)ad {
// Manually hide the status bar. This is a fix for
// https://github.com/googleads/googleads-mobile-flutter/issues/191
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
_statusBarVisibilityBeforeAdShow =
UIApplication.sharedApplication.statusBarHidden;
[UIApplication.sharedApplication setStatusBarHidden:YES];
#pragma clang diagnostic pop
[manager adWillPresentFullScreenContent:self];
}

Expand All @@ -626,6 +636,11 @@ - (void)adDidDismissFullScreenContent:

- (void)adWillDismissFullScreenContent:
(nonnull id<GADFullScreenPresentingAd>)ad {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
[UIApplication.sharedApplication
setStatusBarHidden:_statusBarVisibilityBeforeAdShow];
#pragma clang diagnostic pop
[manager adWillDismissFullScreenContent:self];
}

Expand Down
44 changes: 31 additions & 13 deletions packages/google_mobile_ads/ios/Tests/FLTRewardedAdTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,11 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request
});
// Stub setting of FullScreenContentDelegate to invoke delegate callbacks.
NSError *error = OCMClassMock([NSError class]);
__block id<GADFullScreenContentDelegate> fullScreenContentDelegate;
OCMStub([rewardedClassMock setFullScreenContentDelegate:[OCMArg any]])
.andDo(^(NSInvocation *invocation) {
id<GADFullScreenContentDelegate> delegate;
[invocation getArgument:&delegate atIndex:2];
XCTAssertEqual(delegate, ad);
[delegate adDidRecordImpression:rewardedClassMock];
[delegate adDidRecordClick:rewardedClassMock];
[delegate adDidDismissFullScreenContent:rewardedClassMock];
[delegate adWillPresentFullScreenContent:rewardedClassMock];
[delegate adWillDismissFullScreenContent:rewardedClassMock];
[delegate ad:rewardedClassMock
didFailToPresentFullScreenContentWithError:error];
[invocation getArgument:&fullScreenContentDelegate atIndex:2];
XCTAssertEqual(fullScreenContentDelegate, ad);
});
GADResponseInfo *responseInfo = OCMClassMock([GADResponseInfo class]);
OCMStub([rewardedClassMock responseInfo]).andReturn(responseInfo);
Expand Down Expand Up @@ -110,6 +103,12 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request
handler(adValue);
return YES;
}]]);

// Setup mock for UIApplication.sharedInstance
id uiApplicationClassMock = OCMClassMock([UIApplication class]);
OCMStub(ClassMethod([uiApplicationClassMock sharedApplication]))
.andReturn(uiApplicationClassMock);

// Call load and check expected interactions with mocks.
[ad load];

Expand Down Expand Up @@ -154,12 +153,31 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request
presentFromRootViewController:[OCMArg isEqual:mockRootViewController]
userDidEarnRewardHandler:[OCMArg any]]);

// Verify full screen callbacks.
[fullScreenContentDelegate adWillPresentFullScreenContent:rewardedClassMock];
OCMVerify([mockManager adWillPresentFullScreenContent:[OCMArg isEqual:ad]]);
OCMVerify([mockManager adDidDismissFullScreenContent:[OCMArg isEqual:ad]]);
OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]);
// Verify that we hide status bar
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
OCMVerify([uiApplicationClassMock setStatusBarHidden:YES]);
#pragma clang diagnostic pop

[fullScreenContentDelegate adDidRecordImpression:rewardedClassMock];
OCMVerify([mockManager adDidRecordImpression:[OCMArg isEqual:ad]]);

[fullScreenContentDelegate adDidRecordClick:rewardedClassMock];
OCMVerify([mockManager adDidRecordClick:[OCMArg isEqual:ad]]);

[fullScreenContentDelegate adDidDismissFullScreenContent:rewardedClassMock];
OCMVerify([mockManager adDidDismissFullScreenContent:[OCMArg isEqual:ad]]);

[fullScreenContentDelegate adWillDismissFullScreenContent:rewardedClassMock];
OCMVerify([mockManager adWillDismissFullScreenContent:[OCMArg isEqual:ad]]);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
OCMVerify([uiApplicationClassMock setStatusBarHidden:NO]);
#pragma clang diagnostic pop

[ad ad:rewardedClassMock didFailToPresentFullScreenContentWithError:error];
OCMVerify([mockManager
didFailToPresentFullScreenContentWithError:[OCMArg isEqual:ad]
error:[OCMArg isEqual:error]]);
Expand Down

0 comments on commit 7e00b0d

Please sign in to comment.