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

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

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

Masatoshi Kubode

February 28, 2019
Tweet

More Decks by Masatoshi Kubode

Other Decks in Programming

Transcript

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

    ݱ࣌఺Ͱ3$  w TUBCMFʹͳΔͱਖ਼ࣜʹ"OESPJE9ʹͳͬͯഁյత มߋ͕͋Δ͔΋ AndroidX Navigationͱ͸
  2. ©2019 Wantedly, Inc. w BSHVNFOUͷΫϥεΛੜ੒͢Δ(SBEMF1MVHJO w ܕ҆શʹͳΔ w 'SBHNFOUOFX*OTUBODFͱ͔࡞Βͳͯ͘Α͍ w

    /BWJHBUJPO࢖Θͣ͜Ε͚ͩΛಋೖ͢Δέʔε΋ SafeArgs apply plugin: "androidx.navigation.safeargs.kotlin"
  3. ©2019 Wantedly, Inc. w ΞϓϦશମͷϦχϡʔΞϧΛਐΊ͍ͯΔ w .VMUJNPEVMFԽ͍ͯ͠Δ w 'FBUVSFؒͷը໘ભҠΛͲ͏͢Δ͔ w

    ˠ%SPJE,BJHJͷ࣮૷͕ࢀߟʹͳΓͦ͏ w ˠ/BWJHBUJPOΛࢼ͍ͨ͠ ଞͷಋೖཧ༝
  4. ©2019 Wantedly, Inc.  ۭͷ'SBHNFOUΫϥεΛ͢΂ͯ࡞Δ  SFTOBWJHBUJPOOBWJHBUJPOYNMΛ࡞Δ  (6*Ͱը໘Λ഑ஔ 

    "DUJWJUZʹ/BW)PTU'SBHNFOUΛ഑ஔ  'SBHNFOUͰ/BW$POUSPMMFSOBWJHBUFΛॻ͘ ࣮૷ͷྲྀΕ
  5. ©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>
  6. ©2019 Wantedly, Inc. NavController.navigateͰભҠ // InitialFragment override fun onSignUpSuccessful(userName: String)

    { findNavController() // KTXͷ֦ு .navigate( // safeargsͰੜ੒͞Εͨίʔυ InitialFragmentDirections .actionInitialFragmentToEmailWelcomeFragment(userName) ) }
  7. ©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 } ) }
  8. ©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ͷ࣮૷ͱಉ͡ } } }