-
-
Notifications
You must be signed in to change notification settings - Fork 10
Native ads #98
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
Merged
Merged
Native ads #98
Conversation
This file contains hidden or 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 commit introduces the initial structure for displaying native ads on both Android and iOS. It includes the necessary handlers, data classes, and composable functions, although the core ad loading and display logic is not yet implemented.
* **New API Components:**
* **`NativeAdData`**: A new data class in `commonMain` to hold the assets of a native ad (e.g., headline, body, advertiser).
* **`NativeAdHandler`**: An `expect` class in `commonMain` with `actual` implementations for Android and iOS. This class will manage the lifecycle of a native ad. The current implementation is a skeleton with `TODO()` markers.
* **`NativeAd` Composable**: A new composable function in `commonMain` to display a native ad. It takes a `nativeAdTemplate` composable lambda to render the ad UI.
* **`rememberNativeAd` Composable**: A helper function to create and remember a `NativeAdHandler` instance within a composition.
* **Ad Unit ID:**
* Added `NATIVE_DEFAULT` test ad unit IDs to `AdUnitId` for both Android and iOS platforms.
Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com>
…ata`
This commit refactors the Native Ad implementation by moving all related classes into a `nativead` subpackage. It also converts `NativeAdData` from a `data class` into an `expect` class with platform-specific `actual` implementations, providing a richer, type-safe representation of native ad assets.
* **Package Refactoring:**
* All files related to Native Ads (`NativeAdHandler`, `NativeAdData`, `NativeAd.kt`, `RememberNativeAd.kt`) have been moved from `app.lexilabs.basic.ads` to a new `app.lexilabs.basic.ads.nativead` package.
* **API Enhancement (`NativeAdData`):**
* `NativeAdData` in `commonMain` is now an `expect class` instead of a `data class`.
* It exposes a more comprehensive set of properties, including `adChoicesInfo`, `mediaContent`, and `muteThisAdReasons`.
* Introduced nested `expect` classes: `AdChoicesInfo`, `Image`, `MediaContent`, and `MuteThisAdReason` to provide a common abstraction over platform-specific types.
* **Platform Implementations:**
* Added `actual` implementations for `NativeAdData` on both Android and iOS, wrapping the corresponding classes from the Google Mobile Ads SDK (e.g., `com.google.android.gms.ads.nativead.NativeAd` on Android, `GADNativeAd` on iOS).
* New `NativeAdConverters.kt` files have been added for both Android and iOS to handle the conversion from platform-specific ad objects to the common `NativeAdData` class.
Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com>
This commit refactors the Native Ad API to simplify its usage and implements the ad loading and event handling logic for the Android platform.
* **API Refactoring (Common):**
* The `load` and `setListeners` functions in `NativeAdHandler` have been merged into a single `load` function. This function now accepts all necessary event callbacks (`onLoad`, `onFailure`, `onDismissed`, `onShown`, `onImpression`, `onClick`).
* The `show(nativeAdTemplate)` function has been replaced with `render(): NativeAdData`. The `NativeAd` composable now calls `render()` and passes the resulting `NativeAdData` to the template.
* A `destroy()` function has been added to the `NativeAdHandler` to clean up ad resources.
* **Android Implementation:**
* Implemented the `load` function in `NativeAdHandler` for Android. It uses `AdLoader.Builder` to request a native ad.
* An `AdListener` is used to handle ad lifecycle events (failure, click, impression, shown, dismissed) and invoke the corresponding callbacks.
* The `render()` function is implemented to convert the loaded `com.google.android.gms.ads.nativead.NativeAd` into the common `NativeAdData` class.
* The `destroy()` function now calls `nativeAd.destroy()`.
* **iOS Implementation (Partial):**
* Created `AdLoaderDelegate` and `NativeAdDelegate` to handle `GADAdLoaderDelegateProtocol` and `GADNativeAdDelegateProtocol` respectively.
* The `load` function in the iOS `NativeAdHandler` has been updated to use `GADAdLoader`, but the implementation is incomplete (`TODO`).
* **Composable Updates:**
* The `rememberNativeAd` and `NativeAd` composables have been updated to reflect the new `load` and `render` API in `NativeAdHandler`.
* The `NativeAd` composable that accepts a pre-loaded `NativeAdHandler` has been simplified, removing redundant listener parameters.
Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com>
This commit implements the logic for loading and handling native ads on the iOS platform. It introduces a new `NativeAdLoader` class to manage the ad lifecycle and integrates it with the existing `NativeAdHandler`.
* **New `NativeAdLoader` Class (iOS):**
* A new `NativeAdLoader` class has been created to encapsulate the native ad loading process on iOS.
* It implements `GADNativeAdLoaderDelegateProtocol` to handle ad loading success and failure callbacks from the Google Mobile Ads SDK.
* It uses `suspendCancellableCoroutine` to provide a modern, coroutine-based `loadAd` function.
* It manages the `GADNativeAd` instance and its delegate to forward events like impressions, clicks, and dismissals.
* **Refactor `NativeAdHandler` (iOS):**
* The `load` function in `NativeAdHandler` is now implemented to use the new `NativeAdLoader`.
* It passes callbacks (`onLoad`, `onFailure`, `onShown`, etc.) to the `NativeAdLoader`, which are used to update the `AdState` of the handler.
* The `render()` function is updated to retrieve the loaded ad data from the `NativeAdLoader`.
* The `destroy()` function is implemented to clear the ad reference.
* **File/Class Renaming:**
* The placeholder `AdLoaderDelegate.kt` file and class were renamed and their logic has been superseded by the more complete `NativeAdLoader`.
Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com>
This commit introduces a default composable, `NativeAdDefault`, for rendering native ads and improves the lifecycle management of the `NativeAdHandler`.
* **New `NativeAdDefault` Composable:**
* Added a new `expect` composable `NativeAdDefault` in `commonMain` to provide a default UI for displaying native ads.
* Provided `actual` implementations for both Android and iOS that render common native ad assets like the icon, headline, body, and call to action.
* **Lifecycle Management:**
* In `rememberNativeAd`, a `DisposableEffect` has been added to ensure that `nativeAd.value.destroy()` is called when the composable leaves the composition. This prevents potential resource leaks by properly cleaning up the `NativeAdHandler`.
* **Code Cleanup:**
* Removed `TODO` comments from the `NativeAd` composable, as the new `NativeAdDefault` serves as the intended default template.
Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com>
Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com>
This commit enhances the KDoc documentation for several public composable functions related to ads, improving clarity and developer guidance.
* **Documentation Added/Improved:**
* **`BannerAd.kt`**: Added KDoc for the `BannerAd` composable that accepts an `adUnitId`.
* **`NativeAd.kt`**: Added KDoc for both overloads of the `NativeAd` composable.
* **`NativeAdDefault.kt`**: Added KDoc for the `expect` and `actual` declarations of the `NativeAdDefault` composable.
* **`RememberNativeAd.kt`**: Added comprehensive KDoc for the `rememberNativeAd` composable.
Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com>
robertjamison
added a commit
that referenced
this pull request
Oct 3, 2025
* Native ads (#98) * Add initial support for Native Ads This commit introduces the initial structure for displaying native ads on both Android and iOS. It includes the necessary handlers, data classes, and composable functions, although the core ad loading and display logic is not yet implemented. * **New API Components:** * **`NativeAdData`**: A new data class in `commonMain` to hold the assets of a native ad (e.g., headline, body, advertiser). * **`NativeAdHandler`**: An `expect` class in `commonMain` with `actual` implementations for Android and iOS. This class will manage the lifecycle of a native ad. The current implementation is a skeleton with `TODO()` markers. * **`NativeAd` Composable**: A new composable function in `commonMain` to display a native ad. It takes a `nativeAdTemplate` composable lambda to render the ad UI. * **`rememberNativeAd` Composable**: A helper function to create and remember a `NativeAdHandler` instance within a composition. * **Ad Unit ID:** * Added `NATIVE_DEFAULT` test ad unit IDs to `AdUnitId` for both Android and iOS platforms. Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com> * Refactor Native Ad API and introduce `expect`/`actual` for `NativeAdData` This commit refactors the Native Ad implementation by moving all related classes into a `nativead` subpackage. It also converts `NativeAdData` from a `data class` into an `expect` class with platform-specific `actual` implementations, providing a richer, type-safe representation of native ad assets. * **Package Refactoring:** * All files related to Native Ads (`NativeAdHandler`, `NativeAdData`, `NativeAd.kt`, `RememberNativeAd.kt`) have been moved from `app.lexilabs.basic.ads` to a new `app.lexilabs.basic.ads.nativead` package. * **API Enhancement (`NativeAdData`):** * `NativeAdData` in `commonMain` is now an `expect class` instead of a `data class`. * It exposes a more comprehensive set of properties, including `adChoicesInfo`, `mediaContent`, and `muteThisAdReasons`. * Introduced nested `expect` classes: `AdChoicesInfo`, `Image`, `MediaContent`, and `MuteThisAdReason` to provide a common abstraction over platform-specific types. * **Platform Implementations:** * Added `actual` implementations for `NativeAdData` on both Android and iOS, wrapping the corresponding classes from the Google Mobile Ads SDK (e.g., `com.google.android.gms.ads.nativead.NativeAd` on Android, `GADNativeAd` on iOS). * New `NativeAdConverters.kt` files have been added for both Android and iOS to handle the conversion from platform-specific ad objects to the common `NativeAdData` class. Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com> * Refactor Native Ad API and implement Android loading This commit refactors the Native Ad API to simplify its usage and implements the ad loading and event handling logic for the Android platform. * **API Refactoring (Common):** * The `load` and `setListeners` functions in `NativeAdHandler` have been merged into a single `load` function. This function now accepts all necessary event callbacks (`onLoad`, `onFailure`, `onDismissed`, `onShown`, `onImpression`, `onClick`). * The `show(nativeAdTemplate)` function has been replaced with `render(): NativeAdData`. The `NativeAd` composable now calls `render()` and passes the resulting `NativeAdData` to the template. * A `destroy()` function has been added to the `NativeAdHandler` to clean up ad resources. * **Android Implementation:** * Implemented the `load` function in `NativeAdHandler` for Android. It uses `AdLoader.Builder` to request a native ad. * An `AdListener` is used to handle ad lifecycle events (failure, click, impression, shown, dismissed) and invoke the corresponding callbacks. * The `render()` function is implemented to convert the loaded `com.google.android.gms.ads.nativead.NativeAd` into the common `NativeAdData` class. * The `destroy()` function now calls `nativeAd.destroy()`. * **iOS Implementation (Partial):** * Created `AdLoaderDelegate` and `NativeAdDelegate` to handle `GADAdLoaderDelegateProtocol` and `GADNativeAdDelegateProtocol` respectively. * The `load` function in the iOS `NativeAdHandler` has been updated to use `GADAdLoader`, but the implementation is incomplete (`TODO`). * **Composable Updates:** * The `rememberNativeAd` and `NativeAd` composables have been updated to reflect the new `load` and `render` API in `NativeAdHandler`. * The `NativeAd` composable that accepts a pre-loaded `NativeAdHandler` has been simplified, removing redundant listener parameters. Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com> * Implement Native Ad loading on iOS This commit implements the logic for loading and handling native ads on the iOS platform. It introduces a new `NativeAdLoader` class to manage the ad lifecycle and integrates it with the existing `NativeAdHandler`. * **New `NativeAdLoader` Class (iOS):** * A new `NativeAdLoader` class has been created to encapsulate the native ad loading process on iOS. * It implements `GADNativeAdLoaderDelegateProtocol` to handle ad loading success and failure callbacks from the Google Mobile Ads SDK. * It uses `suspendCancellableCoroutine` to provide a modern, coroutine-based `loadAd` function. * It manages the `GADNativeAd` instance and its delegate to forward events like impressions, clicks, and dismissals. * **Refactor `NativeAdHandler` (iOS):** * The `load` function in `NativeAdHandler` is now implemented to use the new `NativeAdLoader`. * It passes callbacks (`onLoad`, `onFailure`, `onShown`, etc.) to the `NativeAdLoader`, which are used to update the `AdState` of the handler. * The `render()` function is updated to retrieve the loaded ad data from the `NativeAdLoader`. * The `destroy()` function is implemented to clear the ad reference. * **File/Class Renaming:** * The placeholder `AdLoaderDelegate.kt` file and class were renamed and their logic has been superseded by the more complete `NativeAdLoader`. Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com> * Add default native ad template and improve lifecycle This commit introduces a default composable, `NativeAdDefault`, for rendering native ads and improves the lifecycle management of the `NativeAdHandler`. * **New `NativeAdDefault` Composable:** * Added a new `expect` composable `NativeAdDefault` in `commonMain` to provide a default UI for displaying native ads. * Provided `actual` implementations for both Android and iOS that render common native ad assets like the icon, headline, body, and call to action. * **Lifecycle Management:** * In `rememberNativeAd`, a `DisposableEffect` has been added to ensure that `nativeAd.value.destroy()` is called when the composable leaves the composition. This prevents potential resource leaks by properly cleaning up the `NativeAdHandler`. * **Code Cleanup:** * Removed `TODO` comments from the `NativeAd` composable, as the new `NativeAdDefault` serves as the intended default template. Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com> * Updated API Dump. Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com> * Improve KDoc for Ad Composables This commit enhances the KDoc documentation for several public composable functions related to ads, improving clarity and developer guidance. * **Documentation Added/Improved:** * **`BannerAd.kt`**: Added KDoc for the `BannerAd` composable that accepts an `adUnitId`. * **`NativeAd.kt`**: Added KDoc for both overloads of the `NativeAd` composable. * **`NativeAdDefault.kt`**: Added KDoc for the `expect` and `actual` declarations of the `NativeAdDefault` composable. * **`RememberNativeAd.kt`**: Added comprehensive KDoc for the `rememberNativeAd` composable. Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com> --------- Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com> * Version 1.0.0-beta04 This commit updates the library version to `1.0.0-beta04` and bumps the version of the iOS AdMob dependency. * **Version Update:** * The ads library version is updated from `1.0.0-beta03` to `1.0.0-beta04`. * **Dependency Update:** * The CocoaPods AdMob dependency (`cocoapods-admob`) is updated from `12.4.0` to `12.12.0`. These changes are reflected in the `gradle/libs.versions.toml` file. Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com> --------- Signed-off-by: Robert Jamison <65142411+robertjamison@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
documentation
Improvements or additions to documentation
enhancement
New feature or request
help wanted
Extra attention is needed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adding NativeAds implementation for testing in Beta.