@capacitor-community/admob 8.2.0 → 8.2.1-beta.pr490.shaf4a3cab095f4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapacitorCommunityAdmob.podspec +1 -1
- package/Package.swift +1 -1
- package/README.md +8 -7
- package/android/build.gradle +5 -1
- package/android/src/main/java/com/getcapacitor/community/admob/AdMob.java +88 -0
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdExecutor.kt +626 -0
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdFeedSessions.kt +35 -0
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdPlacementValue.kt +44 -0
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdPluginEvents.kt +11 -0
- package/android/src/main/java/com/getcapacitor/community/admob/nativeads/PluginNativeAdView.kt +187 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +5 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/native-ads/index.d.ts +6 -0
- package/dist/esm/native-ads/index.js +4 -0
- package/dist/esm/native-ads/index.js.map +1 -0
- package/dist/esm/native-ads/native-ad-definitions.interface.d.ts +20 -0
- package/dist/esm/native-ads/native-ad-definitions.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-definitions.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-element.d.ts +9 -0
- package/dist/esm/native-ads/native-ad-element.js +53 -0
- package/dist/esm/native-ads/native-ad-element.js.map +1 -0
- package/dist/esm/native-ads/native-ad-event.interface.d.ts +5 -0
- package/dist/esm/native-ads/native-ad-event.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-event.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-feed.d.ts +72 -0
- package/dist/esm/native-ads/native-ad-feed.js +643 -0
- package/dist/esm/native-ads/native-ad-feed.js.map +1 -0
- package/dist/esm/native-ads/native-ad-geometry.d.ts +8 -0
- package/dist/esm/native-ads/native-ad-geometry.js +92 -0
- package/dist/esm/native-ads/native-ad-geometry.js.map +1 -0
- package/dist/esm/native-ads/native-ad-options.interface.d.ts +40 -0
- package/dist/esm/native-ads/native-ad-options.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-options.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-placement.interface.d.ts +28 -0
- package/dist/esm/native-ads/native-ad-placement.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-placement.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-plugin-events.enum.d.ts +9 -0
- package/dist/esm/native-ads/native-ad-plugin-events.enum.js +11 -0
- package/dist/esm/native-ads/native-ad-plugin-events.enum.js.map +1 -0
- package/dist/esm/native-ads/native-ad-style.interface.d.ts +30 -0
- package/dist/esm/native-ads/native-ad-style.interface.js +2 -0
- package/dist/esm/native-ads/native-ad-style.interface.js.map +1 -0
- package/dist/esm/native-ads/native-ad-template.enum.d.ts +11 -0
- package/dist/esm/native-ads/native-ad-template.enum.js +13 -0
- package/dist/esm/native-ads/native-ad-template.enum.js.map +1 -0
- package/dist/esm/web.d.ts +9 -1
- package/dist/esm/web.js +15 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +883 -1
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +883 -1
- package/dist/plugin.js.map +1 -1
- package/docs/configuration.md +2 -2
- package/docs/consent.md +6 -6
- package/docs/events.md +3 -2
- package/docs/migration.md +22 -2
- package/docs/native-ads.md +187 -0
- package/docs/rewarded.md +13 -0
- package/ios/Sources/AdMobPlugin/AdMobPlugin.swift +103 -41
- package/ios/Sources/AdMobPlugin/AppOpen/AppOpenAdPluginEvents.swift +3 -0
- package/ios/Sources/AdMobPlugin/Banner/BannerAdPluginEvents.swift +3 -0
- package/ios/Sources/AdMobPlugin/Banner/BannerAdSizeEnum.swift +3 -0
- package/ios/Sources/AdMobPlugin/Banner/BannerExecutor.swift +4 -4
- package/ios/Sources/AdMobPlugin/Helper/AuthorizationStatusEnum.swift +3 -0
- package/ios/Sources/AdMobPlugin/Interstitial/AdInterstitialExecutor.swift +3 -0
- package/ios/Sources/AdMobPlugin/Interstitial/InterstitialAdPluginEvents.swift +3 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdExecutor.swift +354 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdFeedSessions.swift +34 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdPlacementValue.swift +50 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdPluginEvents.swift +11 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdScrollTracker.swift +66 -0
- package/ios/Sources/AdMobPlugin/NativeAds/NativeAdValues.swift +27 -0
- package/ios/Sources/AdMobPlugin/NativeAds/PluginNativeAdView.swift +187 -0
- package/ios/Sources/AdMobPlugin/Rewarded/AdRewardExecutor.swift +3 -0
- package/ios/Sources/AdMobPlugin/Rewarded/RewardAdPluginEvents.swift +3 -0
- package/ios/Sources/AdMobPlugin/RewardedInterstitial/AdRewardInterstitialExecutor.swift +3 -0
- package/ios/Sources/AdMobPlugin/RewardedInterstitial/RewardInterstitialAdPluginEvents.swift +3 -0
- package/ios/Tests/AdMobPluginTests/AdMobPluginTests.swift +82 -10
- package/ios/Tests/AdMobPluginTests/NativeAdScrollTrackerTests.swift +47 -0
- package/package.json +6 -4
package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdPlacementValue.kt
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
package com.getcapacitor.community.admob.nativeads
|
|
2
|
+
|
|
3
|
+
import org.json.JSONObject
|
|
4
|
+
import kotlin.math.roundToInt
|
|
5
|
+
|
|
6
|
+
internal class NativeAdPlacementValue private constructor(
|
|
7
|
+
val feedId: String,
|
|
8
|
+
val slotKey: String,
|
|
9
|
+
val generation: Int,
|
|
10
|
+
val rectX: Int,
|
|
11
|
+
val rectY: Int,
|
|
12
|
+
val rectWidth: Int,
|
|
13
|
+
val rectHeight: Int,
|
|
14
|
+
val clipX: Int,
|
|
15
|
+
val clipY: Int,
|
|
16
|
+
val clipWidth: Int,
|
|
17
|
+
val clipHeight: Int,
|
|
18
|
+
) {
|
|
19
|
+
private fun hasArea(): Boolean = rectWidth > 0 && rectHeight > 0 && clipWidth > 0 && clipHeight > 0
|
|
20
|
+
|
|
21
|
+
companion object {
|
|
22
|
+
fun parse(expectedFeedId: String, value: JSONObject, density: Float): NativeAdPlacementValue? {
|
|
23
|
+
if (!value.optBoolean("visible", false)) return null
|
|
24
|
+
val rect = value.getJSONObject("rect")
|
|
25
|
+
val clip = value.getJSONObject("clipRect")
|
|
26
|
+
val placement = NativeAdPlacementValue(
|
|
27
|
+
feedId = value.getString("feedId"),
|
|
28
|
+
slotKey = value.getString("slotKey"),
|
|
29
|
+
generation = value.optInt("generation", -1),
|
|
30
|
+
rectX = rect.pixels("x", density),
|
|
31
|
+
rectY = rect.pixels("y", density),
|
|
32
|
+
rectWidth = rect.pixels("width", density),
|
|
33
|
+
rectHeight = rect.pixels("height", density),
|
|
34
|
+
clipX = clip.pixels("x", density),
|
|
35
|
+
clipY = clip.pixels("y", density),
|
|
36
|
+
clipWidth = clip.pixels("width", density),
|
|
37
|
+
clipHeight = clip.pixels("height", density),
|
|
38
|
+
)
|
|
39
|
+
return placement.takeIf { it.feedId == expectedFeedId && it.hasArea() }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
private fun JSONObject.pixels(name: String, density: Float): Int = (getDouble(name) * density).roundToInt()
|
|
43
|
+
}
|
|
44
|
+
}
|
package/android/src/main/java/com/getcapacitor/community/admob/nativeads/NativeAdPluginEvents.kt
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
package com.getcapacitor.community.admob.nativeads
|
|
2
|
+
|
|
3
|
+
internal object NativeAdPluginEvents {
|
|
4
|
+
const val LOADED = "nativeAdLoaded"
|
|
5
|
+
const val FAILED_TO_LOAD = "nativeAdFailedToLoad"
|
|
6
|
+
const val CLICKED = "nativeAdClicked"
|
|
7
|
+
const val IMPRESSION = "nativeAdImpression"
|
|
8
|
+
const val OPENED = "nativeAdOpened"
|
|
9
|
+
const val CLOSED = "nativeAdClosed"
|
|
10
|
+
const val AD_PAID = "nativeAdPaid"
|
|
11
|
+
}
|
package/android/src/main/java/com/getcapacitor/community/admob/nativeads/PluginNativeAdView.kt
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
package com.getcapacitor.community.admob.nativeads
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.graphics.Color
|
|
5
|
+
import android.graphics.drawable.GradientDrawable
|
|
6
|
+
import android.view.Gravity
|
|
7
|
+
import android.view.View
|
|
8
|
+
import android.view.ViewGroup
|
|
9
|
+
import android.widget.Button
|
|
10
|
+
import android.widget.FrameLayout
|
|
11
|
+
import android.widget.ImageView
|
|
12
|
+
import android.widget.LinearLayout
|
|
13
|
+
import android.widget.TextView
|
|
14
|
+
import com.getcapacitor.JSObject
|
|
15
|
+
import com.google.android.gms.ads.nativead.AdChoicesView
|
|
16
|
+
import com.google.android.gms.ads.nativead.MediaView
|
|
17
|
+
import com.google.android.gms.ads.nativead.NativeAd
|
|
18
|
+
import com.google.android.gms.ads.nativead.NativeAdView
|
|
19
|
+
import kotlin.math.max
|
|
20
|
+
import kotlin.math.min
|
|
21
|
+
import kotlin.math.roundToInt
|
|
22
|
+
|
|
23
|
+
/** Builds the plugin-owned layout around the final Next-Gen SDK [NativeAdView]. */
|
|
24
|
+
internal class PluginNativeAdView private constructor(
|
|
25
|
+
private val context: Context,
|
|
26
|
+
nativeAd: NativeAd,
|
|
27
|
+
template: String,
|
|
28
|
+
private val style: JSObject,
|
|
29
|
+
) {
|
|
30
|
+
private val density = context.resources.displayMetrics.density
|
|
31
|
+
private val view = NativeAdView(context)
|
|
32
|
+
|
|
33
|
+
init {
|
|
34
|
+
view.layoutParams = FrameLayout.LayoutParams(
|
|
35
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
36
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
37
|
+
)
|
|
38
|
+
applyBackground()
|
|
39
|
+
bindAssets(nativeAd, template == "small")
|
|
40
|
+
view.setNativeAd(nativeAd)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private fun bindAssets(nativeAd: NativeAd, isSmall: Boolean) {
|
|
44
|
+
val content = LinearLayout(context).apply {
|
|
45
|
+
orientation = LinearLayout.VERTICAL
|
|
46
|
+
setPadding(pixels(12), pixels(12), pixels(12), pixels(12))
|
|
47
|
+
}
|
|
48
|
+
view.addView(
|
|
49
|
+
content,
|
|
50
|
+
FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
if (!isSmall) {
|
|
54
|
+
val media = MediaView(context).apply { minimumHeight = pixels(120) }
|
|
55
|
+
content.addView(media, LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 1f))
|
|
56
|
+
view.mediaView = media
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
val details = LinearLayout(context).apply {
|
|
60
|
+
orientation = LinearLayout.VERTICAL
|
|
61
|
+
setPadding(0, pixels(if (isSmall) 0 else 8), 0, 0)
|
|
62
|
+
}
|
|
63
|
+
content.addView(
|
|
64
|
+
details,
|
|
65
|
+
LinearLayout.LayoutParams(
|
|
66
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
67
|
+
if (isSmall) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT,
|
|
68
|
+
),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
addAttribution(details)
|
|
72
|
+
bindTextAssets(details, nativeAd, isSmall)
|
|
73
|
+
bindFooter(details, nativeAd, isSmall)
|
|
74
|
+
|
|
75
|
+
val adChoices = AdChoicesView(context)
|
|
76
|
+
view.addView(adChoices, FrameLayout.LayoutParams(pixels(24), pixels(24), Gravity.TOP or Gravity.END))
|
|
77
|
+
view.adChoicesView = adChoices
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
private fun addAttribution(parent: LinearLayout) {
|
|
81
|
+
val attribution = TextView(context).apply {
|
|
82
|
+
text = "Ad"
|
|
83
|
+
textSize = 10f
|
|
84
|
+
setTextColor(Color.WHITE)
|
|
85
|
+
setBackgroundColor(Color.DKGRAY)
|
|
86
|
+
gravity = Gravity.CENTER
|
|
87
|
+
}
|
|
88
|
+
parent.addView(attribution, LinearLayout.LayoutParams(pixels(28), pixels(20)))
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private fun bindTextAssets(parent: LinearLayout, nativeAd: NativeAd, isSmall: Boolean) {
|
|
92
|
+
val headline = TextView(context).apply {
|
|
93
|
+
text = nativeAd.headline
|
|
94
|
+
textSize = fontStyle("headlineFontSize", 16f, 12f, 24f)
|
|
95
|
+
setTextColor(colorStyle("headlineColor", Color.BLACK))
|
|
96
|
+
maxLines = 2
|
|
97
|
+
}
|
|
98
|
+
parent.addView(headline)
|
|
99
|
+
view.headlineView = headline
|
|
100
|
+
|
|
101
|
+
val body = TextView(context).apply {
|
|
102
|
+
text = nativeAd.body
|
|
103
|
+
textSize = fontStyle("bodyFontSize", 13f, 10f, 18f)
|
|
104
|
+
setTextColor(colorStyle("bodyColor", Color.DKGRAY))
|
|
105
|
+
maxLines = if (isSmall) 1 else 2
|
|
106
|
+
visibility = if (isSmall || nativeAd.body == null) View.GONE else View.VISIBLE
|
|
107
|
+
}
|
|
108
|
+
parent.addView(body)
|
|
109
|
+
view.bodyView = body
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
private fun bindFooter(parent: LinearLayout, nativeAd: NativeAd, isSmall: Boolean) {
|
|
113
|
+
val footer = LinearLayout(context).apply { gravity = Gravity.CENTER_VERTICAL }
|
|
114
|
+
parent.addView(
|
|
115
|
+
footer,
|
|
116
|
+
LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
val icon = ImageView(context).apply {
|
|
120
|
+
scaleType = ImageView.ScaleType.CENTER_CROP
|
|
121
|
+
nativeAd.icon?.drawable?.let(::setImageDrawable) ?: run { visibility = View.GONE }
|
|
122
|
+
}
|
|
123
|
+
val iconSize = pixels(if (isSmall) 28 else 32)
|
|
124
|
+
footer.addView(icon, LinearLayout.LayoutParams(iconSize, iconSize))
|
|
125
|
+
view.iconView = icon
|
|
126
|
+
|
|
127
|
+
val advertiser = TextView(context).apply {
|
|
128
|
+
text = nativeAd.advertiser
|
|
129
|
+
textSize = 11f
|
|
130
|
+
maxLines = 1
|
|
131
|
+
visibility = if (nativeAd.advertiser == null) View.GONE else View.VISIBLE
|
|
132
|
+
}
|
|
133
|
+
footer.addView(advertiser, LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f))
|
|
134
|
+
view.advertiserView = advertiser
|
|
135
|
+
|
|
136
|
+
val callToAction = Button(context).apply {
|
|
137
|
+
text = nativeAd.callToAction
|
|
138
|
+
textSize = fontStyle("callToActionFontSize", 13f, 12f, 18f)
|
|
139
|
+
setTextColor(colorStyle("callToActionTextColor", Color.WHITE))
|
|
140
|
+
setBackgroundColor(colorStyle("callToActionBackgroundColor", Color.rgb(33, 150, 243)))
|
|
141
|
+
visibility = if (nativeAd.callToAction == null) View.GONE else View.VISIBLE
|
|
142
|
+
}
|
|
143
|
+
footer.addView(
|
|
144
|
+
callToAction,
|
|
145
|
+
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, pixels(if (isSmall) 32 else 40)),
|
|
146
|
+
)
|
|
147
|
+
view.callToActionView = callToAction
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private fun applyBackground() {
|
|
151
|
+
val drawable = GradientDrawable().apply {
|
|
152
|
+
setColor(colorStyle("backgroundColor", Color.WHITE))
|
|
153
|
+
cornerRadius = pixels(floatStyle("cornerRadius", 0f)).toFloat()
|
|
154
|
+
val borderWidth = pixels(floatStyle("borderWidth", 0f))
|
|
155
|
+
if (borderWidth > 0) setStroke(borderWidth, colorStyle("borderColor", Color.TRANSPARENT))
|
|
156
|
+
}
|
|
157
|
+
view.background = drawable
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private fun pixels(logicalPixels: Number): Int = (logicalPixels.toDouble() * density).roundToInt()
|
|
161
|
+
|
|
162
|
+
private fun colorStyle(key: String, fallback: Int): Int {
|
|
163
|
+
val hex = style.getString(key)?.trim()?.removePrefix("#") ?: return fallback
|
|
164
|
+
val rgba = hex.toLongOrNull(16) ?: return fallback
|
|
165
|
+
return when (hex.length) {
|
|
166
|
+
6 -> Color.rgb((rgba shr 16).toInt() and 0xff, (rgba shr 8).toInt() and 0xff, rgba.toInt() and 0xff)
|
|
167
|
+
8 -> Color.argb(
|
|
168
|
+
rgba.toInt() and 0xff,
|
|
169
|
+
(rgba shr 24).toInt() and 0xff,
|
|
170
|
+
(rgba shr 16).toInt() and 0xff,
|
|
171
|
+
(rgba shr 8).toInt() and 0xff,
|
|
172
|
+
)
|
|
173
|
+
else -> fallback
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
private fun floatStyle(key: String, fallback: Float): Float =
|
|
178
|
+
if (style.has(key)) max(0f, style.optDouble(key, fallback.toDouble()).toFloat()) else fallback
|
|
179
|
+
|
|
180
|
+
private fun fontStyle(key: String, fallback: Float, minimum: Float, maximum: Float): Float =
|
|
181
|
+
min(maximum, max(minimum, floatStyle(key, fallback)))
|
|
182
|
+
|
|
183
|
+
companion object {
|
|
184
|
+
fun create(context: Context, nativeAd: NativeAd, template: String, style: JSObject): NativeAdView =
|
|
185
|
+
PluginNativeAdView(context, nativeAd, template, style).view
|
|
186
|
+
}
|
|
187
|
+
}
|
package/dist/esm/index.d.ts
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { registerPlugin } from '@capacitor/core';
|
|
2
|
-
|
|
2
|
+
import { configureNativeAdBridge } from './native-ads/native-ad-feed';
|
|
3
|
+
const nativeAdBridge = registerPlugin('AdMob', {
|
|
3
4
|
web: () => import('./web').then((m) => new m.AdMobWeb()),
|
|
4
5
|
});
|
|
6
|
+
const AdMob = nativeAdBridge;
|
|
7
|
+
configureNativeAdBridge(nativeAdBridge);
|
|
5
8
|
export * from './definitions';
|
|
6
9
|
export * from './banner/index';
|
|
7
10
|
export * from './interstitial/index';
|
|
@@ -10,5 +13,6 @@ export * from './reward/index';
|
|
|
10
13
|
export * from './consent/index';
|
|
11
14
|
export * from './shared/index';
|
|
12
15
|
export * from './app-open/index';
|
|
16
|
+
export * from './native-ads/index';
|
|
13
17
|
export { AdMob };
|
|
14
18
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,OAAO,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEtE,MAAM,cAAc,GAAG,cAAc,CAAoC,OAAO,EAAE;IAChF,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAuC,CAAC;CAC9F,CAAC,CAAC;AACH,MAAM,KAAK,GAAgB,cAAc,CAAC;AAE1C,uBAAuB,CAAC,cAAc,CAAC,CAAC;AAExC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { NativeAdErrorEvent, NativeAdEvent, NativeAdRevenueEvent } from './native-ad-event.interface';
|
|
2
|
+
export { NativeAdFeed } from './native-ad-feed';
|
|
3
|
+
export type { NativeAdFeedOptions } from './native-ad-options.interface';
|
|
4
|
+
export * from './native-ad-plugin-events.enum';
|
|
5
|
+
export type { NativeAdStyle } from './native-ad-style.interface';
|
|
6
|
+
export * from './native-ad-template.enum';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/native-ads/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEhD,cAAc,gCAAgC,CAAC;AAE/C,cAAc,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
import type { NativeAdEvent, NativeAdErrorEvent, NativeAdRevenueEvent } from './native-ad-event.interface';
|
|
3
|
+
import type { NativeAdCommandIdentity, NativeAdFeedSession, NativeAdLoadOptions } from './native-ad-options.interface';
|
|
4
|
+
import type { NativeAdPlacementBatch } from './native-ad-placement.interface';
|
|
5
|
+
import type { NativeAdPluginEvents } from './native-ad-plugin-events.enum';
|
|
6
|
+
/** Low-level native bridge used by {@link NativeAdFeed}. */
|
|
7
|
+
export interface NativeAdDefinitions {
|
|
8
|
+
startNativeAdFeed(options: NativeAdFeedSession): Promise<void>;
|
|
9
|
+
destroyNativeAdFeed(options: NativeAdFeedSession): Promise<void>;
|
|
10
|
+
loadNativeAd(options: NativeAdLoadOptions): Promise<void>;
|
|
11
|
+
updateNativeAdPlacements(options: NativeAdPlacementBatch): Promise<void>;
|
|
12
|
+
removeNativeAd(options: NativeAdCommandIdentity): Promise<void>;
|
|
13
|
+
/** Android-only snapshot; does not change native visibility. */
|
|
14
|
+
captureNativeAdSnapshot?(options: NativeAdCommandIdentity): Promise<{
|
|
15
|
+
dataUrl: string;
|
|
16
|
+
}>;
|
|
17
|
+
/** Android-only: confirm that the appended image is ready for the next WebView draw. */
|
|
18
|
+
prepareNativeAdSnapshot?(options: NativeAdCommandIdentity): Promise<void>;
|
|
19
|
+
addListener(eventName: NativeAdPluginEvents, listenerFunc: (info: (NativeAdEvent | NativeAdErrorEvent | NativeAdRevenueEvent) & NativeAdFeedSession) => void): Promise<PluginListenerHandle>;
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-ad-definitions.interface.js","sourceRoot":"","sources":["../../../src/native-ads/native-ad-definitions.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const NATIVE_AD_ELEMENT_NAME = "capacitor-admob-native";
|
|
2
|
+
interface NativeAdElementFeed {
|
|
3
|
+
attach(slotKey: string, element: HTMLElement): void;
|
|
4
|
+
detach(element: HTMLElement): void;
|
|
5
|
+
}
|
|
6
|
+
type NativeAdFeedLookup = (feedId: string) => NativeAdElementFeed | undefined;
|
|
7
|
+
export declare const defineNativeAdElement: (findFeed: NativeAdFeedLookup) => void;
|
|
8
|
+
export declare const connectNativeAdElements: () => void;
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export const NATIVE_AD_ELEMENT_NAME = 'capacitor-admob-native';
|
|
2
|
+
export const defineNativeAdElement = (findFeed) => {
|
|
3
|
+
const runtime = globalThis;
|
|
4
|
+
runtime.__capacitorAdMobNativeFeedLookup = findFeed;
|
|
5
|
+
if (typeof customElements === 'undefined' || customElements.get(NATIVE_AD_ELEMENT_NAME)) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
customElements.define(NATIVE_AD_ELEMENT_NAME, class extends HTMLElement {
|
|
9
|
+
static get observedAttributes() {
|
|
10
|
+
return ['feed-id', 'slot-key'];
|
|
11
|
+
}
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
this.connectToFeed();
|
|
14
|
+
}
|
|
15
|
+
disconnectedCallback() {
|
|
16
|
+
this.disconnectFromFeed();
|
|
17
|
+
}
|
|
18
|
+
attributeChangedCallback() {
|
|
19
|
+
if (!this.isConnected) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this.disconnectFromFeed();
|
|
23
|
+
this.connectToFeed();
|
|
24
|
+
}
|
|
25
|
+
connectToFeed() {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
const feedId = (_a = this.getAttribute('feed-id')) === null || _a === void 0 ? void 0 : _a.trim();
|
|
28
|
+
const slotKey = (_b = this.getAttribute('slot-key')) === null || _b === void 0 ? void 0 : _b.trim();
|
|
29
|
+
const feed = feedId ? (_c = runtime.__capacitorAdMobNativeFeedLookup) === null || _c === void 0 ? void 0 : _c.call(runtime, feedId) : undefined;
|
|
30
|
+
if (!feed || !slotKey) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
try {
|
|
34
|
+
feed.attach(slotKey, this);
|
|
35
|
+
this.attachedFeed = feed;
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
this.dispatchEvent(new CustomEvent('nativeAdError', { bubbles: true, detail: error }));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
disconnectFromFeed() {
|
|
42
|
+
var _a;
|
|
43
|
+
(_a = this.attachedFeed) === null || _a === void 0 ? void 0 : _a.detach(this);
|
|
44
|
+
this.attachedFeed = undefined;
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
export const connectNativeAdElements = () => {
|
|
49
|
+
document
|
|
50
|
+
.querySelectorAll(NATIVE_AD_ELEMENT_NAME)
|
|
51
|
+
.forEach((element) => { var _a, _b; return (_b = (_a = element).connectToFeed) === null || _b === void 0 ? void 0 : _b.call(_a); });
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=native-ad-element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-ad-element.js","sourceRoot":"","sources":["../../../src/native-ads/native-ad-element.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,wBAAwB,CAAC;AAW/D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,QAA4B,EAAQ,EAAE;IAC1E,MAAM,OAAO,GAAG,UAAoC,CAAC;IACrD,OAAO,CAAC,gCAAgC,GAAG,QAAQ,CAAC;IACpD,IAAI,OAAO,cAAc,KAAK,WAAW,IAAI,cAAc,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE,CAAC;QACxF,OAAO;IACT,CAAC;IAED,cAAc,CAAC,MAAM,CACnB,sBAAsB,EACtB,KAAM,SAAQ,WAAW;QAGvB,MAAM,KAAK,kBAAkB;YAC3B,OAAO,CAAC,SAAS,EAAE,UAAU,CAAC,CAAC;QACjC,CAAC;QAED,iBAAiB;YACf,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;QAED,oBAAoB;YAClB,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC5B,CAAC;QAED,wBAAwB;YACtB,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;gBACtB,OAAO;YACT,CAAC;YACD,IAAI,CAAC,kBAAkB,EAAE,CAAC;YAC1B,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;QAED,aAAa;;YACX,MAAM,MAAM,GAAG,MAAA,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,0CAAE,IAAI,EAAE,CAAC;YACpD,MAAM,OAAO,GAAG,MAAA,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,0CAAE,IAAI,EAAE,CAAC;YACtD,MAAM,IAAI,GAAG,MAAM,CAAC,CAAC,CAAC,MAAA,OAAO,CAAC,gCAAgC,wDAAG,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YACrF,IAAI,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;gBACtB,OAAO;YACT,CAAC;YACD,IAAI,CAAC;gBACH,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;gBAC3B,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,CAAC,eAAe,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC;YACzF,CAAC;QACH,CAAC;QAEO,kBAAkB;;YACxB,MAAA,IAAI,CAAC,YAAY,0CAAE,MAAM,CAAC,IAAI,CAAC,CAAC;YAChC,IAAI,CAAC,YAAY,GAAG,SAAS,CAAC;QAChC,CAAC;KACF,CACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAS,EAAE;IAChD,QAAQ;SACL,gBAAgB,CAAc,sBAAsB,CAAC;SACrD,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,eAAC,OAAA,MAAA,MAAC,OAA2B,EAAC,aAAa,kDAAI,CAAA,EAAA,CAAC,CAAC;AAC1E,CAAC,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AdMobError, AdMobRevenueData } from '../shared';
|
|
2
|
+
import type { NativeAdIdentity } from './native-ad-options.interface';
|
|
3
|
+
export type NativeAdErrorEvent = NativeAdIdentity & AdMobError;
|
|
4
|
+
export type NativeAdRevenueEvent = NativeAdIdentity & AdMobRevenueData;
|
|
5
|
+
export type NativeAdEvent = NativeAdIdentity;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"native-ad-event.interface.js","sourceRoot":"","sources":["../../../src/native-ads/native-ad-event.interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { PluginListenerHandle } from '@capacitor/core';
|
|
2
|
+
import type { NativeAdDefinitions } from './native-ad-definitions.interface';
|
|
3
|
+
import type { NativeAdEvent, NativeAdErrorEvent, NativeAdRevenueEvent } from './native-ad-event.interface';
|
|
4
|
+
import type { NativeAdFeedOptions } from './native-ad-options.interface';
|
|
5
|
+
import type { NativeAdPluginEvents } from './native-ad-plugin-events.enum';
|
|
6
|
+
/**
|
|
7
|
+
* Manages native ad placement and lifecycle in a scrolling feed.
|
|
8
|
+
*
|
|
9
|
+
* A stable `slotKey`, rather than the element or array index, owns the native
|
|
10
|
+
* ad lifecycle. Virtual-scroller compatibility has not yet been validated.
|
|
11
|
+
*/
|
|
12
|
+
export declare class NativeAdFeed {
|
|
13
|
+
private readonly options;
|
|
14
|
+
private readonly nativeScrollElement?;
|
|
15
|
+
private readonly sessionId;
|
|
16
|
+
private readonly slots;
|
|
17
|
+
private readonly elementSlots;
|
|
18
|
+
private readonly scrollRoots;
|
|
19
|
+
private readonly intersectionObserver?;
|
|
20
|
+
private readonly resizeObserver?;
|
|
21
|
+
private destroyed;
|
|
22
|
+
private nativeStarted;
|
|
23
|
+
private paused;
|
|
24
|
+
private layoutInvalidated;
|
|
25
|
+
private placementFrame?;
|
|
26
|
+
private lastPlacements?;
|
|
27
|
+
private lastPlacementWasDirect;
|
|
28
|
+
private placementAcknowledgementRequired;
|
|
29
|
+
private settleTimer?;
|
|
30
|
+
private placementUpdateTask?;
|
|
31
|
+
private operationTask;
|
|
32
|
+
private destroyTask?;
|
|
33
|
+
private updateDirty;
|
|
34
|
+
private placementSequence;
|
|
35
|
+
private readonly listenerHandles;
|
|
36
|
+
private constructor();
|
|
37
|
+
static create(options: NativeAdFeedOptions): Promise<NativeAdFeed>;
|
|
38
|
+
get feedId(): string;
|
|
39
|
+
addListener(eventName: NativeAdPluginEvents.Loaded | NativeAdPluginEvents.Clicked | NativeAdPluginEvents.AdImpression | NativeAdPluginEvents.Opened | NativeAdPluginEvents.Closed, listener: (event: NativeAdEvent) => void): Promise<PluginListenerHandle>;
|
|
40
|
+
addListener(eventName: NativeAdPluginEvents.FailedToLoad, listener: (event: NativeAdErrorEvent) => void): Promise<PluginListenerHandle>;
|
|
41
|
+
addListener(eventName: NativeAdPluginEvents.AdPaid, listener: (event: NativeAdRevenueEvent) => void): Promise<PluginListenerHandle>;
|
|
42
|
+
attach(slotKey: string, element: HTMLElement): void;
|
|
43
|
+
detach(element: HTMLElement): void;
|
|
44
|
+
reload(slotKey: string): Promise<void>;
|
|
45
|
+
/** Immediately hides this feed's overlays until {@link resume} is called. */
|
|
46
|
+
pause(): Promise<void>;
|
|
47
|
+
/** Re-evaluates slots and restores eligible overlays after the viewport settles. */
|
|
48
|
+
resume(): void;
|
|
49
|
+
/** Hides stale overlays and remeasures after an application-driven layout change. */
|
|
50
|
+
invalidateLayout(): Promise<void>;
|
|
51
|
+
destroy(): Promise<void>;
|
|
52
|
+
private readonly handleViewportMotion;
|
|
53
|
+
private schedulePlacementUpdate;
|
|
54
|
+
private updateScrollRoots;
|
|
55
|
+
private readonly handleVisibilityChange;
|
|
56
|
+
private scheduleEvaluation;
|
|
57
|
+
private evaluate;
|
|
58
|
+
private loadState;
|
|
59
|
+
private evictUnusedAds;
|
|
60
|
+
private occupiesNativeAd;
|
|
61
|
+
private getVisibleStates;
|
|
62
|
+
private isSupportedSize;
|
|
63
|
+
private removeStateAd;
|
|
64
|
+
private runOperation;
|
|
65
|
+
private destroyResources;
|
|
66
|
+
private reuseProjectedPlacement;
|
|
67
|
+
private measurePlacement;
|
|
68
|
+
private requestPlacementUpdate;
|
|
69
|
+
private flushPlacementUpdates;
|
|
70
|
+
private assertActive;
|
|
71
|
+
}
|
|
72
|
+
export declare const configureNativeAdBridge: (adMobBridge: NativeAdDefinitions) => void;
|