-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[interactive_media_ads] Adds internal wrapper for iOS native `IMAFrie…
…ndlyObstruction` (#7696)
- Loading branch information
1 parent
fe0a3a0
commit bc4dd46
Showing
12 changed files
with
1,146 additions
and
581 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/interactive_media_ads/example/ios/RunnerTests/FriendlyObstructionTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
.../interactive_media_ads/Sources/interactive_media_ads/FriendlyObstructionAPIDelegate.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.