Skip to content

Latest commit

 

History

History
78 lines (54 loc) · 1.65 KB

USE_JAVA.md

File metadata and controls

78 lines (54 loc) · 1.65 KB

Using in Java

Load root in NavHostFramgent

//loadRoot with class
Fragivity.loadRoot(navHostFragment, HomeFragment.class);

//loadRoot with factory
Fragivity.loadRoot(navHostFragment, HomeFragment.class, () -> {
                    HomeFragment fragment = new HomeFragment();
                    return fragment;
                }));

Navigate to destination fragment

class MyFragment extends Fagment {

    //navigate with class
    Fragivity.of(this).push(DestinationFragment.class);

    //navigate with NavOptions
    Bundle bundle = new Bundle();
    bundle.putString("key", "value");
    Fragivity.of(this).push(DestinaionFragment.class,
            navOptionsBuilder()
                .setArguments(bundle)
                .setEnterAnim(R.anim.slide_in)
                .setExitAnim(R.anim.slide_out)
                .setPopEnterAnim(R.anim.slide_in_pop)
                .setPopExitAnim(R.anim.slide_out_pop)
                .setLaunchMode(LaunchMode.STANDARD)
                .build());


    //navigate with factory
    Fragivity.of(this).push(DestFragment.class, () -> {
        return new DestFragment();
    }, navOptionsBuilder()
        .setArguments(bundle)
        .build());

}

Pop

Fragivity.of(fragment).pop();

Show dialog

Fragivity.of(fragment).showDialog(DialogFragment.class, bundle);

Enable SwipeBack

class MyFragment extends Fragment {
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        SwipeBackUtil.getSwipeBackLayout(this).setEnableGesture(true);
    }
}