stepstone-tech / android-material-stepper

This library allows to use Material steppers inside Android applications.
Apache License 2.0
1.78k stars 262 forks source link

Step fragment is not working properly after recalling #298

Closed behnawwm closed 2 years ago

behnawwm commented 2 years ago

After closing the main fragment which StepperLayout is located, when I open that fragment again, Step views are not shown and next/prev buttons are not working

Adapter :

class StepperAdapter(fragmentManager: FragmentManager, context: Context) :
    AbstractFragmentStepAdapter(fragmentManager, context) {

    override fun getCount(): Int {
        return 3
    }

    override fun createStep(position: Int): Step {
        return when (position) {
            0 -> DeviceNameStepFragment()
            1 -> CheckModemStepFragment()
            2 -> CheckPermissionStepFragment()
            else -> CheckPermissionStepFragment()
        }
    }
}

MainFragment:

class NewDeviceFragment : Fragment(), StepperLayout.StepperListener {

    private lateinit var binding: FragmentNewDeviceBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        binding = FragmentNewDeviceBinding.inflate(inflater)
        binding.stepperLayout.adapter = StepperAdapter(requireFragmentManager(), requireContext())
        binding.stepperLayout.setListener(this)
        return binding.root
    }

    override fun onCompleted(completeButton: View?) {
        findNavController().popBackStack()
    }

    override fun onError(verificationError: VerificationError?) {
    }

    override fun onStepSelected(newStepPosition: Int) {
    }

    override fun onReturn() {
        findNavController().popBackStack()
    }

}
behnawwm commented 2 years ago

solved by using childFragmentManager for setting up the adapter!