-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔧 refactor(main.dart): import 'dart:async' and 'package:xandr/load_mo…
…de.dart' to support asynchronous operations and load mode functionality ✨ feat(main.dart): add ScrollController and StreamController to manage scroll events and check if ad is in viewport 🔧 refactor(main.dart): add listener to _scrollController to add its position to _checkIfAdIsInViewport stream ✨ feat(main.dart): add more Text widgets and a new AdBanner with loadMode set to LoadMode.whenInViewport to demonstrate ad loading when in viewport 🔧 refactor(ad_banner.dart): import 'dart:async' and 'package:xandr/load_mode.dart' to support asynchronous operations and load mode functionality ✨ feat(ad_banner.dart): add loadMode parameter to AdBanner and _HostAdBannerView to determine when the ad is loaded ✨ feat(ad_banner.dart): add loadAd method to trigger ad loading via MethodChannel ✨ feat(ad_banner.dart): add _checkViewport method to check if the ad is in the viewport and load it if it is 🔧 refactor(ad_banner.dart): call loadAd in initState if loadMode is LoadWhenCreated 🔧 refactor(ad_banner.dart): call _checkViewport in initState if loadMode is WhenInViewport 🔧 refactor(ad_banner.dart): add onDoneLoading callback to _HostAdBannerView to update _loading and _loaded states when ad loading is done 🔧 refactor(ad_banner.dart): call loadAd in _HostAdBannerView's onPlatformViewCreated if loadMode is LoadWhenCreated 🔧 refactor(ad_banner.dart): add loadMode to creationParams to pass it to the native code 🔧 refactor(ad_banner.dart): add widgetId to _HostAdBannerView to pass it to the native code 🔧 refactor(ad_banner.dart): complete widgetId in _HostAdBannerView's onPlatformViewCreated if it's not completed yet 🔧 refactor(ad_banner.dart): call onDoneLoading in _HostAdBannerView's onPlatformViewCreated when ad loading is done 🔧 refactor(ad_banner.dart): call loadAd in _HostAdBannerView's onPlatformViewCreated if loadMode is LoadWhenCreated 🔧 refactor(ad_banner.dart): add loadMode to _HostAdBannerView's creationParams to pass it to the native code 🔧 refactor(ad_banner.dart): add loadMode
- Loading branch information
Showing
15 changed files
with
346 additions
and
18 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
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,54 @@ | ||
import 'package:flutter/material.dart'; | ||
|
||
/// Represents the load mode for a specific operation. | ||
class LoadMode { | ||
LoadMode._(); | ||
|
||
/// factory method to create a class [LoadWhenCreated] | ||
factory LoadMode.whenCreated() = LoadWhenCreated; | ||
|
||
/// factory method to create a class [WhenInViewport] | ||
factory LoadMode.whenInViewport( | ||
Stream<ScrollPosition> checkIfInViewport, | ||
int pixelOffset, | ||
) = WhenInViewport; | ||
} | ||
|
||
/// Use this class to automatically load the ad when it's created in the native | ||
/// code. | ||
/// | ||
/// Use the factory method [LoadMode.whenCreated] to create it. | ||
class LoadWhenCreated extends LoadMode { | ||
/// load the ad immediately when it's created. | ||
LoadWhenCreated() : super._(); | ||
} | ||
|
||
/// Use this class to when you want to asynchronously load the ad and | ||
/// additionally check if it's in the viewport (+- pixelOffset). | ||
/// | ||
/// [checkIfInViewport] pass null events, to trigger checking if the | ||
/// BannerAdView is in the viewport (+- pixelOffset). | ||
/// For example, the events could be generated by a [NotificationListener], | ||
/// so that on every scroll, you would check if the BannerAdView is in the | ||
/// viewport. [pixelOffset] number of pixels that is used to calculate when to | ||
/// load the ad. NOTE: Bear in mind, that the BannerAdView should be added to | ||
/// the widget tree. So dynamic ListViews with a builder method could not | ||
/// catch -1000px offsets, because the BannerAdView is not rendered/created yet. | ||
/// Example values: | ||
/// If set to 0, the ad will load when the widget will enter the viewport. | ||
/// If set to -100, the ad will load -100 px before appearing on the screen. | ||
/// If set to 100, the ad will load when 100 px of the ad could be shown. | ||
/// | ||
/// Use the factory method [LoadMode.whenInViewport] to create it. | ||
class WhenInViewport extends LoadMode { | ||
/// load ad when it's in the viewport | ||
WhenInViewport(this.checkIfInViewport, int? pixelOffset) | ||
: pixelOffset = pixelOffset ?? 0, | ||
super._(); | ||
|
||
/// stream which should get new events when scrolling changes | ||
final Stream<ScrollPosition> checkIfInViewport; | ||
|
||
/// pixel offset determining when to load the ad | ||
final int pixelOffset; | ||
} |
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.