Giter Site home page Giter Site logo

Comments (5)

dduan avatar dduan commented on August 25, 2024

Hi @alperkal, thanks!

Let's see, does the progress view update if you set it on a timer? Something like this

var percent: Double = 0
let timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
    print(count)
    self.progressView.setProgress(percent, animated: false)
    count += 0.1
}

from just.

alperkal avatar alperkal commented on August 25, 2024

yes, progressView does update when triggered via a timer:

        var count = 0.0
        _ = Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { _ in
            print(count)
            self.progressView.setProgress(Float(count), animated: false)

            count += 0.1
        }

from just.

alperkal avatar alperkal commented on August 25, 2024

BTW, I haven't extracted the code from an existing big project. That was the most basic view Controller running in a clean project.

import UIKit
import Just
class ViewController: UIViewController {

    @IBOutlet weak var progressView: UIProgressView!
    @IBOutlet weak var button: UIButton!

    @IBAction func buttonClicked(_ sender: AnyObject) {
        let sampleFile = Bundle.main.url(forResource: "sample", withExtension: "jpg")!
        Just.post("https://httpbin.org/post",
                                     files:["sample": .url(sampleFile, nil)],
                                     asyncProgressHandler:{ p in
                                        print(p.percent)
                                        DispatchQueue.main.async(execute: {
                                            self.progressView.setProgress(p.percent, animated: false)
                                        })
            })
       print("Complete!!")
    }
}

from just.

alperkal avatar alperkal commented on August 25, 2024

ok, I got it working finally. I don't know why it only works like this:

 Just.post("https://httpbin.org/post",
                                     files:["sample": .url(sampleFile, nil)],
                                     asyncProgressHandler:{ p in
                                        print(p.percent)
                                        DispatchQueue.main.async(execute: {
                                            self.progressView.setProgress(p.percent, animated: false)
                                        })

        }){ r in
         print(r.ok)
        }

Looks like UI gets updates only if the call is issued asychronously

from just.

dduan avatar dduan commented on August 25, 2024

When Just work synchronously, it needs to block on current thread. If it blocks on the main thread, then any other operation dispatched onto the main thread won't execute until the network is finished. The print statement works because it's not on main thread.

from just.

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.