-
Notifications
You must be signed in to change notification settings - Fork 3.4k
[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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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.
// func adPodInfo(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> IMAAdPodInfo { | ||
// return pigeonInstance.adPodInfo | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
// func adPodInfo(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> IMAAdPodInfo { | |
// return pigeonInstance.adPodInfo | |
// } | |
func adPodInfo(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> IMAAdPodInfo { | |
return pigeonInstance.adPodInfo | |
} |
// func universalAdIDs(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> [IMAUniversalAdID] { | ||
// return pigeonInstance.universalAdIDs | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
// func universalAdIDs(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> [IMAUniversalAdID] { | |
// return pigeonInstance.universalAdIDs | |
// } | |
func universalAdIDs(pigeonApi: PigeonApiIMAAd, pigeonInstance: IMAAd) throws -> [IMAUniversalAdID] { | |
return pigeonInstance.universalAdIDs | |
} |
// 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) | ||
// } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
// 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) | |
} |
AdEvent.ad
/gemini review |
There was a problem hiding this 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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
}
AdEvent.ad
AdEvent.ad
Pre-Review Checklist
[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///
).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
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