NavigationのNavOptions周りを覗いてみよう

 NavigationのNavOptions周りを覗いてみよう

9d4a459864f822fb5aa7a5741e60e26b?s=128

Keisuke kiuchi

June 26, 2018
Tweet

Transcript

  1. /BWJHBUJPOͷ/BW0QUJPOT पΓΛ೷͍ͯΈΑ͏ LJVDIJLFJTVLF 4IJCVZBBQL αϯϓϧίʔυɿIUUQTHJUIVCDPNLJVDIJLFJTVLF/BWJHBUJPO4BOECPY

  2. ໦಺ܒี w ৬ۀɿҰࣇͷύύ݉"OESPJE&OH w झຯͰ࡞ͬͨΞϓϦɿʮΒ͘ͰΜʯ w Ϟοτʔɿ໌೔ͷࣗ෼ʹ༏͍͠ίʔυΛॻ͘ w 4/4
 5XJUUFS!GFJ@LPNF


    (JUIVC!LJVDIJLFJTVLF
 2JJUB!L@LFJTVLF
  3. ࠷ۙͷΞΫςΟϏςΟ Ϝεϝɺେ஍ʹཱͭ

  4. ஫ҙʂ w ͜ͷൃද಺༰͸7FSTJPOBMQIB࣌఺Ͱͷ৘ใͰ͢ɻ ࠓޙͷΞοϓσʔτͰେ͖͘มΘΔՄೳੑ͕͋Γ·͢ w /BWJHBUJPOͱ͸ͳΜͧ΍ʁͱ͍͏࿩͸ɺ
 ࣌ؒͷ౎߹্ Χοτ͓ͯ͠Γ·͢ɺྃ͝ঝ͍ͩ͘͞ɻ

  5. /BWJHBUJPO
 ࢖ͬͯΈ·͔ͨ͠ʁ

  6. /BWJHBUJPOΛ
 ࣮ϓϩδΣΫτʹ
 ಋೖͯ͠Έ·͔ͨ͠ʁ

  7. /BWJHBUJPOͷ࣮૷!'SBHNFOU view?.findViewById<Button>(R.id.button2_to_activity2)?.setOnClickListener { val intent = Intent(context, Main2Activity::class.java) startActivity(intent) }

    #FGPSF view?.findViewById<Button>(R.id.button2_to_activity2)?.setOnClickListener { view?.let { Navigation.findNavController(it). navigate(R.id.action_mainFragment_to_main2Activity) } } "GUFS
  8. /BWJHBUJPOͷ࣮૷!'SBHNFOU view?.findViewById<Button>(R.id.button2_to_activity2)?.setOnClickListener { val intent = Intent(context, Main2Activity::class.java) intent.flags =

    Intent.FLAG_ACTIVITY_SINGLE_TOP startActivity(intent) } #FGPSF "GUFS view?.findViewById<Button>(R.id.button2_to_activity2)?.setOnClickListener { val options = NavOptions.Builder().setLaunchSingleTop(true).build() view?.let { Navigation.findNavController(it).navigate(R.id.action_mainFragment_to_main2Activit y, null, options) } }
  9. NavOptions.Builder().setLaunchSingleTop(true) .build()

  10. /BW0QUJPOTΠζ୭ʁ

  11. /BW0QUJPOT

  12. /BW0QUJPOT w /BHJHBUF࣌ͷΦϓγϣϯΛઃఆ͢ΔͨΊͷΫϥε w ىಈ࣌ͷϑϥάΛઃఆͰ͖Δˡࠓճ࿩͢ w ىಈ࣌ͷΞχϝʔγϣϯΛઃఆͰ͖Δˡࠓճ࿩͢ w #BDL4UBDL͔Β෮ؼ࣌ͷΞχϝʔγϣϯΛઃఆͰ͖Δ
 ˢࠓճ࿩͞ͳ͍

    w 'SBHNFOU'SBHNFOUͷભҠपΓˡࠓճ࿩͞ͳ͍
  13. ىಈ࣌ͷϑϥάΛઃఆ

  14. /BWJHBUJPOͷ࣮૷!'SBHNFOU view?.findViewById<Button>(R.id.button2_to_activity2)?.setOnClickListener { val intent = Intent(context, Main2Activity::class.java) intent.flags =

    Intent.FLAG_ACTIVITY_SINGLE_TOP startActivity(intent) } #FGPSF "GUFS view?.findViewById<Button>(R.id.button2_to_activity2)?.setOnClickListener { val options = NavOptions.Builder().setLaunchSingleTop(true).build() view?.let { Navigation.findNavController(it).navigate(R.id.action_mainFragment_to_main2Activit y, null, options) } }
  15. /BW0QUJPOT
 TFU-BVODI4JOHMF5PQ NavOptions.Builder().setLaunchSingleTop(true) /** * Launch a navigation target as

    single-top if you are making a lateral navigation * between instances of the same target (e.g. detail pages about similar data items) * that should not preserve history. * * @param singleTop true to launch as single-top */ @NonNull public Builder setLaunchSingleTop(boolean singleTop) { if (singleTop) { mLaunchMode |= LAUNCH_SINGLE_TOP; } else { mLaunchMode &= ~LAUNCH_SINGLE_TOP; } return this; } /BW0QUJPOTKBWB
  16. /BW$POUSPMMFS
 OBWJHBUF

  17. /BW$POUSPMMFS
 OBWJHBUF

  18. /BW$POUSPMMFS
 OBWJHBUF

  19. /BW$POUSPMMFS
 OBWJHBUF

  20. /BW$POUSPMMFS
 OBWJHBUF

  21. /BW%FTUJOBUJPO
 OBWJHBUF

  22. "DUJWJUZ/BWJHBUPS
 OBWJHBUF

  23. "DUJWJUZ/BWJHBUPS
 OBWJHBUF

  24. "DUJWJUZ/BWJHBUPS
 OBWJHBUF

  25. "DUJWJUZ/BWJHBUPS
 OBWJHBUF

  26. "DUJWJUZ/BWJHBUPS
 %FTUJOBUJPOTFU$PNQPOFOU/BNF ˏΞϓϦىಈ࣌

  27. ͪͳΈʹ΄͔ͷϑϥά͸ w TFU-BVODI%PDVNFOUˠ .BOJGFTUͷ 
 BUUS%PDVNFOU-BVODI.PEFͰࢦఆͯ͠Ͷʂ w TFU$MFBS5BTLˠTFU1PQ6Q5P JOUEFTUJOBUJPO*E CPPMFBO

    JODMVTJWF Λ࢖ͬͯͶʂJODMVTJWF͸USVFͰΑΖʂ
  28. ىಈ࣌ͷΞχϝʔγϣϯΛ ઃఆ

  29. /BWJHBUJPOͷ࣮૷!'SBHNFOU view?.findViewById<Button>(R.id.button2_to_activity2)?.setOnClickListener { val intent = Intent(context, Main2Activity::class.java) startActivity(intent) activity!!.overridePendingTransition(R.anim.abc_fade_in,

    R.anim.abc_fade_out) } #FGPSF "GUFS view?.findViewById<Button>(R.id.button2_to_activity2)?.setOnClickListener { val options = NavOptions.Builder() .setEnterAnim(R.anim.abc_fade_in) .setExitAnim(R.anim.abc_fade_out) .build() Navigation.findNavController(it).navigate(R.id.action_mainFragment_to_main2Activity, null, options) }
  30. /BW0QUJPOT
 TFU-BVODI4JOHMF5PQ NavOptions.Builder().setEnterAnim(R.anim.abc_fade_in) .setExitAnim(R.anim.abc_fade_out).build() @NonNull public Builder setEnterAnim(@AnimRes @AnimatorRes int

    enterAnim) { mEnterAnim = enterAnim; return this; } @NonNull public Builder setExitAnim(@AnimRes @AnimatorRes int exitAnim) { mExitAnim = exitAnim; return this; } /BW0QUJPOTKBWB
  31. "DUJWJUZ/BWJHBUPS
 OBWJHBUF

  32. "DUJWJUZ/BWJHBUPS
 OBWJHBUF

  33. ·ͱΊ w "DUJWJUZىಈ࣌ͷ'-"(ࢦఆ͸ Ұ෦͸ /BW0QUJPOT
 ͰͰ͖Δͧ w "DUJWJUZભҠ࣌ͷΞχϝʔγϣϯ͸/BW0QUJPOTͰͰ͖Δͧ w ඇਪ঑ϝιουࠞͬͯͨ͟Γ͢Δ͔ΒऔΓѻ͍஫ҙͩͧ

  34. 2JJUBͱ౤͛મ༻23ίʔυ https://goo.gl/7MkkWj