FragmentScenarioKt

Added in 1.1.0

public final class FragmentScenarioKt


Summary

Public methods

static final @NonNull FragmentScenario<@NonNull F>
<F extends Fragment> launchFragment(
    Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    FragmentFactory factory
)

Launches a Fragment with given arguments hosted by an empty FragmentActivity using given FragmentFactory and waits for it to reach initialState.

static final @NonNull FragmentScenario<@NonNull F>
<F extends Fragment> launchFragment(
    Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    @NonNull Function0<@NonNull F> instantiate
)

Launches a Fragment with given arguments hosted by an empty FragmentActivity using instantiate to create the Fragment and waits for it to reach initialState.

static final @NonNull FragmentScenario<@NonNull F>
<F extends Fragment> launchFragmentInContainer(
    Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    FragmentFactory factory
)

Launches a Fragment in the Activity's root view container android.R.id.content, with given arguments hosted by an empty FragmentActivity and waits for it to reach initialState.

static final @NonNull FragmentScenario<@NonNull F>
<F extends Fragment> launchFragmentInContainer(
    Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    @NonNull Function0<@NonNull F> instantiate
)

Launches a Fragment in the Activity's root view container android.R.id.content, with given arguments hosted by an empty FragmentActivity using instantiate to create the Fragment and waits for it to reach initialState.

static final @NonNull T
<F extends Fragment, T extends Object> withFragment(
    @NonNull FragmentScenario<@NonNull F> receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull F, @NonNull T> block
)

Run block using FragmentScenario.onFragment, returning the result of the block.

Public methods

public static final @NonNull FragmentScenario<@NonNull F> <F extends Fragment> launchFragment(
    Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    FragmentFactory factory
)

Launches a Fragment with given arguments hosted by an empty FragmentActivity using given FragmentFactory and waits for it to reach initialState.

This method cannot be called from the main thread.

Parameters
Bundle fragmentArgs

a bundle to passed into fragment

@StyleRes int themeResId

a style resource id to be set to the host activity's theme

@NonNull Lifecycle.State initialState

the initial Lifecycle.State. Passing in DESTROYED will result in an IllegalArgumentException.

FragmentFactory factory

a fragment factory to use or null to use default factory

public static final @NonNull FragmentScenario<@NonNull F> <F extends Fragment> launchFragment(
    Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    @NonNull Function0<@NonNull F> instantiate
)

Launches a Fragment with given arguments hosted by an empty FragmentActivity using instantiate to create the Fragment and waits for it to reach initialState.

This method cannot be called from the main thread.

Parameters
Bundle fragmentArgs

a bundle to passed into fragment

@StyleRes int themeResId

a style resource id to be set to the host activity's theme

@NonNull Lifecycle.State initialState

the initial Lifecycle.State. Passing in DESTROYED will result in an IllegalArgumentException.

@NonNull Function0<@NonNull F> instantiate

method which will be used to instantiate the Fragment.

launchFragmentInContainer

public static final @NonNull FragmentScenario<@NonNull F> <F extends Fragment> launchFragmentInContainer(
    Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    FragmentFactory factory
)

Launches a Fragment in the Activity's root view container android.R.id.content, with given arguments hosted by an empty FragmentActivity and waits for it to reach initialState.

This method cannot be called from the main thread.

Parameters
Bundle fragmentArgs

a bundle to passed into fragment

@StyleRes int themeResId

a style resource id to be set to the host activity's theme

@NonNull Lifecycle.State initialState

the initial Lifecycle.State. Passing in DESTROYED will result in an IllegalArgumentException.

FragmentFactory factory

a fragment factory to use or null to use default factory

launchFragmentInContainer

public static final @NonNull FragmentScenario<@NonNull F> <F extends Fragment> launchFragmentInContainer(
    Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    @NonNull Function0<@NonNull F> instantiate
)

Launches a Fragment in the Activity's root view container android.R.id.content, with given arguments hosted by an empty FragmentActivity using instantiate to create the Fragment and waits for it to reach initialState.

This method cannot be called from the main thread.

Parameters
Bundle fragmentArgs

a bundle to passed into fragment

@StyleRes int themeResId

a style resource id to be set to the host activity's theme

@NonNull Lifecycle.State initialState

the initial Lifecycle.State. Passing in DESTROYED will result in an IllegalArgumentException.

@NonNull Function0<@NonNull F> instantiate

method which will be used to instantiate the Fragment. This is a simplification of the FragmentFactory interface for cases where only a single class needs a custom constructor called.

public static final @NonNull T <F extends Fragment, T extends Object> withFragment(
    @NonNull FragmentScenario<@NonNull F> receiver,
    @ExtensionFunctionType @NonNull Function1<@NonNull F, @NonNull T> block
)

Run block using FragmentScenario.onFragment, returning the result of the block.

If any exceptions are raised while running block, they are rethrown.