1.0.4
Released version 1.0.4
.
What's the difference?
We can transform a view or fragment into a fragment.
How to use?
Here is some example of transformation RecyclerView item in Fragment A into Fragment B.
FragmentA
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// [Step1]: apply onTransformationStartContainer.
onTransformationStartContainer()
}
/** This function will be called from the [PosterSingleAdapter.PosterDelegate]'s onBindViewHolder. */
override fun onItemClick(poster: Poster, itemView: TransformationLayout) {
val fragment = MainSingleDetailFragment()
// [Step2]: getBundle from the TransformationLayout.
val bundle = itemView.getBundle(MainSingleDetailFragment.paramsKey)
bundle.putParcelable(MainSingleDetailFragment.posterKey, poster)
fragment.arguments = bundle
requireFragmentManager()
.beginTransaction()
// [Step3]: addTransformation using the TransformationLayout.
.addTransformation(itemView)
.replace(R.id.main_container, fragment, MainSingleDetailFragment.TAG)
.addToBackStack(MainSingleDetailFragment.TAG)
.commit()
}
RecyclerView.Adapter
transformationLayout.transitionName = item.name
If you want to transform view (not a recyclerView's item), set transiton name in on onViewCreated
.
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
transformationLayout.transitionName = item.name
}
FragmentB
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// [Step1]: apply onTransformationEndContainer using TransformationLayout.Params.
val params = arguments?.getParcelable<TransformationLayout.Params>(paramsKey)
onTransformationEndContainer(params)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// [Step2]: sets a transition name to the target view.
detail_container.transitionName = poster.name
}