Optimize code for Preview.

There should be no change in the preview.
This commit is contained in:
Benoit Marty 2024-10-30 15:10:13 +01:00
parent 53858f6206
commit d22072a606

View file

@ -499,101 +499,78 @@ private fun TextInput(
internal fun TextComposerSimplePreview() = ElementPreview { internal fun TextComposerSimplePreview() = ElementPreview {
PreviewColumn( PreviewColumn(
items = persistentListOf( items = persistentListOf(
{ aTextEditorStateMarkdown(initialText = "", initialFocus = true),
ATextComposer( aTextEditorStateMarkdown(initialText = "A message", initialFocus = true),
state = aTextEditorStateMarkdown(initialText = "", initialFocus = true), aTextEditorStateMarkdown(
voiceMessageState = VoiceMessageState.Idle, initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
composerMode = MessageComposerMode.Normal, initialFocus = true,
enableVoiceMessages = true, ),
) aTextEditorStateMarkdown(initialText = "A message without focus", initialFocus = false),
},
{
ATextComposer(
state = aTextEditorStateMarkdown(initialText = "A message", initialFocus = true),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
},
{
ATextComposer(
state = aTextEditorStateMarkdown(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
initialFocus = true,
),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
},
{
ATextComposer(
state = aTextEditorStateMarkdown(initialText = "A message without focus", initialFocus = false),
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}
) )
) ) { textEditorState ->
ATextComposer(
state = textEditorState,
voiceMessageState = VoiceMessageState.Idle,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}
} }
@PreviewsDayNight @PreviewsDayNight
@Composable @Composable
internal fun TextComposerFormattingPreview() = ElementPreview { internal fun TextComposerFormattingPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({ PreviewColumn(
ATextComposer( items = persistentListOf(
state = aTextEditorStateRich(), aTextEditorStateRich(),
voiceMessageState = VoiceMessageState.Idle, aTextEditorStateRich(initialText = "A message"),
showTextFormatting = true, aTextEditorStateRich(
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}, {
ATextComposer(
state = aTextEditorStateRich(initialText = "A message"),
voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}, {
ATextComposer(
state = aTextEditorStateRich(
initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow", initialText = "A message\nWith several lines\nTo preview larger textfields and long lines with overflow",
), ),
)
) { textEditorState ->
ATextComposer(
state = textEditorState,
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
showTextFormatting = true, showTextFormatting = true,
composerMode = MessageComposerMode.Normal, composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true, enableVoiceMessages = true,
) )
})) }
} }
@PreviewsDayNight @PreviewsDayNight
@Composable @Composable
internal fun TextComposerEditPreview() = ElementPreview { internal fun TextComposerEditPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({ PreviewColumn(
items = persistentListOf(
aTextEditorStateRich(initialText = "A message", initialFocus = true),
)
) { textEditorState ->
ATextComposer( ATextComposer(
state = aTextEditorStateRich(initialText = "A message", initialFocus = true), state = textEditorState,
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
composerMode = aMessageComposerModeEdit(), composerMode = aMessageComposerModeEdit(),
enableVoiceMessages = true, enableVoiceMessages = true,
) )
})) }
} }
@PreviewsDayNight @PreviewsDayNight
@Composable @Composable
internal fun MarkdownTextComposerEditPreview() = ElementPreview { internal fun MarkdownTextComposerEditPreview() = ElementPreview {
PreviewColumn(items = persistentListOf({ PreviewColumn(
items = persistentListOf(
aTextEditorStateMarkdown(initialText = "A message", initialFocus = true),
)
) { textEditorState ->
ATextComposer( ATextComposer(
state = aTextEditorStateMarkdown(initialText = "A message", initialFocus = true), state = textEditorState,
voiceMessageState = VoiceMessageState.Idle, voiceMessageState = VoiceMessageState.Idle,
composerMode = aMessageComposerModeEdit(), composerMode = aMessageComposerModeEdit(),
enableVoiceMessages = true, enableVoiceMessages = true,
) )
})) }
} }
@PreviewsDayNight @PreviewsDayNight
@ -612,63 +589,55 @@ internal fun TextComposerReplyPreview(@PreviewParameter(InReplyToDetailsProvider
@PreviewsDayNight @PreviewsDayNight
@Composable @Composable
internal fun TextComposerVoicePreview() = ElementPreview { internal fun TextComposerVoicePreview() = ElementPreview {
@Composable PreviewColumn(
fun VoicePreview( items = persistentListOf(
voiceMessageState: VoiceMessageState VoiceMessageState.Recording(61.seconds, createFakeWaveform()),
) = ATextComposer( VoiceMessageState.Preview(
state = aTextEditorStateRich(initialFocus = true),
voiceMessageState = voiceMessageState,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
PreviewColumn(items = persistentListOf({
VoicePreview(voiceMessageState = VoiceMessageState.Recording(61.seconds, createFakeWaveform()))
}, {
VoicePreview(
voiceMessageState = VoiceMessageState.Preview(
isSending = false, isSending = false,
isPlaying = false, isPlaying = false,
showCursor = false, showCursor = false,
waveform = createFakeWaveform(), waveform = createFakeWaveform(),
time = 0.seconds, time = 0.seconds,
playbackProgress = 0.0f playbackProgress = 0.0f
) ),
) VoiceMessageState.Preview(
}, {
VoicePreview(
voiceMessageState = VoiceMessageState.Preview(
isSending = false, isSending = false,
isPlaying = true, isPlaying = true,
showCursor = true, showCursor = true,
waveform = createFakeWaveform(), waveform = createFakeWaveform(),
time = 3.seconds, time = 3.seconds,
playbackProgress = 0.2f playbackProgress = 0.2f
) ),
) VoiceMessageState.Preview(
}, {
VoicePreview(
voiceMessageState = VoiceMessageState.Preview(
isSending = true, isSending = true,
isPlaying = false, isPlaying = false,
showCursor = false, showCursor = false,
waveform = createFakeWaveform(), waveform = createFakeWaveform(),
time = 61.seconds, time = 61.seconds,
playbackProgress = 0.0f playbackProgress = 0.0f
) ),
) )
})) ) { voiceMessageState ->
ATextComposer(
state = aTextEditorStateRich(initialFocus = true),
voiceMessageState = voiceMessageState,
composerMode = MessageComposerMode.Normal,
enableVoiceMessages = true,
)
}
} }
@Composable @Composable
private fun PreviewColumn( private fun <T> PreviewColumn(
items: ImmutableList<@Composable () -> Unit>, items: ImmutableList<T>,
view: @Composable (T) -> Unit,
) { ) {
Column { Column {
items.forEach { item -> items.forEach { item ->
Box( Box(
modifier = Modifier.height(IntrinsicSize.Min) modifier = Modifier.height(IntrinsicSize.Min)
) { ) {
item() view(item)
} }
} }
} }