JivoChat / JivoSDK-Android

The Jivo Mobile SDK allows you to embed the Jivo chat into your Android mobile applications to receive customer requests
https://www.jivochat.com
10 stars 5 forks source link

Есть ли решение для Compose? #51

Closed VITYQ closed 3 months ago

VITYQ commented 1 year ago

Как мы можем добавить ваш чат в приложение написанное на Compose?

Kazachenko1998 commented 4 months ago

My example

@Composable
actual fun ChatView() {
    val jivoChatFragment = remember { JivoChatFragment() }
    AndroidView(
        factory = { context ->
            val contentViewId = View.generateViewId()
            val frame = FrameLayout(context).apply { id = contentViewId }
            val activity = context as AppCompatActivity
            activity.supportFragmentManager.commit { add(contentViewId, jivoChatFragment) }
            frame
        },
        modifier = Modifier
            .statusBarsPadding()
            .imeMinPadding()
            .fillMaxSize()
            .clearFocusOnDispose()
            .onDispose { jivoChatFragment.onPause() }
    )
}

val imeMinInset: WindowInsets
    @Composable
    @Stable
    get() = WindowInsets.ime.exclude(WindowInsets.navigationBars)

fun Modifier.imeMinPadding(): Modifier = composed {
    windowInsetsPadding(imeMinInset)
}

fun Modifier.clearFocusOnDispose(): Modifier = composed {
    val hideKeyboard by rememberHideKeyboard()
    DisposableEffect(Unit) {
        onDispose {
            hideKeyboard.invoke()
        }
    }
    this
}