Skip to content

Commit

Permalink
[interactive_media_ads] Adds internal wrapper for iOS native `IMAFrie…
Browse files Browse the repository at this point in the history
…ndlyObstruction` (#7696)
  • Loading branch information
bparrishMines authored Sep 26, 2024
1 parent fe0a3a0 commit bc4dd46
Show file tree
Hide file tree
Showing 12 changed files with 1,146 additions and 581 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.2+3

* Adds internal wrapper for iOS native `IMAFriendlyObstruction`.

## 0.2.2+2

* Adds internal wrapper for Android native `AdsRenderingSettings`.
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.2+2"
const val pluginVersion = "0.2.2+3"
}

override fun setAdTagUrl(pigeon_instance: AdsRequest, adTagUrl: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
8F977DD72C2C89A600A90D4B /* AdEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F977DD62C2C89A600A90D4B /* AdEventTests.swift */; };
8F977DD92C2C8C6A00A90D4B /* AdLoadingErrorDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F977DD82C2C8C6A00A90D4B /* AdLoadingErrorDataTests.swift */; };
8F977DDB2C2C8D2E00A90D4B /* AdsLoadedDataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8F977DDA2C2C8D2E00A90D4B /* AdsLoadedDataTests.swift */; };
8FC919922CA5D86F00188068 /* FriendlyObstructionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8FC919912CA5D86F00188068 /* FriendlyObstructionTests.swift */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; };
Expand Down Expand Up @@ -83,6 +84,7 @@
8F977DD62C2C89A600A90D4B /* AdEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdEventTests.swift; sourceTree = "<group>"; };
8F977DD82C2C8C6A00A90D4B /* AdLoadingErrorDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdLoadingErrorDataTests.swift; sourceTree = "<group>"; };
8F977DDA2C2C8D2E00A90D4B /* AdsLoadedDataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdsLoadedDataTests.swift; sourceTree = "<group>"; };
8FC919912CA5D86F00188068 /* FriendlyObstructionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FriendlyObstructionTests.swift; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -116,6 +118,7 @@
331C8082294A63A400263BE5 /* RunnerTests */ = {
isa = PBXGroup;
children = (
8FC919912CA5D86F00188068 /* FriendlyObstructionTests.swift */,
8F977DCE2C2B99C600A90D4B /* AdDisplayContainerTests.swift */,
8F977DD22C2BA15100A90D4B /* TestProxyApiRegistrar.swift */,
8F977DD42C2C777600A90D4B /* AdErrorTests.swift */,
Expand Down Expand Up @@ -408,6 +411,7 @@
buildActionMask = 2147483647;
files = (
8F599BBF2C3335B40090A0DF /* ViewControllerTests.swift in Sources */,
8FC919922CA5D86F00188068 /* FriendlyObstructionTests.swift in Sources */,
8F977DD92C2C8C6A00A90D4B /* AdLoadingErrorDataTests.swift in Sources */,
8F599BB32C2DD87D0090A0DF /* AdsLoaderTests.swift in Sources */,
8F977DD72C2C89A600A90D4B /* AdEventTests.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// 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.

import Flutter
import GoogleInteractiveMediaAds
import UIKit
import XCTest

@testable import interactive_media_ads

class FriendlyObstructionProxyApiTests: XCTestCase {
func testPigeonDefaultConstructor() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAFriendlyObstruction(registrar)

let instance = try? api.pigeonDelegate.pigeonDefaultConstructor(
pigeonApi: api, view: UIView(), purpose: .mediaControls, detailedReason: "myString")
XCTAssertNotNil(instance)
}

func testPigeonDefaultConstructorWithUnknownPurpose() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAFriendlyObstruction(registrar)

XCTAssertThrowsError(
try api.pigeonDelegate.pigeonDefaultConstructor(
pigeonApi: api, view: UIView(), purpose: .unknown, detailedReason: "myString")
) { error in
XCTAssertTrue(error is PigeonError)
}
}

func testView() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAFriendlyObstruction(registrar)

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

XCTAssertEqual(value, instance.view)
}

func testPurpose() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAFriendlyObstruction(registrar)

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

XCTAssertEqual(value, FriendlyObstructionPurpose.closeAd)
}

func testDetailedReason() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAFriendlyObstruction(registrar)

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

XCTAssertEqual(value, instance.detailedReason)
}
}
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.2+2"
static let pluginVersion = "0.2.2+3"

func pigeonDefaultConstructor(
pigeonApi: PigeonApiIMAAdsRequest, adTagUrl: String, adDisplayContainer: IMAAdDisplayContainer,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// 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.

import Foundation
import GoogleInteractiveMediaAds
import UIKit

/// ProxyApi implementation for [IMAFriendlyObstruction].
///
/// This class may handle instantiating native object instances that are attached to a Dart instance
/// or handle method calls on the associated native class or an instance of that class.
class FriendlyObstructionProxyAPIDelegate: PigeonApiDelegateIMAFriendlyObstruction {
func pigeonDefaultConstructor(
pigeonApi: PigeonApiIMAFriendlyObstruction, view: UIView, purpose: FriendlyObstructionPurpose,
detailedReason: String?
) throws -> IMAFriendlyObstruction {
var nativePurpose: IMAFriendlyObstructionPurpose
switch purpose {
case .mediaControls:
nativePurpose = IMAFriendlyObstructionPurpose.mediaControls
case .closeAd:
nativePurpose = IMAFriendlyObstructionPurpose.closeAd
case .notVisible:
nativePurpose = IMAFriendlyObstructionPurpose.notVisible
case .other:
nativePurpose = IMAFriendlyObstructionPurpose.other
case .unknown:
throw (pigeonApi.pigeonRegistrar.apiDelegate as! ProxyApiDelegate).createUnknownEnumError(
withEnum: purpose)
}
return IMAFriendlyObstruction(
view: view, purpose: nativePurpose, detailedReason: detailedReason)
}

func view(pigeonApi: PigeonApiIMAFriendlyObstruction, pigeonInstance: IMAFriendlyObstruction)
throws -> UIView
{
return pigeonInstance.view
}

func purpose(pigeonApi: PigeonApiIMAFriendlyObstruction, pigeonInstance: IMAFriendlyObstruction)
throws -> FriendlyObstructionPurpose
{
switch pigeonInstance.purpose {
case .mediaControls:
return .mediaControls
case .closeAd:
return .closeAd
case .notVisible:
return .notVisible
case .other:
return .other
@unknown default:
return .unknown
}
}

func detailedReason(
pigeonApi: PigeonApiIMAFriendlyObstruction, pigeonInstance: IMAFriendlyObstruction
) throws -> String? {
return pigeonInstance.detailedReason
}
}
Loading

0 comments on commit bc4dd46

Please sign in to comment.