BendingSpoons / tempura-swift

A holistic approach to iOS development, inspired by Redux and MVVM

Home Page:http://bendingspoons.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UINavigationController ...?

shinnokdisengir opened this issue · comments

Sto utilizzando da qualche giorno la vostra libreria BS Tempura e
non ho trovato il modo di utilizzare la transition push invece che la modal,
questo perche' non sono state inserite UINavigationController nell'alberatura.
Non ho trovato purtroppo una vostra implementazione della class citata prima e in pratica
non so se e' corretto aggiungerne una pagina "esterna" a tempura, o tendere
a non utilizzarla proprio. Nell'esempio, che e' forse un po' troppo stringato, si utilizza solamente la presentModal.
NB: Vorrei capire se la vostra filosofia e' effettivamente quella di gestire tutto con la RoutableWithConfiguration lasciando
perdere la navigazione classica
Grazie mille e buon lavoro
Gabriele

I've been using your BS Tempura library for a few days now.
I couldn't find a way to use transition push instead of modal,
that's because there's no UINavigationController in the tree.
Unfortunately I have not found an implementation of the above mentioned class of yours and in practice
I don't know if it's right to add an "external" page to tempura that implements it, or to tend to
not to use it at all. In the example, which is perhaps a bit too tight, you only use presentModal.
NB: I would like to understand if your philosophy is actually to manage everything with RoutableWithConfiguration by leaving
miss the classic navigation
Thank you very much
Gabriele

Ciao Gabriele.

It is perfectly valid to use UINavigationControllers or UITabBarControllers with Tempura. We do that in all of our apps.

Let me give an example of use.

Suppose we want:
A --> B --> C

and we want to show C with a push transition.

We have two options:

  1. still use a modal, but use a UIViewControllerTransitioningDelegate to supply a custom push animation to the modal.

  2. This is what you were asking. Wrap B with a UINavigationController and ask to push C instead of presenting it.

Let's focus on the 2.
When A is presenting B it wraps it in a UINavigationController.

extension A: RoutableWithConfiguration {
  var routeIdentifier: RouteElementIdentifier {
    return "A"
  }

  return [
    .show("B"): .presentModally { context in
      let b = B(store: self.store)
      let nav = UINavigationController(rootViewController: b)
      return nav
    }
  ]
}

To implement the push from B to C you can then use .custom:

extension B: RoutableWithConfiguration {
  var routeIdentifier: RouteElementIdentifier {
    return "B"
  }

  .show("C"): .custom({ _, _, animated, context, completion  in
        let c = C(store: self.store)
        self.navigationController?.pushViewController(c, animated: animated, completion: completion)
      })
}

We then conform C to routable:

extension C: Routable {
  var routeIdentifier: RouteElementIdentifier {
    return "C"
  }

Sorry for the late response.
Let me know if this is not clear or if you have more questions.