Slide 1

Slide 1 text

NavigationΛ৮ͬͯΈͨ ਂ͍͍ษڧձ vol.5
 Fuji

Slide 2

Slide 2 text

What’s Navigation • A part of Android Architecture Component. • Current version is Alpha02. • A little like xCode’s StoryBoard. • We don’t need to use FragmentTransaction! • Don’t crash by IllegalStateException. • Automatically stack management (For better or for worse). • Deep linking, Safe args, NavigateUp safety, Transaction animation easily, …etc.

Slide 3

Slide 3 text

How to use !?

Slide 4

Slide 4 text

How to use 2 Fragment Action

Slide 5

Slide 5 text

Variety of actions ɾTo Destination ɾTo Self ɾReturn To Source (popUpTo ✗✗) ɾGlobal + Transitions + Arguments + LaunchOptions

Slide 6

Slide 6 text

What’s happen? • When use BottomNavigation’s extension • When use Nested Graph • When use it with ViewModel • When use it with RecyclerView • When use Global navigation

Slide 7

Slide 7 text

When use BottomNavigation’s extension • σϑΥϧτΞχϝʔγϣϯ෇͖ • menu.xmlͷidͱnavigation.xmlͷidΛ ಉ͡ʹ͢Δ͜ͱͰ࿈݁͞ΕΔ • όοΫϘλϯΛԡ͢ͱStartDestination ʹઃఆ͞ΕͨFragment(͜͜Ͱ͸Home) ΁ભҠ͞ΕΔ • λϒҠಈͷͨͼʹclearTask͍ͯ͠ΔΠ ϝʔδ • DrawerLayout΍NavigationViewͷ extension΋͋Δ

Slide 8

Slide 8 text

When use Nested Graph • Navigation in NavigationΛ࡞Δ͜ͱ͕Ͱ ͖Δ • طଘͷActivityભҠΛॻ͖׵͑Δͱ͖ʹε ςοϓͱͯ͠࢖͑Δ • BottomNavigationͱͷ࿈ܞͰ͸fragment ͷid͚ͩͰͳ͘ɺnavigationͷid΋ઃఆͰ ͖Δ • ωετͳNavigation͝ͱʹϑΝΠϧ෼ׂ΋ Մೳ(λάͰ࣋ͬͯ͜ΕΔ)

Slide 9

Slide 9 text

When use Nested Graph ಈը͕ੌ͘Θ͔ΓͮΒ͍Ͱ͕͢ɺ
 ཁ͸ɺͰғ͏ͱಉ͡ΧςΰϦ
 ͱͯ͠ѻΘΕΔͱ͍͏͜ͱͰ͢

Slide 10

Slide 10 text

When use it with ViewModel • ViewModelͷॳճΦϒδΣΫτऔಘ࣌ʹFragmentͷ ContextΛ౉ͨ͠৔߹ɺnavigateͷλΠϛϯάͰഁغ͞ΕΔ • ActivityͷContextΛ౉ͨ͠৔߹͸ɺFragment͕੾ΓସΘͬ ͯ΋ੜ͖ଓ͚Δ(=σʔλͷ෮ݩ͕Մೳ) • ಉ͡Fragment͕ͩɺத਎ͷσʔλ͕ҟͳΔ৔߹ʹ ViewModelͷ؅ཧ͕໘౗ͦ͏(ݕࡧɺϓϩϑΟʔϧɺϓϨΠ ϠʔͳͲ)

Slide 11

Slide 11 text

When use it with RecyclerView • Stackʹ͋ΔFragment΁ͷpopͰ͋Ε ͹ɺεΫϩʔϧҐஔ͕อ࣋͞Εͨঢ়ଶ Ͱ໭ͬͯ͘Δ͜ͱ͕Մೳ • ϝϯόม਺΋อ࣋͞Εͨঢ়ଶͰ෮ݩ͞ ΕΔ • ಺෦తʹ͸addToBackStack͕ݺ͹Ε ͳ͕Βreplace͞Ε͍ͯͦ͏ • Paging LibraryͱҰॹʹ࢖ͬͯΈ͍ͨ • NestedScrollView͸εΫϩʔϧҐஔ ͕อ࣋͞Ε͍ͯͳ͔ͬͨ

Slide 12

Slide 12 text

Conclusion

Slide 13

Slide 13 text

Conclusion • I’m waiting for SingleTask launch option for stack management such as Instagram. • Few cost, few merits. • I recommend to introduce by limited usage.
 - Use safe args only.
 - Use in Deep linking only.
 - Use it where you want to pop at a specific stack position. • Be to convenient in stable version.