@ -57,7 +57,6 @@ import io.element.android.libraries.textcomposer.components.VoiceMessagePreview
@@ -57,7 +57,6 @@ import io.element.android.libraries.textcomposer.components.VoiceMessagePreview
import io.element.android.libraries.textcomposer.components.VoiceMessageRecorderButton
import io.element.android.libraries.textcomposer.components.VoiceMessageRecording
import io.element.android.libraries.textcomposer.components.markdown.MarkdownTextInput
import io.element.android.libraries.textcomposer.components.markdown.aMarkdownTextEditorState
import io.element.android.libraries.textcomposer.components.textInputRoundedCornerShape
import io.element.android.libraries.textcomposer.model.MessageComposerMode
import io.element.android.libraries.textcomposer.model.Suggestion
@ -65,6 +64,8 @@ import io.element.android.libraries.textcomposer.model.TextEditorState
@@ -65,6 +64,8 @@ import io.element.android.libraries.textcomposer.model.TextEditorState
import io.element.android.libraries.textcomposer.model.VoiceMessagePlayerEvent
import io.element.android.libraries.textcomposer.model.VoiceMessageRecorderEvent
import io.element.android.libraries.textcomposer.model.VoiceMessageState
import io.element.android.libraries.textcomposer.model.aTextEditorStateMarkdown
import io.element.android.libraries.textcomposer.model.aTextEditorStateRich
import io.element.android.libraries.ui.strings.CommonStrings
import io.element.android.wysiwyg.compose.RichTextEditor
import io.element.android.wysiwyg.compose.RichTextEditorState
@ -493,185 +494,156 @@ private fun TextInput(
@@ -493,185 +494,156 @@ private fun TextInput(
}
}
private fun aTextEditorStateMarkdownList ( ) = persistentListOf (
aTextEditorStateMarkdown ( initialText = " " , initialFocus = true ) ,
aTextEditorStateMarkdown ( initialText = " A message " , initialFocus = true ) ,
aTextEditorStateMarkdown (
initialText = " A message \n With several lines \n To preview larger textfields and long lines with overflow " ,
initialFocus = true ,
) ,
aTextEditorStateMarkdown ( initialText = " A message without focus " , initialFocus = false ) ,
)
private fun aTextEditorStateRichList ( ) = persistentListOf (
aTextEditorStateRich ( initialFocus = true ) ,
aTextEditorStateRich ( initialText = " A message " , initialFocus = true ) ,
aTextEditorStateRich (
initialText = " A message \n With several lines \n To preview larger textfields and long lines with overflow " ,
initialFocus = true
) ,
aTextEditorStateRich ( initialText = " A message without focus " , initialFocus = false ) ,
)
@PreviewsDayNight
@Composable
internal fun TextComposerSimplePreview ( ) = ElementPreview {
PreviewColumn (
items = persistentListOf (
{
ATextComposer (
TextEditorState . Markdown ( aMarkdownTextEditorState ( initialText = " " , initialFocus = true ) ) ,
voiceMessageState = VoiceMessageState . Idle ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
} ,
{
ATextComposer (
TextEditorState . Markdown ( aMarkdownTextEditorState ( initialText = " A message " , initialFocus = true ) ) ,
voiceMessageState = VoiceMessageState . Idle ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
} ,
{
ATextComposer (
TextEditorState . Markdown (
aMarkdownTextEditorState (
initialText = " A message \n With several lines \n To preview larger textfields and long lines with overflow " ,
initialFocus = true
)
) ,
voiceMessageState = VoiceMessageState . Idle ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
} ,
{
ATextComposer (
TextEditorState . Markdown ( aMarkdownTextEditorState ( initialText = " A message without focus " , initialFocus = false ) ) ,
voiceMessageState = VoiceMessageState . Idle ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
}
items = aTextEditorStateMarkdownList ( )
) { textEditorState ->
ATextComposer (
state = textEditorState ,
voiceMessageState = VoiceMessageState . Idle ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
)
}
}
@PreviewsDayNight
@Composable
internal fun TextComposerFormattingPreview ( ) = ElementPreview {
PreviewColumn ( items = persistentListOf ( {
ATextComposer (
TextEditorState . Rich ( aRichTextEditorState ( ) ) ,
voiceMessageState = VoiceMessageState . Idle ,
showTextFormatting = true ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
} , {
ATextComposer (
TextEditorState . Rich ( aRichTextEditorState ( initialText = " A message " ) ) ,
voiceMessageState = VoiceMessageState . Idle ,
showTextFormatting = true ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
} , {
PreviewColumn (
items = aTextEditorStateRichList ( )
) { textEditorState ->
ATextComposer (
TextEditorState . Rich (
aRichTextEditorState (
initialText = " A message \n With several lines \n To preview larger textfields and long lines with overflow " ,
)
) ,
state = textEditorState ,
voiceMessageState = VoiceMessageState . Idle ,
showTextFormatting = true ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
} ) )
}
}
@PreviewsDayNight
@Composable
internal fun TextComposerEditPreview ( ) = ElementPreview {
PreviewColumn ( items = persistentListOf ( {
PreviewColumn (
items = aTextEditorStateRichList ( )
) { textEditorState ->
ATextComposer (
TextEditorState . Rich ( aRichTextEditorState ( initialText = " A message " , initialFocus = true ) ) ,
state = textEditorState ,
voiceMessageState = VoiceMessageState . Idle ,
composerMode = aMessageComposerModeEdit ( ) ,
enableVoiceMessages = true ,
)
} ) )
}
}
@PreviewsDayNight
@Composable
internal fun MarkdownTextComposerEditPreview ( ) = ElementPreview {
PreviewColumn ( items = persistentListOf ( {
PreviewColumn (
items = aTextEditorStateMarkdownList ( )
) { textEditorState ->
ATextComposer (
TextEditorState . Markdown ( aMarkdownTextEditorState ( initialText = " A message " , initialFocus = true ) ) ,
state = textEditorState ,
voiceMessageState = VoiceMessageState . Idle ,
composerMode = aMessageComposerModeEdit ( ) ,
enableVoiceMessages = true ,
)
} ) )
}
}
@PreviewsDayNight
@Composable
internal fun TextComposerReplyPreview ( @PreviewParameter ( InReplyToDetailsProvider :: class ) inReplyToDetails : InReplyToDetails ) = ElementPreview {
ATextComposer (
state = TextEditorState . Rich ( aRichTextEditorState ( ) ) ,
voiceMessageState = VoiceMessageState . Idle ,
composerMode = aMessageComposerModeReply (
replyToDetails = inReplyToDetails ,
) ,
enableVoiceMessages = true ,
)
PreviewColumn (
items = aTextEditorStateRichList ( )
) { textEditorState ->
ATextComposer (
state = textEditorState ,
voiceMessageState = VoiceMessageState . Idle ,
composerMode = aMessageComposerModeReply (
replyToDetails = inReplyToDetails ,
) ,
enableVoiceMessages = true ,
)
}
}
@PreviewsDayNight
@Composable
internal fun TextComposerVoicePreview ( ) = ElementPreview {
@Composable
fun VoicePreview (
voiceMessageState : VoiceMessageState
) = ATextComposer (
TextEditorState . Rich ( aRichTextEditorState ( initialFocus = true ) ) ,
voiceMessageState = voiceMessageState ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
PreviewColumn ( items = persistentListOf ( {
VoicePreview ( voiceMessageState = VoiceMessageState . Recording ( 61. seconds , createFakeWaveform ( ) ) )
} , {
VoicePreview (
voiceMessageState = VoiceMessageState . Preview (
PreviewColumn (
items = persistentListOf (
VoiceMessageState . Recording ( 61. seconds , createFakeWaveform ( ) ) ,
VoiceMessageState . Preview (
isSending = false ,
isPlaying = false ,
showCursor = false ,
waveform = createFakeWaveform ( ) ,
time = 0. seconds ,
playbackProgress = 0.0f
)
)
} , {
VoicePreview (
voiceMessageState = VoiceMessageState . Preview (
) ,
VoiceMessageState . Preview (
isSending = false ,
isPlaying = true ,
showCursor = true ,
waveform = createFakeWaveform ( ) ,
time = 3. seconds ,
playbackProgress = 0.2f
)
)
} , {
VoicePreview (
voiceMessageState = VoiceMessageState . Preview (
) ,
VoiceMessageState . Preview (
isSending = true ,
isPlaying = false ,
showCursor = false ,
waveform = createFakeWaveform ( ) ,
time = 61. seconds ,
playbackProgress = 0.0f
)
) ,
)
} ) )
) { voiceMessageState ->
ATextComposer (
state = aTextEditorStateRich ( initialFocus = true ) ,
voiceMessageState = voiceMessageState ,
composerMode = MessageComposerMode . Normal ,
enableVoiceMessages = true ,
)
}
}
@Composable
private fun PreviewColumn (
items : ImmutableList < @Composable ( ) -> Unit > ,
private fun < T > PreviewColumn (
items : ImmutableList < T > ,
view : @Composable ( T ) -> Unit ,
) {
Column {
items . forEach { item ->
Box (
modifier = Modifier . height ( IntrinsicSize . Min )
) {
item ( )
view ( item )
}
}
}
@ -708,17 +680,6 @@ private fun ATextComposer(
@@ -708,17 +680,6 @@ private fun ATextComposer(
)
}
fun aRichTextEditorState (
initialText : String = " " ,
initialHtml : String = initialText ,
initialMarkdown : String = initialText ,
initialFocus : Boolean = false ,
) = RichTextEditorState (
initialHtml = initialHtml ,
initialMarkdown = initialMarkdown ,
initialFocus = initialFocus ,
)
fun aMessageComposerModeEdit (
eventOrTransactionId : EventOrTransactionId = EventId ( " $ 1234 " ) . toEventOrTransactionId ( ) ,
content : String = " Some text " ,