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

Material Motion

Nabe
July 22, 2020

Material Motion

Nabe

July 22, 2020
Tweet

More Decks by Nabe

Other Decks in Programming

Transcript

  1. $POUBJOFSUSBOTGPSN w ίϯςφΛؚΉ6*ཁૉؒ ͷભҠ w '"#͔Β#PUUPN4IFFU ʹભҠ w -JTU͔Βৄࡉϖʔδʹભ Ҡ

    w ͜Ε·Ͱͷ4IBSFE &MFNFOU5SBOTJUJPOͱ͸୯ Ұͷཁૉ ը૾ͱ͔ ʹ࢖Θ ͳ͍ͱ͍͏఺͕ҟͳΔ
  2. $POUBJOFSUSBOTGPSN *NQMFNFOUBUJPO w 4IBSFE&MFNFOU5SBOTJUJPOͷ࣮૷ͱಉ͡Α͏ʹɺ։࢝ͷ7JFX ͱભҠઌͷ'SBHNFOUͷϧʔτͷ7JFXʹUSBOTJUJPO/BNFΛ ઃఆ͠ɺભҠͷॲཧΛ࣮૷ <View ... android:transitionName="transition_card" />

    // navigate with transition card.setOnClickListener { card -> val extras = FragmentNavigatorExtras(card to card.transitionName) findNavController().navigate( R.id.action_List_to_Detail, null, null, extras ) }
  3. $POUBJOFSUSBOTGPSN *NQMFNFOUBUJPO w ભҠઌ'SBHNFOUͷTIBSFE&MFNFOU&OUFS5SBOTJUJPOʹ .BUFSJBM$POUBJOFS5SBOTGPSNΛઃఆ // Fragment.kt override fun onCreate(savedInstanceState:

    Bundle?) { super.onCreate(savedInstanceState) // setup transition sharedElementEnterTransition = MaterialContainerTransform().apply { // if not exist background in fragment setAllContainerColors( MaterialColors.getColor( requireContext(), android.R.attr.colorBackground, "The attribute is not set in the current theme" ) ) } }
  4. $POUBJOFSUSBOTGPSN *NQMFNFOUBUJPO w ભҠઌ'SBHNFOUͷTIBSFE&MFNFOU&OUFS5SBOTJUJPOʹ .BUFSJBM$POUBJOFS5SBOTGPSNΛઃఆ // Fragment.kt override fun onCreate(savedInstanceState:

    Bundle?) { super.onCreate(savedInstanceState) // setup transition sharedElementEnterTransition = MaterialContainerTransform().apply { // if not exist background in fragment setAllContainerColors( MaterialColors.getColor( requireContext(), android.R.attr.colorBackground, "The attribute is not set in the current theme" ) ) } }
  5. 4IBSFEBYJT *NQMFNFOUBUJPO w .BUFSJBM4IBSFE"YJTΛUSBOTJUJPOʹઃఆ // StartFragment.kt override fun onCreate(savedInstanceState: Bundle?)

    { super.onCreate(savedInstanceState) // setup transition val backward = MaterialSharedAxis(MaterialSharedAxis.X, false) reenterTransition = backward val forward = MaterialSharedAxis(MaterialSharedAxis.X, true) exitTransition = forward } // EndFragment.kt override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // setup transition val forward = MaterialSharedAxis(MaterialSharedAxis.X, true) enterTransition = forward val backward = MaterialSharedAxis(MaterialSharedAxis.X, false) returnTransition = backward }
  6. 4IBSFEBYJT *NQMFNFOUBUJPO w .BUFSJBM4IBSFE"YJTΛUSBOTJUJPOʹઃఆ // StartFragment.kt override fun onCreate(savedInstanceState: Bundle?)

    { super.onCreate(savedInstanceState) // setup transition val backward = MaterialSharedAxis(MaterialSharedAxis.X, false) reenterTransition = backward val forward = MaterialSharedAxis(MaterialSharedAxis.X, true) exitTransition = forward } // EndFragment.kt override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) // setup transition val forward = MaterialSharedAxis(MaterialSharedAxis.X, true) enterTransition = forward val backward = MaterialSharedAxis(MaterialSharedAxis.X, false) returnTransition = backward }
  7. 'BEFUISPVHI *NQMFNFOUBUJPO w .BUFSJBM'BEF5ISPVHIΛUSBOTJUJPOʹઃఆ // Fragment.kt override fun onCreate(savedInstanceState: Bundle?)

    { super.onCreate(savedInstanceState) // setup transition exitTransition = MaterialFadeThrough() enterTransition = MaterialFadeThrough() }
  8. 'BEFUISPVHI *NQMFNFOUBUJPO w .BUFSJBM'BEF5ISPVHIΛUSBOTJUJPOʹઃఆ // Fragment.kt override fun onCreate(savedInstanceState: Bundle?)

    { super.onCreate(savedInstanceState) // setup transition exitTransition = MaterialFadeThrough() enterTransition = MaterialFadeThrough() }
  9. 'BEF *NQMFNFOUBUJPO w .BUFSJBM'BEFΛ5SBOTJUJPO.BOBHFSʹઃఆͯ͠ 7JFXͷදࣔඇදࣔΛߦ͏ fun showFab() { val materialFade

    = MaterialFade().apply { duration = 150L } TransitionManager.beginDelayedTransition(container, materialFade) fab.isVisible = true } fun hideFab() { val materialFade = MaterialFade().apply { duration = 75L } TransitionManager.beginDelayedTransition(container, materialFade) fab.isVisible = false }
  10. 'BEF *NQMFNFOUBUJPO w .BUFSJBM'BEFΛ5SBOTJUJPO.BOBHFSʹઃఆͯ͠ 7JFXͷදࣔඇදࣔΛߦ͏ fun showFab() { val materialFade

    = MaterialFade().apply { duration = 150L } TransitionManager.beginDelayedTransition(container, materialFade) fab.isVisible = true } fun hideFab() { val materialFade = MaterialFade().apply { duration = 75L } TransitionManager.beginDelayedTransition(container, materialFade) fab.isVisible = false }