Daily life with Jetpack Compose part 1
How to achieve simple tasks with Jetpack Compose series. Simple tasks with plain Android stayed mostly the same with minor API changes, but there are no official documentation on this subject.
How to display a web web in a Composable
In your code
import android.webkit.WebView
import android.webkit.WebViewClient
@Composable
fun createWebView(article: Post, modifier: Modifier) {
val context = ContextAmbient.current
val webViewClient = WebViewClient()
AndroidView(
viewBlock = {
WebView(context).apply {
this.webViewClient = webViewClient
this.loadUrl("https://hanquoc.kr/${article.slug}")
}
},
modifier = modifier
)
}
Don’t use the androidx version – it’s useless
How to share a URL with Jetpack Compose
In your code
import android.content.Intent
@Composable
fun ArticleView(
article: Post
) {
val context = ContextAmbient.current
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.type = "text/plain"
shareIntent.putExtra(Intent.EXTRA_TEXT, "https://hanquoc.kr/${article.slug}")
shareIntent.putExtra(Intent.EXTRA_SUBJECT, article.title.rendered)
startActivity(
context,
Intent.createChooser(shareIntent, null),
null
)
}