Upgrade to Pro — share decks privately, control downloads, hide ads and more …

深いい勉強会 The Navigation Component

深いい勉強会 The Navigation Component

FujiKinaga

July 02, 2018
Tweet

More Decks by FujiKinaga

Other Decks in Programming

Transcript

  1. 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.
  2. Variety of actions ɾTo Destination ɾTo Self ɾReturn To Source

    (popUpTo ✗✗) ɾGlobal + Transitions + Arguments + LaunchOptions
  3. 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
  4. When use BottomNavigation’s extension • σϑΥϧτΞχϝʔγϣϯ෇͖ • menu.xmlͷidͱnavigation.xmlͷidΛ ಉ͡ʹ͢Δ͜ͱͰ࿈݁͞ΕΔ •

    όοΫϘλϯΛԡ͢ͱStartDestination ʹઃఆ͞ΕͨFragment(͜͜Ͱ͸Home) ΁ભҠ͞ΕΔ • λϒҠಈͷͨͼʹclearTask͍ͯ͠ΔΠ ϝʔδ • DrawerLayout΍NavigationViewͷ extension΋͋Δ
  5. When use Nested Graph • Navigation in NavigationΛ࡞Δ͜ͱ͕Ͱ ͖Δ •

    طଘͷActivityભҠΛॻ͖׵͑Δͱ͖ʹε ςοϓͱͯ͠࢖͑Δ • BottomNavigationͱͷ࿈ܞͰ͸fragment ͷid͚ͩͰͳ͘ɺnavigationͷid΋ઃఆͰ ͖Δ • ωετͳNavigation͝ͱʹϑΝΠϧ෼ׂ΋ Մೳ(<incude>λάͰ࣋ͬͯ͜ΕΔ)
  6. When use it with ViewModel • ViewModelͷॳճΦϒδΣΫτऔಘ࣌ʹFragmentͷ ContextΛ౉ͨ͠৔߹ɺnavigateͷλΠϛϯάͰഁغ͞ΕΔ • ActivityͷContextΛ౉ͨ͠৔߹͸ɺFragment͕੾ΓସΘͬ

    ͯ΋ੜ͖ଓ͚Δ(=σʔλͷ෮ݩ͕Մೳ) • ಉ͡Fragment͕ͩɺத਎ͷσʔλ͕ҟͳΔ৔߹ʹ ViewModelͷ؅ཧ͕໘౗ͦ͏(ݕࡧɺϓϩϑΟʔϧɺϓϨΠ ϠʔͳͲ)
  7. When use it with RecyclerView • Stackʹ͋ΔFragment΁ͷpopͰ͋Ε ͹ɺεΫϩʔϧҐஔ͕อ࣋͞Εͨঢ়ଶ Ͱ໭ͬͯ͘Δ͜ͱ͕Մೳ •

    ϝϯόม਺΋อ࣋͞Εͨঢ়ଶͰ෮ݩ͞ ΕΔ • ಺෦తʹ͸addToBackStack͕ݺ͹Ε ͳ͕Βreplace͞Ε͍ͯͦ͏ • Paging LibraryͱҰॹʹ࢖ͬͯΈ͍ͨ • NestedScrollView͸εΫϩʔϧҐஔ ͕อ࣋͞Ε͍ͯͳ͔ͬͨ
  8. 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.