FragmentScenarioKt

public final class FragmentScenarioKt


Summary

Public methods

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

This method is deprecated. Superseded by launchFragment that takes an initialState

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

This method is deprecated. Superseded by launchFragment that takes an initialState

static final @NonNull FragmentScenario<@NonNull F>
<F extends Fragment> launchFragment(
    @Nullable Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    @Nullable 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(
    @Nullable 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(
    @Nullable Bundle fragmentArgs,
    @StyleRes int themeResId,
    @Nullable FragmentFactory factory
)

This method is deprecated. Superseded by launchFragmentInContainer that takes an initialState

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

This method is deprecated. Superseded by launchFragmentInContainer that takes an initialState

static final @NonNull FragmentScenario<@NonNull F>
<F extends Fragment> launchFragmentInContainer(
    @Nullable Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    @Nullable 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(
    @Nullable 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> FragmentScenarioKt.withFragment(
    @NonNull FragmentScenario<@NonNull F> receiver,
    @NonNull Function1<@NonNull F, @NonNull T> block
)

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

Public methods

launchFragment

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

launchFragment

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

launchFragment

@NonNull
public static final FragmentScenario<@NonNull F> <F extends Fragment> launchFragment(
    @Nullable Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    @Nullable 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
@Nullable 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. This must be one of Lifecycle.State.CREATED, Lifecycle.State.STARTED, or Lifecycle.State.RESUMED.

@Nullable FragmentFactory factory

a fragment factory to use or null to use default factory

launchFragment

@NonNull
public static final FragmentScenario<@NonNull F> <F extends Fragment> launchFragment(
    @Nullable 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
@Nullable 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. This must be one of Lifecycle.State.CREATED, Lifecycle.State.STARTED, or Lifecycle.State.RESUMED.

@NonNull Function0<@NonNull F> instantiate

method which will be used to instantiate the Fragment.

launchFragmentInContainer

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

launchFragmentInContainer

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

launchFragmentInContainer

@NonNull
public static final FragmentScenario<@NonNull F> <F extends Fragment> launchFragmentInContainer(
    @Nullable Bundle fragmentArgs,
    @StyleRes int themeResId,
    @NonNull Lifecycle.State initialState,
    @Nullable 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
@Nullable 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. This must be one of Lifecycle.State.CREATED, Lifecycle.State.STARTED, or Lifecycle.State.RESUMED.

@Nullable FragmentFactory factory

a fragment factory to use or null to use default factory

launchFragmentInContainer

@NonNull
public static final FragmentScenario<@NonNull F> <F extends Fragment> launchFragmentInContainer(
    @Nullable 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
@Nullable 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. This must be one of Lifecycle.State.CREATED, Lifecycle.State.STARTED, or Lifecycle.State.RESUMED.

@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.

FragmentScenarioKt.withFragment

@NonNull
public static final T <F extends Fragment, T extends Object> FragmentScenarioKt.withFragment(
    @NonNull FragmentScenario<@NonNull F> receiver,
    @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.