Merge pull request #4 from jmartinesp/fix/render-composer-mode-performance-and-full-screen-mode

Improve the performance of changing the composer mode.
This commit is contained in:
Benoit Marty
2022-12-02 15:49:21 +01:00
committed by GitHub
3 changed files with 23 additions and 9 deletions

View File

@@ -240,9 +240,9 @@ fun MessagesContent(
.fillMaxWidth()
.let {
if (composerFullScreen) {
it.weight(1f)
it.weight(1f, fill = false)
} else {
it.height(COMPOSER_HEIGHT)
it.wrapContentHeight(Alignment.Bottom)
}
},
)

View File

@@ -66,6 +66,7 @@ class RichTextComposerLayout @JvmOverloads constructor(
// There is no need to persist these values since they're always updated by the parent fragment
private var isFullScreen = false
private var hasRelatedMessage = false
private var composerMode: MessageComposerMode? = null
var isTextFormattingEnabled = true
set(value) {
@@ -118,9 +119,15 @@ class RichTextComposerLayout @JvmOverloads constructor(
private val dimensionConverter = DimensionConverter(resources)
fun setFullScreen(isFullScreen: Boolean, manageKeyboard: Boolean) {
fun setFullScreen(isFullScreen: Boolean, animated: Boolean, manageKeyboard: Boolean) {
if (!animated && views.composerLayout.layoutParams != null) {
views.composerLayout.updateLayoutParams<ViewGroup.LayoutParams> {
height =
if (isFullScreen) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT
}
}
editText.updateLayoutParams<ViewGroup.LayoutParams> {
height = if (isFullScreen) 0 else ViewGroup.LayoutParams.WRAP_CONTENT
height = if (isFullScreen) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT
}
updateTextFieldBorder(isFullScreen)
@@ -141,6 +148,7 @@ class RichTextComposerLayout @JvmOverloads constructor(
editText.hideKeyboard()
}
}
this.isFullScreen = isFullScreen
}
@@ -466,6 +474,9 @@ class RichTextComposerLayout @JvmOverloads constructor(
}
override fun renderComposerMode(mode: MessageComposerMode) {
if (this.composerMode == mode) return
this.composerMode = mode
if (mode is MessageComposerMode.Special) {
views.composerModeGroup.isVisible = true
replaceFormattedContent(mode.defaultContent)

View File

@@ -71,7 +71,7 @@ fun TextComposer(
}
}
setFullScreen(fullscreen, true)
setFullScreen(fullscreen, animated = false, manageKeyboard = true)
(this as MessageComposerView).apply {
setup(isInDarkMode, composerMode)
}
@@ -85,8 +85,9 @@ fun TextComposer(
// whenever the state changes
// Example of Compose -> View communication
val messageComposerView = (view as MessageComposerView)
view.setFullScreen(fullscreen, false)
// TODO messageComposerView.renderComposerMode(composerMode)
view.setFullScreen(fullscreen, animated = false, manageKeyboard = false)
// TODO: un-comment once we update to a version of the lib > 0.8.0
// messageComposerView.renderComposerMode(composerMode)
messageComposerView.sendButton.isInvisible = !composerCanSendMessage
messageComposerView.setTextIfDifferent(composerText ?: "")
}
@@ -122,7 +123,9 @@ private fun MessageComposerView.setup(isDarkMode: Boolean, composerMode: Message
editText.setHint(ElementR.string.room_message_placeholder)
emojiButton?.isVisible = true
sendButton.isVisible = true
// TODO renderComposerMode(composerMode)
editText.maxLines = MessageComposerView.MAX_LINES_WHEN_COLLAPSED
// TODO: un-comment once we update to a version of the lib > 0.8.0
// renderComposerMode(composerMode)
}
@Preview
@@ -138,4 +141,4 @@ fun TextComposerPreview() {
composerCanSendMessage = true,
composerText = "Message",
)
}
}