Skip to content

Loaf is shown only first time #18

@petrovi4

Description

@petrovi4

I have here is such code

private func showNotification() {
  if !Thread.isMainThread {
    DispatchQueue.main.async { self.showNotification() }
    return
  }

  guard  let rootVC = UIApplication.topViewController() else {
    print(">>> No root view controller defined")
    return
  }
	
  Loaf("Importing ...", sender: rootVC).show()
}

where function topViewController (extension of UIApplication) return top-level current view controller

static func topViewController(base: UIViewController? = UIApplication.shared.delegate?.window??.rootViewController) -> UIViewController? {
  if let nav = base as? UINavigationController {
    return topViewController(base: nav.visibleViewController)
  }
		
  if let tab = base as? UITabBarController, let selected = tab.selectedViewController {
    return topViewController(base: selected)
  }
		
  if let presented = base?.presentedViewController {
    return topViewController(base: presented)
  }
		
  return base
}

Here's the problem: if I call showNotification multiple times, then the Loaf is shown only once - the first time.
After the first Loaf has disappeared all subsequent calls to Loaf(...).show() lead to nothing

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