acefalobi / android-stepper

A library for creating a wizard-like step-through user interface that uses navigation components and menus for displaying steps with advanced customization.
Apache License 2.0
325 stars 38 forks source link

Java support #9

Closed srserx closed 3 years ago

srserx commented 3 years ago

The following code seems to be only supported by Kotlin:

Captura de pantalla 2020-12-04 a las 12 26 33

as the setupWithNavController call in java asks for a second parameter, which must be an AnimBuilder. But AnimBuilder seems not to be available for Java:

Captura de pantalla 2020-12-04 a las 12 29 05

Is there any workaround in order to make it work with Java as well?

Thanks a lot in advance!

srserx commented 3 years ago

Found out we can use both Java and Kotlin in the same project :-)

acefalobi commented 3 years ago

Hi @srserx,

The AnimBuilder class is written in Kotlin, but it is still interoperable with Java so yes you can use the function like this:

StepperNavigationView stepper = findViewById(R.id.stepper);
NavController navController = ActivityKt.findNavController(this, R.id.frame_stepper);
stepper.setupWithNavController(
        navController,
        builder -> {
            builder.setEnter(android.R.anim.fade_in);
            builder.setExit(android.R.anim.fade_out);
            builder.setPopEnter(android.R.anim.fade_in);
            builder.setPopExit(android.R.anim.fade_out);
            return Unit.INSTANCE;
        }
);

I will add a @JvmOverloads annotation to the setupWithNavController function so you can use it with the default AnimBuilder like:

stepper.setupWithNavController(navController);