-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 `IMAComp…
…anionAd` (#7873)
- Loading branch information
1 parent
5582669
commit a99f9e6
Showing
12 changed files
with
392 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -135,40 +135,21 @@ To update a wrapper for a platform, follow the steps: | |
* Android: Run `flutter build apk --debug` in `example/`. | ||
* iOS: Run `flutter build ios --simulator` in `example/` | ||
|
||
##### 2. Ensure the correct `pigeon` package is added to `dev_dependencies` in the `pubspec.yaml` and run `pub upgrade` | ||
##### 2. Make changes to the respective pigeon file that matches the native SDK | ||
|
||
Android: | ||
|
||
```yaml | ||
pigeon: ^22.2.0 | ||
``` | ||
iOS: | ||
```yaml | ||
pigeon: | ||
git: | ||
url: [email protected]:bparrishMines/packages.git | ||
ref: pigeon_wrapper_swift | ||
path: packages/pigeon | ||
``` | ||
##### 3. Uncomment the multiline comments in the pigeon file | ||
* Android: `pigeons/interactive_media_ads_android.dart` | ||
* iOS: `pigeons/interactive_media_ads_ios.dart` | ||
|
||
##### 4. Make changes that match the native SDK | ||
|
||
* [Android SDK] | ||
* [iOS SDK] | ||
* Android: | ||
- [Android SDK] | ||
- Pigeon file to update: `pigeons/interactive_media_ads_android.dart` | ||
* iOS: | ||
- [iOS SDK] | ||
- Pigeon file to update: `pigeons/interactive_media_ads_ios.dart` | ||
|
||
##### 5. Run the code generator from the terminal | ||
##### 3. Run the code generator from the terminal | ||
|
||
* Android: `dart run pigeon --input pigeons/interactive_media_ads_android.dart` | ||
* iOS: `dart run pigeon --input pigeons/interactive_media_ads_ios.dart` | ||
|
||
##### 6. Update the generated APIs in native code | ||
##### 4. Update the generated APIs in native code | ||
|
||
Running the `flutter build` step from step 1 again should provide build errors and indicate what | ||
needs to be done. Alternatively, it can be easier to update native code with the platform's specific | ||
|
@@ -177,7 +158,7 @@ IDE: | |
* Android: Open `example/android/` in a separate Android Studio project. | ||
* iOS: Open `example/ios/` in Xcode. | ||
|
||
##### 7. Write API tests | ||
##### 5. Write API tests | ||
|
||
Assuming a non-static method or constructor was added to the native wrapper, a native test will need | ||
to be added. | ||
|
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
77 changes: 77 additions & 0 deletions
77
packages/interactive_media_ads/example/ios/RunnerTests/CompanionAdProxyApiTests.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,77 @@ | ||
// 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 XCTest | ||
|
||
@testable import interactive_media_ads | ||
|
||
class CompanionAdProxyApiTests: XCTestCase { | ||
func testResourceValue() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMACompanionAd(registrar) | ||
|
||
let instance = TestCompanionAd.customInit() | ||
let value = try? api.pigeonDelegate.resourceValue(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertEqual(value, instance.resourceValue) | ||
} | ||
|
||
func testApiFramework() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMACompanionAd(registrar) | ||
|
||
let instance = TestCompanionAd.customInit() | ||
let value = try? api.pigeonDelegate.apiFramework(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertEqual(value, instance.apiFramework) | ||
} | ||
|
||
func testWidth() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMACompanionAd(registrar) | ||
|
||
let instance = TestCompanionAd.customInit() | ||
let value = try? api.pigeonDelegate.width(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertEqual(value, Int64(instance.width)) | ||
} | ||
|
||
func testHeight() { | ||
let registrar = TestProxyApiRegistrar() | ||
let api = registrar.apiDelegate.pigeonApiIMACompanionAd(registrar) | ||
|
||
let instance = TestCompanionAd.customInit() | ||
let value = try? api.pigeonDelegate.height(pigeonApi: api, pigeonInstance: instance) | ||
|
||
XCTAssertEqual(value, Int64(instance.height)) | ||
} | ||
|
||
} | ||
|
||
class TestCompanionAd: IMACompanionAd { | ||
// Workaround to subclass an Objective-C class that has an `init` constructor with NS_UNAVAILABLE | ||
static func customInit() -> TestCompanionAd { | ||
let instance = | ||
TestCompanionAd.perform(NSSelectorFromString("new")).takeRetainedValue() as! TestCompanionAd | ||
return instance | ||
} | ||
|
||
override var resourceValue: String? { | ||
return "resourceValue" | ||
} | ||
|
||
override var apiFramework: String? { | ||
return "apiFramework" | ||
} | ||
|
||
override var width: Int { | ||
return 0 | ||
} | ||
|
||
override var height: Int { | ||
return 1 | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...ios/interactive_media_ads/Sources/interactive_media_ads/CompanionAdProxyAPIDelegate.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,32 @@ | ||
// 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 | ||
|
||
/// ProxyApi implementation for [IMACompanionAd]. | ||
/// | ||
/// 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 CompanionAdProxyAPIDelegate: PigeonApiDelegateIMACompanionAd { | ||
func resourceValue(pigeonApi: PigeonApiIMACompanionAd, pigeonInstance: IMACompanionAd) throws | ||
-> String? | ||
{ | ||
return pigeonInstance.resourceValue | ||
} | ||
|
||
func apiFramework(pigeonApi: PigeonApiIMACompanionAd, pigeonInstance: IMACompanionAd) throws | ||
-> String? | ||
{ | ||
return pigeonInstance.apiFramework | ||
} | ||
|
||
func width(pigeonApi: PigeonApiIMACompanionAd, pigeonInstance: IMACompanionAd) throws -> Int64 { | ||
return Int64(pigeonInstance.width) | ||
} | ||
|
||
func height(pigeonApi: PigeonApiIMACompanionAd, pigeonInstance: IMACompanionAd) throws -> Int64 { | ||
return Int64(pigeonInstance.height) | ||
} | ||
} |
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
Oops, something went wrong.