Customize loading state
There is a way to customize how FuseAdView
behaves while a new ad is loading.
You can provide loadingBehaviour
parameter when creating a new instance of FuseAdView
.
Display Loading Spinner
When this option is selected, default animated loading spinner is displayed in the middle of the view while a new ad is loading.
Android:
val adView = FuseAdView(
context,
code = "zone_code",
loadingBehaviour = FuseAdViewBehaviour.ProgressBar,
)
iOS:
let adView = FuseAdView(
code: "zone_code",
loadingBehaviour: .progressBar,
)
Display Placeholder Image
When this option is selected, a provided image is displayed in the middle of the view while a new ad is loading.
NOTE: If the image is bigger than FuseAdView
, it will be adjusted to fit the bounds, if it is smaller - it will be rendered as is.
Android:
val image = AppCompatResources.getDrawable(context, <image_resource>)
val adView = FuseAdView(
context,
code = "zone_code",
loadingBehaviour = FuseAdViewBehaviour.Background(image),
)
iOS:
let image = UIImage(named: "<image_resource>")
let adView = FuseAdView(
code: "zone_code",
loadingBehaviour: .background(image: image)
)
Hide While Loading
When this option is selected, a view will be completely hidden while a new ad is loading.
val adView = FuseAdView(
context,
code = "zone_code",
loadingBehaviour = FuseAdViewBehaviour.Hide,
)
iOS:
let adView = FuseAdView(
code: "zone_code",
loadingBehaviour: .hide,
)
Display Custom View
When this option is selected, a provided closure is used to build an arbitrary view which is then placed inside FuseAdView
.
val loadingBehaviour = FuseAdViewBehaviour.CustomView(
viewBuilder = { ctx, parent ->
TextView(ctx).apply {
text = "Loading"
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
)
}
},
)
val adView = FuseAdView(
context,
code = "zone_code",
loadingBehaviour = loadingBehaviour,
)
// Compose
ComposeFuseAdView(
code = "zone_code",
loadingBehaviour = loadingBehaviour,
)
NOTE: layoutParams
will define how custom view will be laid out inside FuseAdView
. Irrespective of custom view size, the height of FuseAdView
will not change and will remain based on the requested ad sizes, unless the size is dynamic (fluid or native). In this case FuseAdView
will adopt the height of the custom view provided.
iOS:
private func buildCustomView() -> UIView {
let label = UILabel()
label.text = "Loading"
label.textAlignment = .center
return label
}
let adView = FuseAdView(
code: "zone_code",
loadingBehaviour: .customView(viewBuilder: buildCustomView)
)
// SwiftUI
FuseAdViewRepresentable(
code: "zone_code",
loadingBehaviour: .customView(viewBuilder: buildCustomView)
)
NOTE: On iOS the custom view is pinned to all the sides of FuseAdView
. If the zone uses fixed ad sizes, then FuseAdView
will adopt the height of the largest ad size and the custom view will be centred inside it. If the zone uses dynamic ad sizes (fluid or native) then FuseAdView
will adopt the height of the custom view provided.
Global Settings
loadingBehaviour
parameter is optional. If it is not provided, default value will be taken from the FuseSDK
object.
If you want to provide default behaviour which would be applied to all FuseAdView
s across the app, set the following value on the FuseSDK
object:
Android:
FuseSDK.defaultLoadingBehaviour = FuseAdViewBehaviour.ProgressBar
iOS:
FuseSDK.shared.defaultLoadingBehaviour = .progressBar
If this value is not provided, it will default to do nothing.