Presentation is loading. Please wait.

Presentation is loading. Please wait.

Use conductor instead Gergely Szőke | Wanari

Similar presentations


Presentation on theme: "Use conductor instead Gergely Szőke | Wanari"— Presentation transcript:

1 Use conductor instead Gergely Szőke | Wanari
Get rid of Fragments Use conductor instead Gergely Szőke | Wanari

2 Fragments Problems Support or not Transaction is complicated
Backstack management is complicated

3 Conductor can be the solution
View-based Provides wrapper around views Works almost the same as Fragments Easier lifecycle It has 4 main parts: Controller Router ControllerChangeHandler ControllerTransaction

4 Controller The Controller is the View wrapper that will give you all of your lifecycle management features. Think of it as a lighter-weight and more predictable Fragment alternative with an easier to manage lifecycle.

5 Router A Router implements navigation and backstack handling for Controllers. Router objects are attached to Activity/containing ViewGroup pairs. Routers do not directly render or push Views to the container ViewGroup, but instead defer this responsibility to the ControllerChangeHandler specified in a given transaction. It has several methods to work with the backstack (changehandlers also can added): popToRoot popToTag (RouterTransaction can be tagged) popCurrent setBackStack(!)

6 ControllerChangeHandler
ControllerChangeHandlers are responsible for swapping the View for one Controller to the View of another. They can be useful for performing animations and transitions between Controllers. Several default ControllerChangeHandlers are included. You just have to add push-, and popChangeHandlers to the router

7 ControllerTransaction
Transactions are used to define data about adding Controllers. RouterControllerTransactions are used to push a Controller to a Router with specified ControllerChangeHandlers, while ChildControllerTransactions are used to add child Controllers.

8 LifeCycle

9 In action

10 Activity Works the same as usual
You have to create a Router instance providing a container ViewGroup (same as the previous fragmentContainer FrameLayout) Set a root Controller to the router Pass onBackPressed events to the router if it returns false, then leave it to super

11 Controller You have to implement only the onCreateView method
But you have several others like Fragments does Worth to mention: onChangeStarted, onChangeEnded You can handle the the UI during transactions (for example disable, and reenable buttons) You can also handle the optionsMenu from a controller From a controller you can get the activity’s router, to navigate

12 Nested Controllers Controllers can be nested with ChildRouters
It needs a container too There is an optional setting, setPopLastView (default false) If you set it to true, then the child root itself can be popped separately, othervise it pops with the parent controller If you would like to connect two controllers like „onResult” you can setTargetController to the specified controller (the target controller is retained)

13 About memory things There are two options for controllers, to handle destructive lifecycle events, when to release: ReleaseDetach (default): releases when Detach happens RetainDetach: retains on Detach, but still release on config change Example: If you set on your rootController the RetainDetach mode, then if you navigate back to it, this won’t be recreated

14 Mosby There is a mosby extension for Conductor, therefore you can use the classic MVP architecture Only one thing to mention, Presenter is instantiated before onAttach, so this is the first place where you can use it

15 Keep in touch! https://twitter.com/TeamWanari

16 Resources https://github.com/bluelinelabs/Conductor


Download ppt "Use conductor instead Gergely Szőke | Wanari"

Similar presentations


Ads by Google