Skip to content

Commit

Permalink
comment and test
Browse files Browse the repository at this point in the history
  • Loading branch information
PaananenReko committed Jan 14, 2025
1 parent 13c3ae6 commit 187323c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/google_mobile_ads/lib/src/ad_containers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
40 changes: 40 additions & 0 deletions packages/google_mobile_ads/test/ad_containers_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -412,6 +413,45 @@ void main() {
}
});

testWidgets('passes gestureRecognizers to PlatformView on iOS',
(WidgetTester tester) async {
final gestureRecognizers = <Factory<OneSequenceGestureRecognizer>>{
Factory<OneSequenceGestureRecognizer>(() => PanGestureRecognizer()),
Factory<OneSequenceGestureRecognizer>(() => 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<UiKitView>(uiKitViewFinder);
expect(uiKitView.gestureRecognizers, gestureRecognizers);

debugDefaultTargetPlatformOverride = null;
await ad.dispose();
});

test('load show rewarded', () async {
RewardedAd? rewarded;
AdRequest request = AdRequest();
Expand Down

0 comments on commit 187323c

Please sign in to comment.