MVI fix: add another way of providing screen arguments

This commit is contained in:
Kirill Nayduik 2021-07-01 12:50:43 +03:00
parent 96d761a04d
commit 02cae3c97d
2 changed files with 15 additions and 5 deletions

View File

@ -0,0 +1,9 @@
package ru.touchin.roboswag.mvi_arch.core
import android.os.Parcelable
/**
* Used for setting arguments and initial state into Fragments
*/
fun <NavArgs : Parcelable, State, Action, VM, TFragment : MviFragment<NavArgs, State, Action, VM>>
TFragment.withArgs(navArgs: NavArgs) = apply { initArgs(navArgs) }

View File

@ -46,8 +46,7 @@ import javax.inject.Inject
* @author Created by Max Bachinsky and Ivan Vlasov at Touch Instinct.
*/
abstract class MviFragment<NavArgs, State, Action, VM>(
@LayoutRes layout: Int,
navArgs: NavArgs = EmptyState as NavArgs
@LayoutRes layout: Int
) : BaseFragment<FragmentActivity>(layout)
where NavArgs : Parcelable,
State : ViewState,
@ -70,9 +69,11 @@ abstract class MviFragment<NavArgs, State, Action, VM>(
lateinit var viewModelMap: MutableMap<Class<out ViewModel>, ViewModelAssistedFactory<out ViewModel>>
init {
arguments?.putParcelable(INIT_ARGS_KEY, navArgs) ?: let {
arguments = bundleOf(INIT_ARGS_KEY to navArgs)
}
arguments = bundleOf(INIT_ARGS_KEY to EmptyState)
}
fun initArgs(navArgs: NavArgs) {
arguments?.putParcelable(INIT_ARGS_KEY, navArgs)
}
@CallSuper