# AndroidFragment

## Functions summary

|---|---|
| `inline https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/compose/AndroidFragment.composable#AndroidFragment(androidx.compose.ui.Modifier,androidx.fragment.compose.FragmentState,android.os.Bundle,androidx.lifecycle.Lifecycle.State,kotlin.Function1)( modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier, fragmentState: https://developer.android.com/reference/kotlin/androidx/fragment/compose/FragmentState, arguments: https://developer.android.com/reference/android/os/Bundle.html, maxLifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State, noinline onUpdate: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Allows for adding a `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` directly into Compose. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment> https://developer.android.com/reference/kotlin/androidx/fragment/compose/AndroidFragment.composable#AndroidFragment(java.lang.Class,androidx.compose.ui.Modifier,androidx.fragment.compose.FragmentState,android.os.Bundle,androidx.lifecycle.Lifecycle.State,kotlin.Function1)( clazz: https://developer.android.com/reference/java/lang/Class.html<T>, modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier, fragmentState: https://developer.android.com/reference/kotlin/androidx/fragment/compose/FragmentState, arguments: https://developer.android.com/reference/android/os/Bundle.html, maxLifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State, onUpdate: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Allows for adding a `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` directly into Compose. |

## Functions

### AndroidFragment

Artifact: [androidx.fragment:fragment-compose](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/compose/AndroidFragment.kt+function:AndroidFragment)

```
@Composable
inline fun <T : Fragment> AndroidFragment(
    modifier: Modifier = Modifier,
    fragmentState: FragmentState = rememberFragmentState(),
    arguments: Bundle = Bundle.EMPTY,
    maxLifecycle: Lifecycle.State = LocalLifecycleOwner.current.lifecycle.currentStateAsState().value,
    noinline onUpdate: (T) -> Unit = {}
): Unit
```

Allows for adding a `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` directly into Compose. It creates a fragment of the given class and adds it to the fragment manager.

Updating the `https://developer.android.com/reference/kotlin/androidx/fragment/compose/package-summary#AndroidFragment(androidx.compose.ui.Modifier,androidx.fragment.compose.FragmentState,android.os.Bundle,androidx.lifecycle.Lifecycle.State,kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/fragment/compose/package-summary#AndroidFragment(androidx.compose.ui.Modifier,androidx.fragment.compose.FragmentState,android.os.Bundle,androidx.lifecycle.Lifecycle.State,kotlin.Function1)` parameters will result in a new fragment instance being added to the fragment manager and invoke the `https://developer.android.com/reference/kotlin/androidx/fragment/compose/package-summary#AndroidFragment(androidx.compose.ui.Modifier,androidx.fragment.compose.FragmentState,android.os.Bundle,androidx.lifecycle.Lifecycle.State,kotlin.Function1)` callback with the new instance.

```kotlin
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.compose.AndroidFragment
import androidx.fragment.compose.rememberFragmentState

val fragmentState = rememberFragmentState()
val args =
    @Suppress("DEPRECATION") // bundleOf is deprecated
    bundleOf("myarg" to "arguments")
AndroidFragment<MyFragment>(fragmentState = fragmentState, arguments = args)
```

| Parameters |
|---|---|
| `modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier = Modifier` | the modifier to be applied to the layout |
| `fragmentState: https://developer.android.com/reference/kotlin/androidx/fragment/compose/FragmentState = rememberFragmentState()` | the savedState of the fragment |
| `arguments: https://developer.android.com/reference/android/os/Bundle.html = Bundle.EMPTY` | args to be passed to the fragment |
| `maxLifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State = LocalLifecycleOwner.current.lifecycle.currentStateAsState().value` | the max lifecycle state for the fragment |
| `noinline onUpdate: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html = {}` | callback that provides the created fragment |

### AndroidFragment

Artifact: [androidx.fragment:fragment-compose](https://developer.android.com/jetpack/androidx/releases/fragment) [View Source](https://cs.android.com/search?q=file:androidx/fragment/compose/AndroidFragment.kt+function:AndroidFragment)

```
@Composable
fun <T : Fragment> AndroidFragment(
    clazz: Class<T>,
    modifier: Modifier = Modifier,
    fragmentState: FragmentState = rememberFragmentState(),
    arguments: Bundle = Bundle.EMPTY,
    maxLifecycle: Lifecycle.State = LocalLifecycleOwner.current.lifecycle.currentStateAsState().value,
    onUpdate: (T) -> Unit = {}
): Unit
```

Allows for adding a `https://developer.android.com/reference/kotlin/androidx/fragment/app/Fragment` directly into Compose. It creates a fragment of the given class and adds it to the fragment manager.

Updating the `https://developer.android.com/reference/kotlin/androidx/fragment/compose/package-summary#AndroidFragment(java.lang.Class,androidx.compose.ui.Modifier,androidx.fragment.compose.FragmentState,android.os.Bundle,androidx.lifecycle.Lifecycle.State,kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/fragment/compose/package-summary#AndroidFragment(java.lang.Class,androidx.compose.ui.Modifier,androidx.fragment.compose.FragmentState,android.os.Bundle,androidx.lifecycle.Lifecycle.State,kotlin.Function1)` parameters will result in a new fragment instance being added to the fragment manager and invoke the `https://developer.android.com/reference/kotlin/androidx/fragment/compose/package-summary#AndroidFragment(java.lang.Class,androidx.compose.ui.Modifier,androidx.fragment.compose.FragmentState,android.os.Bundle,androidx.lifecycle.Lifecycle.State,kotlin.Function1)` callback with the new instance.

```kotlin
import androidx.core.os.bundleOf
import androidx.fragment.app.Fragment
import androidx.fragment.compose.AndroidFragment
import androidx.fragment.compose.rememberFragmentState

val fragmentState = rememberFragmentState()
val args =
    @Suppress("DEPRECATION") // bundleOf is deprecated
    bundleOf("myarg" to "arguments")
AndroidFragment<MyFragment>(fragmentState = fragmentState, arguments = args)
```

| Parameters |
|---|---|
| `clazz: https://developer.android.com/reference/java/lang/Class.html<T>` | fragment class to be created |
| `modifier: https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier = Modifier` | the modifier to be applied to the layout |
| `fragmentState: https://developer.android.com/reference/kotlin/androidx/fragment/compose/FragmentState = rememberFragmentState()` | the savedState of the fragment |
| `arguments: https://developer.android.com/reference/android/os/Bundle.html = Bundle.EMPTY` | args to be passed to the fragment |
| `maxLifecycle: https://developer.android.com/reference/kotlin/androidx/lifecycle/Lifecycle.State = LocalLifecycleOwner.current.lifecycle.currentStateAsState().value` | the max lifecycle state for the fragment |
| `onUpdate: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html = {}` | callback that provides the created fragment |