Skip to content

Commit f916b1b

Browse files
committed
chore(fc): move typing indicator _into_ MessageList as a footer
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent f797875 commit f916b1b

3 files changed

Lines changed: 41 additions & 21 deletions

File tree

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/ConversationMessages.kt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
package xyz.flipchat.app.features.chat.conversation
22

3+
import androidx.compose.animation.AnimatedContent
4+
import androidx.compose.animation.core.Spring
35
import androidx.compose.animation.core.animateFloatAsState
6+
import androidx.compose.animation.core.spring
47
import androidx.compose.animation.core.tween
8+
import androidx.compose.animation.fadeIn
9+
import androidx.compose.animation.fadeOut
10+
import androidx.compose.animation.scaleIn
11+
import androidx.compose.animation.scaleOut
12+
import androidx.compose.animation.slideInVertically
13+
import androidx.compose.animation.slideOutVertically
14+
import androidx.compose.animation.togetherWith
515
import androidx.compose.foundation.Image
616
import androidx.compose.foundation.clickable
717
import androidx.compose.foundation.layout.Arrangement
@@ -44,6 +54,7 @@ import com.getcode.ui.components.chat.HostableAvatar
4454
import com.getcode.ui.components.chat.MessageList
4555
import com.getcode.ui.components.chat.MessageListEvent
4656
import com.getcode.ui.components.chat.MessageListPointerResult
57+
import com.getcode.ui.components.chat.TypingIndicator
4758
import com.getcode.ui.components.chat.messagecontents.LocalAnnouncementActionResolver
4859
import com.getcode.ui.components.chat.messagecontents.ResolvedAction
4960
import com.getcode.ui.components.chat.utils.ChatItem
@@ -116,6 +127,28 @@ internal fun ConversationMessages(
116127
current.sender.id == next?.sender?.id
117128
)
118129
},
130+
footer = {
131+
AnimatedContent(
132+
targetState = state.otherUsersTyping.isNotEmpty(),
133+
transitionSpec = {
134+
slideInVertically(
135+
animationSpec = spring(
136+
dampingRatio = Spring.DampingRatioMediumBouncy,
137+
stiffness = Spring.StiffnessLow
138+
)
139+
) { it } + scaleIn() + fadeIn() togetherWith
140+
fadeOut() + slideOutVertically { it }
141+
}
142+
) { show ->
143+
if (show) {
144+
TypingIndicator(
145+
modifier = Modifier
146+
.padding(horizontal = CodeTheme.dimens.inset),
147+
userImages = state.otherUsersTyping
148+
)
149+
}
150+
}
151+
},
119152
dispatch = { event ->
120153
when (event) {
121154
is MessageListEvent.AdvancePointer -> {

flipchatApp/src/main/kotlin/xyz/flipchat/app/features/chat/conversation/ConversationScreen.kt

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -257,26 +257,6 @@ private fun ConversationScreenContent(
257257
},
258258
verticalArrangement = Arrangement.spacedBy(CodeTheme.dimens.grid.x3),
259259
) {
260-
AnimatedContent(
261-
targetState = state.otherUsersTyping.isNotEmpty(),
262-
transitionSpec = {
263-
slideInVertically(
264-
animationSpec = spring(
265-
dampingRatio = Spring.DampingRatioMediumBouncy,
266-
stiffness = Spring.StiffnessLow
267-
)
268-
) { it } + scaleIn() + fadeIn() togetherWith fadeOut() + scaleOut() + slideOutVertically { it }
269-
}
270-
) { show ->
271-
if (show) {
272-
TypingIndicator(
273-
modifier = Modifier
274-
.padding(horizontal = CodeTheme.dimens.grid.x2),
275-
userImages = state.otherUsersTyping
276-
)
277-
}
278-
}
279-
280260
Column(
281261
modifier = Modifier
282262
.addIf(state.chattableState?.isActiveMember() == true) {

ui/components/src/main/kotlin/com/getcode/ui/components/chat/MessageList.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ fun MessageList(
7878
val nextGrouped = next?.chatMessageId == current.chatMessageId
7979
MessageListPointerResult(prevGrouped, nextGrouped)
8080
},
81+
footer: (@Composable () -> Unit)? = null,
8182
dispatch: (MessageListEvent) -> Unit = { },
8283
) {
8384
var hasSetAtUnread by rememberSaveable(key = "0") { mutableStateOf(false) }
@@ -97,10 +98,16 @@ fun MessageList(
9798
reverseLayout = true,
9899
contentPadding = PaddingValues(
99100
top = CodeTheme.dimens.inset,
100-
bottom = CodeTheme.dimens.grid.x2,
101+
bottom = CodeTheme.dimens.grid.x1,
101102
),
102103
verticalArrangement = Arrangement.Top,
103104
) {
105+
if (footer != null) {
106+
item {
107+
footer.invoke()
108+
}
109+
}
110+
104111
items(
105112
count = messages.itemCount,
106113
key = messages.itemKey { item -> item.key },

0 commit comments

Comments
 (0)