diff --git a/packages/google_mobile_ads/lib/src/ad_containers.dart b/packages/google_mobile_ads/lib/src/ad_containers.dart index f55bd2723..abd1f25f4 100644 --- a/packages/google_mobile_ads/lib/src/ad_containers.dart +++ b/packages/google_mobile_ads/lib/src/ad_containers.dart @@ -645,6 +645,10 @@ abstract class AdWithoutView extends Ad { /// (e.g. [BannerAd] and [NativeAd]) and allows them to be added to the Flutter /// widget tree. /// +/// Optionally, you can provide [gestureRecognizers] to enable custom gesture +/// interactions with the ad content. For example, this can allow users to +/// swipe or perform other gestures based on your app's requirements. +/// /// Must call `load()` first before showing the widget. Otherwise, a /// [PlatformException] will be thrown. class AdWidget extends StatefulWidget { diff --git a/packages/google_mobile_ads/test/ad_containers_test.dart b/packages/google_mobile_ads/test/ad_containers_test.dart index f67ed656f..6b8e240c6 100644 --- a/packages/google_mobile_ads/test/ad_containers_test.dart +++ b/packages/google_mobile_ads/test/ad_containers_test.dart @@ -15,6 +15,7 @@ import 'dart:async'; import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:google_mobile_ads/src/ad_instance_manager.dart'; import 'package:google_mobile_ads/google_mobile_ads.dart'; @@ -412,6 +413,45 @@ void main() { } }); + testWidgets('passes gestureRecognizers to PlatformView on iOS', + (WidgetTester tester) async { + final gestureRecognizers = >{ + Factory(() => PanGestureRecognizer()), + Factory(() => TapGestureRecognizer()), + }; + + final NativeAd ad = NativeAd( + adUnitId: 'test-ad-unit', + factoryId: '0', + listener: NativeAdListener(), + request: AdRequest(), + ); + + await ad.load(); + + debugDefaultTargetPlatformOverride = TargetPlatform.iOS; + + await tester.pumpWidget( + MaterialApp( + home: Material( + child: AdWidget( + ad: ad, + gestureRecognizers: gestureRecognizers, + ), + ), + ), + ); + + final uiKitViewFinder = find.byType(UiKitView); + expect(uiKitViewFinder, findsOneWidget); + + final uiKitView = tester.widget(uiKitViewFinder); + expect(uiKitView.gestureRecognizers, gestureRecognizers); + + debugDefaultTargetPlatformOverride = null; + await ad.dispose(); + }); + test('load show rewarded', () async { RewardedAd? rewarded; AdRequest request = AdRequest();