Skip to content

Loading state is not a initial state?  #52

Open

Description

@kidsid-Ixigo

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.

Activity

  1. douglasd3 commented on Apr 4, 2017

    @douglasd3

    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.

  2. aschuch commented on May 15, 2017

    @aschuch
    Owner

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

  3. FWJonathan commented on Jun 29, 2017

    @FWJonathan

    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() {
          ...
       }
    }
  4. FWJonathan commented on Jun 29, 2017

    @FWJonathan

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions