Skip to content

Commit

Permalink
[interactive_media_ads] Adds remaining methods for internal wrapper o…
Browse files Browse the repository at this point in the history
…f the iOS native `IMAAdDisplayContainer`. (flutter#8153)
  • Loading branch information
bparrishMines authored Jan 8, 2025
1 parent 03f83cf commit 4efc3d1
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 28 deletions.
4 changes: 4 additions & 0 deletions packages/interactive_media_ads/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.2.3+4

* Adds remaining methods for internal wrapper of the iOS native `IMAAdDisplayContainer`.

## 0.2.3+3

* Adds internal wrapper for Android native `CompanionAdSlot` and `CompanionAdSlot.ClickListener`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AdsRequestProxyApi(override val pigeonRegistrar: ProxyApiRegistrar) :
*
* This must match the version in pubspec.yaml.
*/
const val pluginVersion = "0.2.3+3"
const val pluginVersion = "0.2.3+4"
}

override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

import Flutter
import GoogleInteractiveMediaAds
import XCTest

@testable import interactive_media_ads
Expand All @@ -13,8 +14,104 @@ final class AdDisplayContainerTests: XCTestCase {
let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar)

let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(
pigeonApi: api, adContainer: UIView(), adContainerViewController: UIViewController())

pigeonApi: api, adContainer: UIView(), companionSlots: [],
adContainerViewController: UIViewController())
XCTAssertNotNil(instance)
}

func testAdContainer() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar)

let instance = TestAdDisplayContainer()
let value = try? api.pigeonDelegate.adContainer(pigeonApi: api, pigeonInstance: instance)

XCTAssertEqual(value, instance.adContainer)
}

func testCompanionSlots() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar)

let instance = TestAdDisplayContainer()
let value = try? api.pigeonDelegate.companionSlots(pigeonApi: api, pigeonInstance: instance)

XCTAssertEqual(value, instance.companionSlots)
}

func testSetAdContainerViewController() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar)

let instance = TestAdDisplayContainer()
let controller = UIViewController()
try? api.pigeonDelegate.setAdContainerViewController(
pigeonApi: api, pigeonInstance: instance, controller: controller)

XCTAssertEqual(instance.adContainerViewController, controller)
}

func testGetAdContainerViewController() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar)

let instance = TestAdDisplayContainer()
let adContainerViewController = UIViewController()
instance.adContainerViewController = adContainerViewController
let value = try? api.pigeonDelegate.getAdContainerViewController(
pigeonApi: api, pigeonInstance: instance)

XCTAssertEqual(value, adContainerViewController)
}

func testRegisterFriendlyObstruction() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar)

let instance = TestAdDisplayContainer()
let friendlyObstruction = IMAFriendlyObstruction(
view: UIView(), purpose: IMAFriendlyObstructionPurpose.closeAd, detailedReason: "reason")
try? api.pigeonDelegate.registerFriendlyObstruction(
pigeonApi: api, pigeonInstance: instance, friendlyObstruction: friendlyObstruction)

XCTAssertEqual(instance.registerFriendlyObstructionArgs, [friendlyObstruction])
}

func testUnregisterAllFriendlyObstructions() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAAdDisplayContainer(registrar)

let instance = TestAdDisplayContainer()
try? api.pigeonDelegate.unregisterAllFriendlyObstructions(
pigeonApi: api, pigeonInstance: instance)

XCTAssertTrue(instance.unregisterAllFriendlyObstructionsCalled)
}
}

class TestAdDisplayContainer: IMAAdDisplayContainer {
private var adContainerTestValue = UIView()
private var companionSlotsTestValue = [IMACompanionAdSlot(view: UIView())]
var registerFriendlyObstructionArgs: [AnyHashable?]? = nil
var unregisterAllFriendlyObstructionsCalled = false

convenience init() {
self.init(adContainer: UIView(), viewController: UIViewController())
}

override var adContainer: UIView {
return adContainerTestValue
}

override var companionSlots: [IMACompanionAdSlot] {
return companionSlotsTestValue
}

override func register(_ friendlyObstruction: IMAFriendlyObstruction) {
registerFriendlyObstructionArgs = [friendlyObstruction]
}

override func unregisterAllFriendlyObstructions() {
unregisterAllFriendlyObstructionsCalled = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,48 @@ import GoogleInteractiveMediaAds
class AdDisplayContainerProxyAPIDelegate: PigeonApiDelegateIMAAdDisplayContainer {
func pigeonDefaultConstructor(
pigeonApi: PigeonApiIMAAdDisplayContainer, adContainer: UIView,
adContainerViewController: UIViewController?
companionSlots: [IMACompanionAdSlot]?, adContainerViewController: UIViewController?
) throws -> IMAAdDisplayContainer {
return IMAAdDisplayContainer(
adContainer: adContainer, viewController: adContainerViewController)
adContainer: adContainer, viewController: adContainerViewController,
companionSlots: companionSlots)
}

func adContainer(pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer)
throws -> UIView
{
return pigeonInstance.adContainer
}

func companionSlots(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer
) throws -> [IMACompanionAdSlot]? {
return pigeonInstance.companionSlots
}

func setAdContainerViewController(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer,
controller: UIViewController?
) throws {
pigeonInstance.adContainerViewController = controller
}

func getAdContainerViewController(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer
) throws -> UIViewController? {
return pigeonInstance.adContainerViewController
}

func registerFriendlyObstruction(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer,
friendlyObstruction: IMAFriendlyObstruction
) throws {
pigeonInstance.register(friendlyObstruction)
}

func unregisterAllFriendlyObstructions(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer
) throws {
pigeonInstance.unregisterAllFriendlyObstructions()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class AdsRequestProxyAPIDelegate: PigeonApiDelegateIMAAdsRequest {
/// The current version of the `interactive_media_ads` plugin.
///
/// This must match the version in pubspec.yaml.
static let pluginVersion = "0.2.3+3"
static let pluginVersion = "0.2.3+4"

func pigeonDefaultConstructor(
pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Autogenerated from Pigeon (v22.5.0), do not edit directly.
// Autogenerated from Pigeon (v22.6.2), do not edit directly.
// See also: https://pub.dev/packages/pigeon

import Foundation
Expand Down Expand Up @@ -1200,10 +1200,38 @@ class InteractiveMediaAdsLibraryPigeonCodec: FlutterStandardMessageCodec, @unche
}

protocol PigeonApiDelegateIMAAdDisplayContainer {
/// Initializes IMAAdDisplayContainer for rendering the ad and displaying the
/// sad UI.
func pigeonDefaultConstructor(
pigeonApi: PigeonApiIMAAdDisplayContainer, adContainer: UIView,
adContainerViewController: UIViewController?
companionSlots: [IMACompanionAdSlot]?, adContainerViewController: UIViewController?
) throws -> IMAAdDisplayContainer
/// View containing the video display and ad related UI.
///
/// This view must be present in the view hierarchy in order to make ad or
/// stream requests.
func adContainer(pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer)
throws -> UIView
/// List of companion ad slots.
func companionSlots(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer
) throws -> [IMACompanionAdSlot]?
/// View controller containing the ad container.
func setAdContainerViewController(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer,
controller: UIViewController?) throws
/// View controller containing the ad container.
func getAdContainerViewController(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer
) throws -> UIViewController?
/// Registers a view that overlays or obstructs this container as “friendly”
/// for viewability measurement purposes.
func registerFriendlyObstruction(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer,
friendlyObstruction: IMAFriendlyObstruction) throws
/// Unregisters all previously registered friendly obstructions.
func unregisterAllFriendlyObstructions(
pigeonApi: PigeonApiIMAAdDisplayContainer, pigeonInstance: IMAAdDisplayContainer) throws
}

protocol PigeonApiProtocolIMAAdDisplayContainer {
Expand Down Expand Up @@ -1242,11 +1270,12 @@ final class PigeonApiIMAAdDisplayContainer: PigeonApiProtocolIMAAdDisplayContain
let args = message as! [Any?]
let pigeonIdentifierArg = args[0] as! Int64
let adContainerArg = args[1] as! UIView
let adContainerViewControllerArg: UIViewController? = nilOrValue(args[2])
let companionSlotsArg: [IMACompanionAdSlot]? = nilOrValue(args[2])
let adContainerViewControllerArg: UIViewController? = nilOrValue(args[3])
do {
api.pigeonRegistrar.instanceManager.addDartCreatedInstance(
try api.pigeonDelegate.pigeonDefaultConstructor(
pigeonApi: api, adContainer: adContainerArg,
pigeonApi: api, adContainer: adContainerArg, companionSlots: companionSlotsArg,
adContainerViewController: adContainerViewControllerArg),
withIdentifier: pigeonIdentifierArg)
reply(wrapResult(nil))
Expand All @@ -1257,6 +1286,85 @@ final class PigeonApiIMAAdDisplayContainer: PigeonApiProtocolIMAAdDisplayContain
} else {
pigeonDefaultConstructorChannel.setMessageHandler(nil)
}
let setAdContainerViewControllerChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.setAdContainerViewController",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
setAdContainerViewControllerChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let pigeonInstanceArg = args[0] as! IMAAdDisplayContainer
let controllerArg: UIViewController? = nilOrValue(args[1])
do {
try api.pigeonDelegate.setAdContainerViewController(
pigeonApi: api, pigeonInstance: pigeonInstanceArg, controller: controllerArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
setAdContainerViewControllerChannel.setMessageHandler(nil)
}
let getAdContainerViewControllerChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.getAdContainerViewController",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
getAdContainerViewControllerChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let pigeonInstanceArg = args[0] as! IMAAdDisplayContainer
do {
let result = try api.pigeonDelegate.getAdContainerViewController(
pigeonApi: api, pigeonInstance: pigeonInstanceArg)
reply(wrapResult(result))
} catch {
reply(wrapError(error))
}
}
} else {
getAdContainerViewControllerChannel.setMessageHandler(nil)
}
let registerFriendlyObstructionChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.registerFriendlyObstruction",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
registerFriendlyObstructionChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let pigeonInstanceArg = args[0] as! IMAAdDisplayContainer
let friendlyObstructionArg = args[1] as! IMAFriendlyObstruction
do {
try api.pigeonDelegate.registerFriendlyObstruction(
pigeonApi: api, pigeonInstance: pigeonInstanceArg,
friendlyObstruction: friendlyObstructionArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
registerFriendlyObstructionChannel.setMessageHandler(nil)
}
let unregisterAllFriendlyObstructionsChannel = FlutterBasicMessageChannel(
name:
"dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.unregisterAllFriendlyObstructions",
binaryMessenger: binaryMessenger, codec: codec)
if let api = api {
unregisterAllFriendlyObstructionsChannel.setMessageHandler { message, reply in
let args = message as! [Any?]
let pigeonInstanceArg = args[0] as! IMAAdDisplayContainer
do {
try api.pigeonDelegate.unregisterAllFriendlyObstructions(
pigeonApi: api, pigeonInstance: pigeonInstanceArg)
reply(wrapResult(nil))
} catch {
reply(wrapError(error))
}
}
} else {
unregisterAllFriendlyObstructionsChannel.setMessageHandler(nil)
}
}

///Creates a Dart instance of IMAAdDisplayContainer and attaches it to [pigeonInstance].
Expand All @@ -1277,13 +1385,18 @@ final class PigeonApiIMAAdDisplayContainer: PigeonApiProtocolIMAAdDisplayContain
}
let pigeonIdentifierArg = pigeonRegistrar.instanceManager.addHostCreatedInstance(
pigeonInstance as AnyObject)
let adContainerArg = try! pigeonDelegate.adContainer(
pigeonApi: self, pigeonInstance: pigeonInstance)
let companionSlotsArg = try! pigeonDelegate.companionSlots(
pigeonApi: self, pigeonInstance: pigeonInstance)
let binaryMessenger = pigeonRegistrar.binaryMessenger
let codec = pigeonRegistrar.codec
let channelName: String =
"dev.flutter.pigeon.interactive_media_ads.IMAAdDisplayContainer.pigeon_newInstance"
let channel = FlutterBasicMessageChannel(
name: channelName, binaryMessenger: binaryMessenger, codec: codec)
channel.sendMessage([pigeonIdentifierArg] as [Any?]) { response in
channel.sendMessage([pigeonIdentifierArg, adContainerArg, companionSlotsArg] as [Any?]) {
response in
guard let listResponse = response as? [Any?] else {
completion(.failure(createConnectionError(withChannelName: channelName)))
return
Expand Down
Loading

0 comments on commit 4efc3d1

Please sign in to comment.