
📌참고자료
Compose is designed with View interoperability
Once all the contents are in compose
-> remove fragments entirely & replace with screen level composable
-> use navigation compose to navigate & pass data between composables
📌참고자료
buildFeatures{
compose true
}
ComposeView 태그 사용하여 저으이<androidx.compose.ui.platform.ComposeView
android:id="@+id/compose_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
setContent 함수 호출override fun onCreateView(...): View? {
val binding = DataBindingUtil.inflate<FragmentPlantDetailBinding>(
inflater, R.layout.fragment_plant_detail, container, false
)
binding.composeView.setContent {
MaterialTheme {
PlantDetailDescription()
}
}
//...
}
observeAsState 함수 사용@Composable
<T : Any?> LiveData<T>.observeAsState()Lifecycle.State.DESTROYED 상태가 되면 자동으로 제거됨LocalContext.current 사용Android View 사용@Composable
@UiComposable
fun <T : View> AndroidView(
factory: (Context) -> T,
modifier: Modifier = Modifier,
update: (T) -> Unit = NoOpUpdate
): Unit
ComposeView를 사용하는 경우, Compose의 생명주기 Fragment View의 생명주기와 맞춰야setViewCompositionStrategy 함수로 ViewCompositionStrategy 설정Compose UI View(ex. ComposeView)의 Composition 관리 strategyfindViewTreeLifecycleOwner of the*next window the view is attached to is destroyed