Skip to content

Commit eaf7e0e

Browse files
fix: correct rendering issue with Rokt placement holder
2 parents 39c40aa + 80db0b9 commit eaf7e0e

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

src/main/kotlin/com/mparticle/kits/RoktKit.kt

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import com.mparticle.kits.KitIntegration.IdentityListener
1616
import com.mparticle.kits.KitIntegration.RoktListener
1717
import com.mparticle.rokt.RoktEmbeddedView
1818
import com.rokt.roktsdk.Rokt
19+
import com.rokt.roktsdk.RoktWidgetDimensionCallBack
1920
import com.rokt.roktsdk.Widget
2021
import java.lang.ref.WeakReference
2122
import java.math.BigDecimal
@@ -127,12 +128,30 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
127128
fontTypefaces: MutableMap<String, WeakReference<Typeface>>?,
128129
filterUser: FilteredMParticleUser?
129130
) {
130-
// Converting the placeholders to a Map<String, WeakReference<Widget>> by filtering and casting each entry
131131
val placeholders: Map<String, WeakReference<Widget>>? = placeHolders?.mapNotNull { entry ->
132-
val weakRef = entry.value
133-
val widget = weakRef.get() as? Widget // Safe cast to Widget
134-
widget?.let { entry.key to weakRef as WeakReference<Widget> } // Only include if it's a Widget
132+
val widget = Widget(entry.value.get()?.context as Context)
133+
entry.value.get()?.removeAllViews()
134+
entry.value.get()?.addView(widget)
135+
entry.value.get()?.dimensionCallBack?.let {
136+
widget.registerDimensionListener(object: RoktWidgetDimensionCallBack {
137+
override fun onHeightChanged(height: Int) {
138+
it.onHeightChanged(height)
139+
}
140+
141+
override fun onMarginChanged(
142+
start: Int,
143+
top: Int,
144+
end: Int,
145+
bottom: Int
146+
) {
147+
it.onMarginChanged(start, top, end, bottom)
148+
}
149+
150+
})
151+
}
152+
entry.key to WeakReference(widget)
135153
}?.toMap()
154+
136155
this.mpRoktEventCallback = mpRoktEventCallback
137156
val finalAttributes: HashMap<String, String> = HashMap<String, String>()
138157
filterUser?.userAttributes?.let { userAttrs ->
@@ -141,11 +160,10 @@ class RoktKit : KitIntegration(), CommerceListener, IdentityListener, RoktListen
141160
}
142161
}
143162

144-
filterUser?.id?.let { mpid ->
145-
finalAttributes.put(MPID, mpid.toString())
146-
} ?: run {
147-
Logger.warning("RoktKit: No user ID available for placement")
148-
}
163+
filterUser?.id?.toString()?.let { mpid ->
164+
finalAttributes[MPID] = mpid
165+
} ?: Logger.warning("RoktKit: No user ID available for placement")
166+
149167
addIdentityAttributes(finalAttributes, filterUser)
150168

151169
Rokt.execute(

0 commit comments

Comments
 (0)