Fix for message composer losing focus in Compose 1.8.0 (#4853)
Co-authored-by: ElementBot <android@element.io>
This commit is contained in:
parent
2eda54d264
commit
eff693ccd9
12 changed files with 46 additions and 25 deletions
|
|
@ -7,6 +7,8 @@
|
|||
|
||||
package io.element.android.libraries.textcomposer
|
||||
|
||||
import android.os.Build
|
||||
import android.view.WindowInsets
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
|
|
@ -14,6 +16,7 @@ import androidx.compose.runtime.rememberUpdatedState
|
|||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import io.element.android.libraries.androidutils.ui.awaitWindowFocus
|
||||
import io.element.android.libraries.androidutils.ui.isKeyboardVisible
|
||||
import io.element.android.libraries.androidutils.ui.showKeyboard
|
||||
|
||||
/**
|
||||
|
|
@ -40,11 +43,17 @@ internal fun <T> SoftKeyboardEffect(
|
|||
// Await window focus in case returning from a dialog
|
||||
view.awaitWindowFocus()
|
||||
|
||||
// Show the keyboard, temporarily using the root view for focus
|
||||
view.showKeyboard(andRequestFocus = true)
|
||||
if (!view.isKeyboardVisible()) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
view.windowInsetsController?.show(WindowInsets.Type.ime())
|
||||
} else {
|
||||
// Show the keyboard, temporarily using the root view for focus
|
||||
view.showKeyboard(andRequestFocus = true)
|
||||
}
|
||||
|
||||
// Refocus to the correct view
|
||||
latestOnRequestFocus()
|
||||
// Refocus to the correct view
|
||||
latestOnRequestFocus()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,12 +18,14 @@ import androidx.compose.foundation.layout.Column
|
|||
import androidx.compose.foundation.layout.IntrinsicSize
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.WindowInsets
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.requiredHeightIn
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.systemBars
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
|
|
@ -35,6 +37,7 @@ import androidx.compose.runtime.setValue
|
|||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
|
|
@ -432,8 +435,9 @@ private fun TextFormattingLayout(
|
|||
sendButton: @Composable () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val bottomPadding = with(LocalDensity.current) { WindowInsets.systemBars.getBottom(this).toDp() + 8.dp }
|
||||
Column(
|
||||
modifier = modifier.padding(vertical = 4.dp),
|
||||
modifier = modifier.padding(vertical = 4.dp).padding(bottom = bottomPadding),
|
||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||
) {
|
||||
if (isRoomEncrypted == false) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@
|
|||
package io.element.android.libraries.textcomposer.components.markdown
|
||||
|
||||
import android.content.Context
|
||||
import android.view.View
|
||||
import androidx.appcompat.widget.AppCompatEditText
|
||||
|
||||
internal class MarkdownEditText(
|
||||
|
|
@ -37,8 +36,4 @@ internal class MarkdownEditText(
|
|||
onSelectionChangeListener?.invoke(selStart, selEnd)
|
||||
}
|
||||
}
|
||||
|
||||
override fun focusSearch(direction: Int): View? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,6 +118,11 @@ fun MarkdownTextInput(
|
|||
)
|
||||
}
|
||||
state.requestFocusAction = { this.requestFocus() }
|
||||
} else {
|
||||
isEnabled = false
|
||||
isFocusable = false
|
||||
isFocusableInTouchMode = false
|
||||
isClickable = false
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue