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

addTapHandler after SwiftSpinner.show(delay: …) #97

Open
Pomanks opened this issue Jan 22, 2017 · 10 comments
Open

addTapHandler after SwiftSpinner.show(delay: …) #97

Pomanks opened this issue Jan 22, 2017 · 10 comments

Comments

@Pomanks
Copy link

Pomanks commented Jan 22, 2017

It would be great if you can change the following function func show(delay: Double, title: String, animated: Bool = true) to return a SwiftSpinner as other show functions to allow us adding a tapHandler after a specific delay…

I'm trying to find a workaround but couldn't make one working for now…

Is there a reason you didn't returned a SwiftSpinner with that specific function ?

If anyone has a solution, go ahead and tell me 👍

@aamck
Copy link
Contributor

aamck commented Jan 22, 2017

The demo project has lots of examples of this. Take a look at the code in viewWillAppear inside the ViewController.swift. It has lots of examples using a delays to call SwiftSpinner.show all of which could have the tapHandler bolted onto them if desired (and some of them do).

@Pomanks
Copy link
Author

Pomanks commented Jan 22, 2017

Yeah, I tried doing something like this :

`func showSpinner() {
    SwiftSpinner.show(NSLocalizedString("Presenter.noDelay", value:  "Connecting to server", comment: "Indicates that the application is connecting to the server"))

    SwiftSpinner.show(delay: 0.7, title: NSLocalizedString("Presenter.delayOf1.0", value:  "Fetching data from server", comment: "Indicates that the application is fetching the data from the server"))

    delay(seconds: 10.0, completion: {
        SwiftSpinner.show(NSLocalizedString("Presenter.delayOf10.0", value:  "Server is taking too long to respond or is'nt responding…", comment: "Indicates that the server is not responding properly"))
            .addTapHandler({
                SwiftSpinner.hide()
            }, subtitle: NSLocalizedString("TapHandler.comment", value: "You can tap the loader to dismiss it", comment: "Tells the user can tap to hide the loading spinner"))
    })
}

func delay(seconds: Double, completion: @escaping () -> ()) {
    let popTime = DispatchTime.now() + Double(Int64( Double(NSEC_PER_SEC) * seconds )) / Double(NSEC_PER_SEC)

    DispatchQueue.main.asyncAfter(deadline: popTime) {
        completion()
    }
}`

But even after calling this method
SwiftSpinner.hide({ SwiftSpinner.hideCancelsScheduledSpinners = true })

the spinner shows.. this is my biggest problem actually :/
It wouldn't if the delay function allowed me to add a tapHandler though.

@aamck
Copy link
Contributor

aamck commented Jan 22, 2017

Could you tidy that reply up, I think you'd double pasted some parts?

@Pomanks
Copy link
Author

Pomanks commented Jan 22, 2017

I'm calling this SwiftSpinner.hide({ SwiftSpinner.hideCancelsScheduledSpinners = true }) in another function not showed above.

For what's showed up there, I'm not duplicating any code cause I'm assigning different strings to the Spinner.

@aamck
Copy link
Contributor

aamck commented Jan 22, 2017

So your .addTapHandler({SwiftSpinner.hide()} block isn't hiding the spinner when the user taps?

@Pomanks
Copy link
Author

Pomanks commented Jan 22, 2017

Yes it does, but the

delay(seconds: 10.0, completion: { SwiftSpinner.show(NSLocalizedString("Presenter.delayOf10.0", value: "Server is taking too long to respond or is'nt responding…", comment: "Indicates that the server is not responding properly")) .addTapHandler({ SwiftSpinner.hide() }, subtitle: NSLocalizedString("TapHandler.comment", value: "You can tap the loader to dismiss it", comment: "Tells the user can tap to hide the loading spinner")) })

block is showing even after calling the .addTapHandler({SwiftSpinner.hide()} block..

(sorry I can't make it properly indented.. :/)

@aamck
Copy link
Contributor

aamck commented Jan 22, 2017

That's the same block of code I was referring too. In the code you've provided, that block will always be show. There is no check in between to see if it does actually need to be shown.

@Pomanks
Copy link
Author

Pomanks commented Jan 22, 2017

Okay.. I'll try to find a way then.. thanks for you help buddy :)

@aamck
Copy link
Contributor

aamck commented Jan 22, 2017

To break it down a little more clearly.

This is shown first:

SwiftSpinner.show(NSLocalizedString("Presenter.noDelay", value:  "Connecting to server", comment: "Indicates that the application is connecting to the server"))

Then this:

SwiftSpinner.show(delay: 0.7, title: NSLocalizedString("Presenter.delayOf1.0", value:  "Fetching data from server", comment: "Indicates that the application is fetching the data from the server"))

Then this:

delay(seconds: 10.0, completion: {
        SwiftSpinner.show(NSLocalizedString("Presenter.delayOf10.0", value:  "Server is taking too long to respond or is'nt responding…", comment: "Indicates that the server is not responding properly"))
            .addTapHandler({
                SwiftSpinner.hide()
            }, subtitle: NSLocalizedString("TapHandler.comment", value: "You can tap the loader to dismiss it", comment: "Tells the user can tap to hide the loading spinner"))
    })

That sequence will always run to the conclusion of the 'server is taking too long' stage. If you don't want that part showing, because your networking was a success, you need a check in place to prevent that. I would suggest breaking this up into separate parts and then only calling the bits you need at appropriate times in the blocks that handle your networking.

@Pomanks
Copy link
Author

Pomanks commented Jan 22, 2017

Thank you for your explanation, I may do as you suggest to answer my problem the best way :)

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

2 participants