Meshtastic-Android/app/src/main/java/com/geeksville/mesh/ui/ComposeFragment.kt

57 lines
1.6 KiB
Kotlin
Raw Normal View History

2020-04-07 11:27:51 -07:00
package com.geeksville.mesh.ui
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.compose.Composable
import androidx.ui.core.setContent
fun androidx.fragment.app.Fragment.setComposable(
id: Int,
content: @Composable() () -> Unit
): View? =
context?.let {
FrameLayout(it).apply {
2020-04-07 12:48:42 -07:00
this.isClickable = true
2020-04-07 11:27:51 -07:00
this.id =
id // Compose requires a unique ID for the containing view to make savedInstanceState work
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
setContent(content)
}
}
2020-04-07 12:13:50 -07:00
open class ComposeFragment(
screenName: String,
id: Int,
private val content: @Composable() () -> Unit
2020-04-07 12:48:42 -07:00
) : ScreenFragment(screenName) {
2020-04-07 11:27:51 -07:00
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? =
2020-04-07 12:48:42 -07:00
FrameLayout(context!!).apply {
this.isClickable = true
this.id =
id // Compose requires a unique ID for the containing view to make savedInstanceState work
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
setContent(content)
}
/* override fun onStart() {
super.onStart()
(view as ViewGroup).setContent(content)
} */
}