Skip to content
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

Video ads often not start playing in SwiftUI #247

Open
mrbodich opened this issue May 22, 2024 · 1 comment
Open

Video ads often not start playing in SwiftUI #247

mrbodich opened this issue May 22, 2024 · 1 comment
Assignees

Comments

@mrbodich
Copy link

mrbodich commented May 22, 2024

I have implemented Teads through SwiftUI.
Some video ads or scroll-to-animate ads are not starting playing most of view presentations if I scroll the list from the bottom.
I mean if the list was loaded with 0 offset and I scroll from the top, videos work well. But if the list was pre-scrolled at some deeper point, and I slowly scroll back to the top, the banner appears, the progress bar is progressing but no video.
If I return bannerView in one line of code directly in makeUIView(context:) and do nothing in updateUIView then it works like described.
If I set up the TeadsInReadAdView in the updateUIView(_ uiView:) it works in similar way, but what's the same is empty video when I scroll from the bottom (as I said, if the list was presented with immediately pre-defined offset deeper than the Teads Ad cell).

Scrolling from the bottom — Empty video
Scrolling from the top — Video exists and playing
As we see, the Ad UIView is presented successfully, we see the title and the progress bar.

Screenshot 2024-05-22 at 13 41 46 Screenshot 2024-05-22 at 13 42 25

In the attached code below:

The bannerView property which is passed here is coming from the Ads Loader.
More often it's passed from cache already pre-loaded, in the provided case I've tested pre-loaded, so the TeadsInReadAdView is available immediately when the SwiftUI view is presented.

I've tried a lot of variations, setting constraints manually or not, with all that layout methods called or no or variations.
It works more stable when I directly return bannerView in makeUIView(context:) but in some specific cases no.

@MainActor
struct TeadsBannerView: UIViewRepresentable {
    let bannerView: TeadsInReadAdView
    
    func makeUIView(context: Context) -> UIView {
        return UIView()
    }
    
    func updateUIView(_ uiView: UIView, context: Context) {
        uiView.addSubview(bannerView)
        bannerView.translatesAutoresizingMaskIntoConstraints = false
        NSLayoutConstraint.activate([
            bannerView.topAnchor.constraint(equalTo: uiView.topAnchor),
            bannerView.bottomAnchor.constraint(equalTo: uiView.bottomAnchor),
            bannerView.leadingAnchor.constraint(equalTo: uiView.leadingAnchor),
            bannerView.trailingAnchor.constraint(equalTo: uiView.trailingAnchor),
        ])
        bannerView.setNeedsLayout()
        bannerView.layoutIfNeeded()
        bannerView.layoutSubviews()
    }
}

// Another version
@MainActor
struct TeadsBannerView: UIViewRepresentable {
    let bannerView: TeadsInReadAdView
    
    func makeUIView(context: Context) -> TeadsInReadAdView {
        return bannerView
    }
    
    func updateUIView(_ uiView: TeadsInReadAdView, context: Context) { }
}

Have no idea how to solve that, maybe you can take a look and find the right direction?
I believe there is some issue in the TeadsInReadAdView life cycle, it is missing some update trigger when it should be triggered.

@github-lucas-bon
Copy link
Contributor

Hello @mrbodich thanks for sharing it.
Could you provide the ad response (which you could get using Charles/Proxyman)? If possible provide a video as well of the issue happening.
What you mean with scroll-to-animate ads?
Do you have any animation in place when expanding the ad slot to display it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants