Pro Yearly is on sale from $80 to $50! »

AndroidX Navigationを導入した話 / Introducing AndroidX Navigation

AndroidX Navigationを導入した話 / Introducing AndroidX Navigation

E505897a79eede1a676f92740261e8f8?s=128

Masatoshi Kubode

February 28, 2019
Tweet

Transcript

  1. ©2019 Wantedly, Inc. "OESPJE9/BWJHBUJPO Λಋೖͨ͠࿩ QPUBUPUJQT ٱอग़խढ़ 2019/02/28

  2. ©2019 Wantedly, Inc. ٱอग़խढ़ 8BOUFEMZ ओʹ8BOUFEMZ7JTJUͷ"OESPJEΞϓϦΛ։ൃ͍ͯ͠·͢ɻ ઈࢍϦχϡʔΞϧதɻ QPUBUPUJQT͸ճ࿈ଓग़৔தɻ ,PUMJO 1PLFNPO(P

    ࣗݾ঺հ 5XJUUFS !TXJ[@BSE (JU)VC !LVCPEF
  3. ©2019 Wantedly, Inc.  "OESPJE9/BWJHBUJPOͱ͸  ͳͥಋೖͨ͠ͷ͔  ࣮૷ 

    ൃੜͨ͠໰୊఺  ·ͱΊ ࿩͢͜ͱ
  4. ©2019 Wantedly, Inc. "OESPJE9/BWJHBUJPOͱ͸

  5. ©2019 Wantedly, Inc. w "OESPJE9ͷͻͱͭ w چ /BWJHBUJPO$PNQPOFOUT w ͦΖͦΖTUBCMF

    ݱ࣌఺Ͱ3$  w TUBCMFʹͳΔͱਖ਼ࣜʹ"OESPJE9ʹͳͬͯഁյత มߋ͕͋Δ͔΋ AndroidX Navigationͱ͸
  6. ©2019 Wantedly, Inc. w (6*ͰͷભҠਤ w 9.-Ͱ΋هड़Մ ػೳ

  7. ©2019 Wantedly, Inc. w ը໘Ҿ਺ w 4BGF"SHTͰͷܕ҆શͳ
 'SBHNFOU"SHTͷੜ੒ w %FFQ-JOLରԠ

    w 5SBOTJUJPO"OJNBUJPO w 4IBSFE&MFNFOU ػೳ
  8. ©2019 Wantedly, Inc. w BSHVNFOUͷΫϥεΛੜ੒͢Δ(SBEMF1MVHJO w ܕ҆શʹͳΔ w 'SBHNFOUOFX*OTUBODFͱ͔࡞Βͳͯ͘Α͍ w

    /BWJHBUJPO࢖Θͣ͜Ε͚ͩΛಋೖ͢Δέʔε΋ SafeArgs apply plugin: "androidx.navigation.safeargs.kotlin"
  9. ©2019 Wantedly, Inc. ͳͥಋೖͨ͠ͷ͔

  10. ©2019 Wantedly, Inc. w ΦϯϘʔσΟϯάΛϦχϡʔΞϧ w "DUJWJUZͰϑϩʔΛ؅ཧ w ෳ਺ͷը໘͸'SBHNFOUͰ࡞Δ ͳͥಋೖͨ͠ͷ͔

  11. ©2019 Wantedly, Inc. OnboardingActivity ϑϩʔͷߏ੒ InitialFragment WelcomeFragment SelectOccupationFragment MainActivity

  12. ©2019 Wantedly, Inc. w ৚݅෼ذ͕
 ͋Δ w ύϥϝʔλʔ
 ͷड͚౉͠ w

    جຊతʹ
 Ұํ௨ߦ ࣮ࡍͷϑϩʔ
  13. ©2019 Wantedly, Inc. w ΞϓϦશମͷϦχϡʔΞϧΛਐΊ͍ͯΔ w .VMUJNPEVMFԽ͍ͯ͠Δ w 'FBUVSFؒͷը໘ભҠΛͲ͏͢Δ͔ w

    ˠ%SPJE,BJHJͷ࣮૷͕ࢀߟʹͳΓͦ͏ w ˠ/BWJHBUJPOΛࢼ͍ͨ͠ ଞͷಋೖཧ༝
  14. ϖʔδλΠτϧ ϖʔδαϒλΠτϧ ©2019 Wantedly, Inc. /BWJHBUJPO΍Δͧ

  15. ©2019 Wantedly, Inc. ࣮૷

  16. ©2019 Wantedly, Inc.  ۭͷ'SBHNFOUΫϥεΛ͢΂ͯ࡞Δ  SFTOBWJHBUJPOOBWJHBUJPOYNMΛ࡞Δ  (6*Ͱը໘Λ഑ஔ 

    "DUJWJUZʹ/BW)PTU'SBHNFOUΛ഑ஔ  'SBHNFOUͰ/BW$POUSPMMFSOBWJHBUFΛॻ͘ ࣮૷ͷྲྀΕ
  17. ©2019 Wantedly, Inc. ը໘ͷ഑ஔ

  18. ©2019 Wantedly, Inc. ભҠΛͭͳ͛Δ

  19. ©2019 Wantedly, Inc. NavHostFragmentͷ഑ஔ <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent"

    > <fragment android:id="@+id/nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" android:layout_width="match_parent" android:layout_height="match_parent" app:defaultNavHost="true" app:navGraph="@navigation/onboarding_navigation" /> </androidx.coordinatorlayout.widget.CoordinatorLayout>
  20. ©2019 Wantedly, Inc. NavController.navigateͰભҠ // InitialFragment override fun onSignUpSuccessful(userName: String)

    { findNavController() // KTXͷ֦ு .navigate( // safeargsͰੜ੒͞Εͨίʔυ InitialFragmentDirections .actionInitialFragmentToEmailWelcomeFragment(userName) ) }
  21. ©2019 Wantedly, Inc. ൃੜͨ͠໰୊఺

  22. ©2019 Wantedly, Inc. w όοΫΩʔͰ໭Εͯ͠·͏ w ը໘͝ͱʹঢ়ଶΛ͍࣋ͬͯΔͷͰ໭ΔͱόάΔ w 1PQ#FIBWJPSͰ໭Γઌ͸ࢦఆͰ͖Δ͕ɾɾɾ w

    ໭Βͤͳ͘͢Δ͜ͱ͸/BWJHBUJPOͰ͸Ͱ͖ͳ͍ ໰୊఺1
  23. ϖʔδλΠτϧ ϖʔδαϒλΠτϧ ©2019 Wantedly, Inc. "OESPJE9"DUJWJUZ

  24. ©2019 Wantedly, Inc. w BEE0O#BDL1SFTTFE$BMMCBDL͕௥Ճ w όοΫΩʔ੍ޚΛ'SBHNFOUͰ࣮૷Ͱ͖Δ AndroidX Activity //

    WelcomeFragment override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) // Disable back key requireActivity().addOnBackPressedCallback( viewLifecycleOwner, OnBackPressedCallback { true } ) }
  25. ©2019 Wantedly, Inc. ൃੜͨ͠໰୊఺

  26. ©2019 Wantedly, Inc. w pUT4ZTUFN8JOEPXT
 ͕ޮ͔ͳ͍ w /BW)PTU'SBHNFOU͕
 'SBNF-BZPVUΛ࢖͍ͬͯΔ w

    'SBNF-BZPVU͸
 pUT4ZTUFN8JOEPXT͕ޮ͔ͳ͍ ໰୊఺2
  27. ©2019 Wantedly, Inc. ໰୊఺2ͷղܾࡦ class FitsSystemWindowsNavHostFragment : NavHostFragment() { override

    fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { // CoordinatorLayout͸fitsSystemWindowsʹରԠ͍ͯ͠Δ return CoordinatorLayout(inflater.context).apply { fitsSystemWindows = true id = this.id // ͜Ε͸NavHostFragmentͷ࣮૷ͱಉ͡ } } }
  28. ©2019 Wantedly, Inc. ·ͱΊ

  29. ©2019 Wantedly, Inc. w ࢼݧతʹಋೖ͚ͨ͠Ͳ࢖͍উख͕Α͔ͬͨ w 'SBHNFOU5SBOTBDUJPO w ଍Γͳ͍ͱ͜Ζ΋͋Δ͕ଞͷ"OESPJE9Ͱิ͑ͨ w

    কདྷతʹ͸શମΛ/BWJHBUJPOʹஔ͖׵͍͑ͨ ·ͱΊ
  30. ϖʔδλΠτϧ ϖʔδαϒλΠτϧ ©2019 Wantedly, Inc. 5IBOLZPV