stepstone-tech / android-material-stepper

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

Layout not inflating properly on when StepperAdapter in Fragment #221

Closed lucasharada closed 7 years ago

lucasharada commented 7 years ago

I did not see anything related to the Stepper being used in Fragment (F1) instead of Activity, so I gave it a try. At first, it works, but has a bug where the Stepper is not inflated correctly when F1 is remove and then added again.

Steps to reproduce:

  1. Implement an Activity with a FrameLayout to contain the Fragments and the Fragment that will start the Fragment with the Stepper, which I called CallerFragment;
  2. Implement the Stepper in a Fragment, which I called MainFragment;
  3. Implement 3 Fragments that extends Step, which I called FirstStepFragment, SecondStepFragment and ThirdStepFragment;
  4. On a click event, replace the CallerFragment for the MainFragment; It will inflate everything properly
  5. Finish the MainFragment and repeat step 4; The Steps will not be loaded properly, as I need to go to the third step and come back to the first to be able to see the content

Finally, is it a problem with using the Stepper with Activity? Or am I doing something wrong?

Replacing CallerFragment for MainFragment

final Fragment fragment = new MainFragment(); final FragmentTransaction transaction = getFragmentManager().beginTransaction(); transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN); transaction.replace(R.id.main_container, fragment).addToBackStack("callerFragment").commit();

Destroying the MainFragment, which contains the Stepper, and popping the backstack

FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); FragmentTransaction transaction = fragmentManager.beginTransaction(); transaction.remove(this).commit(); fragmentManager.popBackStack("callerFragment", FragmentManager.POP_BACK_STACK_INCLUSIVE);

zawadz88 commented 7 years ago

Hi @lucasharada, I have never tried putting the StepperLayout in a Fragment before so I'm not really sure how it would behave. When constructing AbstractFragmentStepAdapter does the FragmentManager come from the Activity or are you using MainFragment#getChildFragmentManager()?

lucasharada commented 7 years ago

@zawadz88 I'm currently using MainFragment#getFragmentManager() (not sure if the same as Activity#getFragmentManager()).

zawadz88 commented 7 years ago

I think that for MainFragment this will be the same as Activity#getFragmentManager(). Please try with MainFragment#getChildFragmentManager() and let me know if it helps.

lucasharada commented 7 years ago

@zawadz88 That worked! Thanks a lot!

sfrinx commented 4 years ago

I think that for MainFragment this will be the same as Activity#getFragmentManager(). Please try with MainFragment#getChildFragmentManager() and let me know if it helps.

I suggest you to insert this information in the main page. Thank you