Skip to content

[interactive_media_ads] Updates ProxyApis to prepare to add support for AdEvent.ad #9785

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Aug 11, 2025

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds internal wrappers for the iOS native IMAAd and IMAUniversalAdID classes, which is a good step forward. The changes include new pigeon definitions, generated code for Dart and Swift, native delegate implementations, and new tests.

However, there are a few critical issues to address:

  • The pull request description is the default template and hasn't been filled out. Please update it to describe the changes and link to the relevant issue(s), as required by the contributor guide.
  • There are inconsistencies in the implementation. Some delegate methods in AdProxyAPIDelegate.swift are commented out, but the generated code calls them with force unwrapping (try!), which will lead to a runtime crash.
  • A test case for companion ads is commented out in AdProxyAPITests.swift, which should be enabled to ensure full test coverage for the newly supported feature.

Please address these points to ensure the stability and completeness of the changes.

Comment on lines 86 to 88
// func adPodInfo(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> IMAAdPodInfo {
// return pigeonInstance.adPodInfo
// }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This method is commented out, but the generated pigeon code in InteractiveMediaAdsLibrary.g.swift calls it using try!. This will cause a runtime crash when a new IMAAd instance is created. Please uncomment and implement this method.

Suggested change
// func adPodInfo(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> IMAAdPodInfo {
// return pigeonInstance.adPodInfo
// }
func adPodInfo(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> IMAAdPodInfo {
return pigeonInstance.adPodInfo
}

Comment on lines 102 to 104
// func universalAdIDs(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> [IMAUniversalAdID] {
// return pigeonInstance.universalAdIDs
// }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This method is commented out, but the generated pigeon code in InteractiveMediaAdsLibrary.g.swift calls it using try!. This will cause a runtime crash when a new IMAAd instance is created. Please uncomment and implement this method.

Suggested change
// func universalAdIDs(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> [IMAUniversalAdID] {
// return pigeonInstance.universalAdIDs
// }
func universalAdIDs(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> [IMAUniversalAdID] {
return pigeonInstance.universalAdIDs
}

Comment on lines 52 to 60
// func testCompanionAds() {
// let registrar = TestProxyApiRegistrar()
// let api = registrar.apiDelegate.pigeonApiIMAAd(registrar)
//
// let instance = TestAd.customInit()
// let value = try? api.pigeonDelegate.companionAds(pigeonApi: api, pigeonInstance: instance)
//
// XCTAssertEqual(value, instance.companionAds)
// }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This test case for companionAds is commented out. Since the README.md has been updated to remove companion ads from the list of unsupported features, this test should be enabled to ensure the functionality is correctly implemented and verified.

Suggested change
// func testCompanionAds() {
// let registrar = TestProxyApiRegistrar()
// let api = registrar.apiDelegate.pigeonApiIMAAd(registrar)
//
// let instance = TestAd.customInit()
// let value = try? api.pigeonDelegate.companionAds(pigeonApi: api, pigeonInstance: instance)
//
// XCTAssertEqual(value, instance.companionAds)
// }
func testCompanionAds() {
let registrar = TestProxyApiRegistrar()
let api = registrar.apiDelegate.pigeonApiIMAAd(registrar)
let instance = TestAd.customInit()
let value = try? api.pigeonDelegate.companionAds(pigeonApi: api, pigeonInstance: instance)
XCTAssertEqual(value, instance.companionAds)
}

@bparrishMines bparrishMines changed the title Ima ad ios [interactive_media_ads] Updates native ProxyApis to prepare to add support for AdEvent.ad Aug 14, 2025
@bparrishMines bparrishMines marked this pull request as ready for review August 18, 2025 21:42
@bparrishMines
Copy link
Contributor Author

/gemini review

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request prepares for adding support for AdEvent.ad by updating the native ProxyAPIs. It introduces new classes for IMAAd and IMAUniversalAdID on iOS, and updates AdEvent on both Android and iOS to include the ad property. The changes are well-implemented, with corresponding updates to pigeon files, native code, tests, and package metadata. The refactoring of some iOS pigeon classes to extend NSObject improves consistency. I have one suggestion to improve the implementation of the uiElements function for better readability and maintainability.

Comment on lines 42 to 64
var uiElements: [UIElementType] = []
let uiElementsArray = pigeonInstance.uiElements as NSArray
// IMAAd.uiElements is expected to be NSArray<NSNumber *>, but is returning as
// an NSArray<NSString *> and causing a crash when using Swift. This attempts
// to handle both scenarios and returns UIElementType.unknown if the value
// can't be handled.
for uiElement in uiElementsArray {
switch uiElement {
case let uiElement as String where uiElement == "adAttribution":
uiElements.append(UIElementType.adAttribution)
case let uiElement as NSNumber
where uiElement.intValue == IMAUiElementType.elements_AD_ATTRIBUTION.rawValue:
uiElements.append(UIElementType.adAttribution)
case let uiElement as String where uiElement == "countdown":
uiElements.append(UIElementType.countdown)
case let uiElement as NSNumber
where uiElement.intValue == IMAUiElementType.elements_COUNTDOWN.rawValue:
uiElements.append(UIElementType.countdown)
default:
uiElements.append(UIElementType.unknown)
}
}
return uiElements

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The implementation of this function is a bit verbose and can be simplified using a more functional approach with map. This would make the code more concise and arguably easier to read by reducing repetition.

    let uiElementsArray = pigeonInstance.uiElements as NSArray
    // IMAAd.uiElements is expected to be NSArray<NSNumber *>, but is returning as
    // an NSArray<NSString *> and causing a crash when using Swift. This attempts
    // to handle both scenarios and returns UIElementType.unknown if the value
    // can't be handled.
    return uiElementsArray.map { uiElement -> UIElementType in
      if let stringValue = uiElement as? String {
        switch stringValue {
        case "adAttribution":
          return .adAttribution
        case "countdown":
          return .countdown
        default:
          return .unknown
        }
      } else if let numberValue = uiElement as? NSNumber,
        let type = IMAUiElementType(rawValue: numberValue.intValue)
      {
        switch type {
        case .elements_AD_ATTRIBUTION:
          return .adAttribution
        case .elements_COUNTDOWN:
          return .countdown
        default:
          return .unknown
        }
      }
      return .unknown
    }

@bparrishMines bparrishMines changed the title [interactive_media_ads] Updates native ProxyApis to prepare to add support for AdEvent.ad [interactive_media_ads] Updates ProxyApis to prepare to add support for AdEvent.ad Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant