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

Android Jetpack: Navigationを使ってみる

Android Jetpack: Navigationを使ってみる

Dee1ceb83e8c6afd83792ca7df9e9524?s=128

Yui Matsuura

May 17, 2018
Tweet

Transcript

  1. Android Jetpack: Navigationを使っ てみる Google I/O 2018 わいわい報告会 @teshi04

  2. About me てし @teshi04 Yui Matuura Mercari/Marpay

  3. Android Jetpack

  4. Jetpack: Architecture • Databinding • Lifecycles • LiveData • Navigation

    new! • Paging new! • Room • ViewModel • WorkManager new!
  5. デモ

  6. None
  7. Navigationの課題 • Fragment Transition • Passing Arguments • Deep Links

    • Up and Back • Testing • Error-prone Boilerplate
  8. Architecture: Navigation ビジュアルツールとXML • Navigation Actions • Arguments • Animation

    • Up behavior • Deep Link no more Fragment Transaction!
  9. Gradle Dependency allprojects { repositories { google() jcenter() } }

    implementation 'android.arch.navigation:navigation-fragment:1.0.0-alpha01' implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha01'
  10. NavHostFragmentを追加 activity_main.xml <fragment android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/my_nav_host_fragment" android:name="androidx.navigation.fragment.NavHostFragment" app:navGraph="@navigation/mobile_navigation" app:defaultNavHost="true" />

  11. Navigation Graph

  12. Actionを設定する

  13. Actionを設定する

  14. Navigation Graph(XML) mobile_navigation.xml <navigation 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" app:startDestination="@+id/launcher_home"> <fragment android:id="@+id/launcher_home"

    android:name="com.example.android.codelabs.navigation.MainFragment" android:label="@string/home" tools:layout="@layout/main_fragment"> <action android:id="@+id/next_action" app:destination="@id/flow_step_one" ... app:popExitAnim="@anim/slide_out_right" /> </fragment> <fragment android:id="@+id/flow_step_one" android:name="com.example.android.codelabs.navigation.FlowStepFragment" tools:layout="@layout/flow_step_one_fragment"/> ...
  15. NavControllerで遷移する MainFragment.kt transactionsButton.setOnClickListener { view -> Navigation.findNavController(view).navigate(R.id.next_action) }

  16. まとめ • Android Jetpack: Navigationのメリット ◦ 画面遷移が可視化できる ◦ FragmentTransition, Animationが簡単とか

    • Jetpack。手段の一つでしかない。使うか使わないかは アプリの次第だと思う
  17. 参考リンク • 「Android Jetpack: manage UI navigation with Navigation Controller

    (Google I/O '18) https://www.youtube.com/watch?v=8GCXtCjtg40 • Sample https://github.com/googlesamples/android-architecture-c omponents/tree/master/NavigationBasicSample • Navigation Codelab https://codelabs.developers.google.com/codelabs/androi d-navigation/index.html • ドキュメント https://developer.android.com/topic/libraries/architecture/ navigation/
  18. Thanks!