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

Loading state is not a initial state? #52

Open
kidsid-Ixigo opened this issue Mar 21, 2017 · 4 comments
Open

Loading state is not a initial state? #52

kidsid-Ixigo opened this issue Mar 21, 2017 · 4 comments

Comments

@kidsid-Ixigo
Copy link

When I open my view controller I can see my empty view momentarily then it switches back to loading state. How to avoid that? Either you introduce a new "Initial State" or make Loading state by default state.

@douglasd3
Copy link

douglasd3 commented Apr 4, 2017

I always face this issue when showing empty states, and always came to a different workaround.
You can try to set your loading when the VC disappears, when you have an empty state to show:

    override func viewDidDisappear(_ animated: Bool) {
        super.viewDidDisappear(animated)
   
        if !hasContent() {
            startLoading()
        }
    }

It worked for me.

@aschuch
Copy link
Owner

aschuch commented May 15, 2017

I am unable to reproduce this issue. The example project calls startLoading() from viewWillAppear to make sure the loading state is shown immediately.

@FWJonathan
Copy link

FWJonathan commented Jun 29, 2017

I think this may be the same issue I was seeing here (and I am seeing again): #47

Since the view presentation is being pushed to a subsequent run loop with DispatchQueue.main.sync(), perhaps it is undefined as to whether it occurs in time to mask the content view? I personally only see the issue intermittently.

As I suggested before, you could guarantee that this can't happen in the viewWillAppear scenario by doing something like this in transitionToState(...):

if Thread.isMainThread {
      ...
} else {
   DispatchQueue.main.sync() {
      ...
   }
}

@FWJonathan
Copy link

However, again I notice that the issue is complicated further by the async queue call, which sounds like it could be the more likely culprit, i.e. we have no idea when this code will be executed in relation to the content view's presentation on the main thread.

Perhaps if animated == false and the queue is empty, the presentation should just happen 'now' on the main thread?

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

4 participants