GithubHelp home page GithubHelp logo

Comments (2)

tabuna avatar tabuna commented on August 30, 2024

I have a not perfect solution. In the idea, I was supposed to use the observer to track the wkwebview.

But I did through a timer:

var needShowSpash: Bool = true

final class ViewController: VisitableViewController, ErrorPresenter {

    public var startTimerLoader: Timer?
    public var spashImage: UIImageView?

    override func viewDidLoad() {
        super.viewDidLoad()

        self.startLoadingAnimate()
    }

    func startLoadingAnimate() {
        if needShowSpash == false {
            return
        }

        let image = UIImage(named: "Splash")
        self.spashImage = UIImageView(image: image)
        self.spashImage!.frame = UIScreen.main.bounds

        self.view.addSubview(self.spashImage!)

        self.startTimerLoader = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(ViewController.checkLoadingPageForHiddenSpash), userInfo: nil, repeats: true)
    }

    @objc func checkLoadingPageForHiddenSpash() {
        if visitableView.webView?.estimatedProgress ?? 0.0 < 0.9 {
            return
        }

        self.startTimerLoader?.invalidate()
        self.startTimerLoader = nil
        needShowSpash = false

        UIView.transition(with: self.spashImage!,
                          duration: 0.5,
                          options: .transitionCrossDissolve,
                          animations: {self.spashImage!.alpha = 0},
                          completion: {_ in self.spashImage!.removeFromSuperview()}
        )
    }
}

If anyone has any suggestions on how to improve this would be great.

from turbo-ios.

joemasilotti avatar joemasilotti commented on August 30, 2024

Can you hook into the SessionDelegate to learn when the first network request has completed? For example:

extension ViewController: SessionDelegate {
    func sessionDidFinishRequest(_ session: Session) {
        if view.subviews.contains(splashImage) {
            splashImage.removeFromSuperview()
        }
    }
}

from turbo-ios.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.