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

Navigation Component

Navigation Component

Presented at CA.apk #6 (2018.05.22)

satsukies

May 22, 2018
Tweet

More Decks by satsukies

Other Decks in Technology

Transcript

  1. 8IBU`TUIF/BWJHBUJPO w ը໘ભҠΛ9.-ϕʔεͷϦιʔεͱͯ͠ఆٛ <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" /> <activity android:id="@+id/main_activity" android:name="com.example.android.codelabs.navigation.MainActivity" android:label="MainActivity" /> </navigation>
  2. 8IBU`TUIF/BWJHBUJPO w ը໘ભҠΛ9.-ϕʔεͷϦιʔεͱͯ͠ఆٛ w 4BGF"SHVNFOUTʹΑΔܕ҆શͳҾ਺ͷαϙʔτ w 'SBHNFOUʹॳظ஋Λ౉͍ͨ࣌͠ɺ#VOEMFΛྑ͘࢖͏ val args =

    Bundle() args.putInt("artistId", 123456) val artistId = arguments?.getInt("artistId") ֨ೲ࣌ͱผͷܕͰΞΫηε͠Α͏ͱ͢Δ͜ͱ΋Մೳ ʹܕ҆શ͡Όͳ͍
  3. public class FlowStepFragmentArgs { private String artistId = "hoge"; private

    FlowStepFragmentArgs() { } public static FlowStepFragmentArgs fromBundle(Bundle bundle) { FlowStepFragmentArgs result = new FlowStepFragmentArgs(); if (bundle.containsKey("artistId")) { result.artistId = bundle.getString("artistId"); } return result; } public String getArtistId() { return artistId; } public Bundle toBundle() { Bundle __outBundle = new Bundle(); __outBundle.putString("artistId", this.artistId); return __outBundle; } ...
  4. public static class Builder { private String artistId = "hoge";

    public Builder(FlowStepFragmentArgs original) { this.artistId = original.artistId; } public Builder() {} public FlowStepFragmentArgs build() { FlowStepFragmentArgs result = new FlowStepFragmentArgs(); result.artistId = this.artistId; return result; } public Builder setArtistId(String artistId) { this.artistId = artistId; return this; } public String getArtistId() { return artistId; } }
  5. 8IBU`TUIF/BWJHBUJPO w ը໘ભҠΛ9.-ϕʔεͷϦιʔεͱͯ͠ఆٛ w 4BGF"SHVNFOUTʹΑΔܕ҆શͳҾ਺ͷαϙʔτ FlowStepFragmentArgs.Builder() .setArtistId("123456") .build() .toBundle() val

    artistId = arguments?.let { val safeArgs = FlowStepFragmentArgs.fromBundle(it) safeArgs.artistId } UZQFTBGFʹҾ਺ܦ༝Ͱ΍ΓͱΓ͕Մೳ
  6. 4UBSUUP/BWJHBUJPO w ϞδϡʔϧͷCVJMEHSBEMFʹҎԼΛ௥Ճ w 
 w 4BGFBSHVNFOUTΛ࢖͏৔߹ɺϓϩδΣΫτͷCVJMEHSBEMFʹҎԼΛ௥Ճ implementation 
 'android.arch.navigation:navigation-fragment:1.0.0-alpha01'

    implementation 'android.arch.navigation:navigation-ui:1.0.0-alpha01' dependencies { classpath 'android.arch.navigation:navigation-safe-args- gradle-plugin:1.0.0-alpha01' }
  7. 8IBU`TUIF/BWJHBUJPOʢ࠶ܝʣ w ը໘ભҠΛ9.-ϕʔεͷϦιʔεͱͯ͠ఆٛ w 4BGF"SHVNFOUTʹΑΔܕ҆શͳҾ਺ͷαϙʔτ FlowStepFragmentArgs.Builder() .setArtistId("123456") .build() .toBundle() val

    artistId = arguments?.let { val safeArgs = FlowStepFragmentArgs.fromBundle(it) safeArgs.artistId } UZQFTBGFʹҾ਺ܦ༝Ͱ΍ΓͱΓ͕Մೳ