mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Merge branch 'feature/bma/optimizeLazyColumn' into develop
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
|
||||||
|
### Jetpack Compose
|
||||||
|
|
||||||
|
https://developer.android.com/jetpack/compose/mental-model
|
||||||
|
|
||||||
|
https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/docs/compose-api-guidelines.md#api-guidelines-for-jetpack-compose
|
||||||
+20
-2
@@ -10,7 +10,7 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
|
|||||||
import androidx.compose.foundation.layout.*
|
import androidx.compose.foundation.layout.*
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
import androidx.compose.foundation.lazy.LazyListState
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.lazy.itemsIndexed
|
import androidx.compose.foundation.lazy.items
|
||||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.ExperimentalMaterialApi
|
import androidx.compose.material.ExperimentalMaterialApi
|
||||||
@@ -230,7 +230,11 @@ fun TimelineItems(
|
|||||||
verticalArrangement = Arrangement.Bottom,
|
verticalArrangement = Arrangement.Bottom,
|
||||||
reverseLayout = true
|
reverseLayout = true
|
||||||
) {
|
) {
|
||||||
itemsIndexed(timelineItems) { index, timelineItem ->
|
items(
|
||||||
|
items = timelineItems,
|
||||||
|
contentType = { timelineItem -> timelineItem.contentType() },
|
||||||
|
key = { timelineItem -> timelineItem.key() },
|
||||||
|
) { timelineItem ->
|
||||||
TimelineItemRow(
|
TimelineItemRow(
|
||||||
timelineItem = timelineItem,
|
timelineItem = timelineItem,
|
||||||
onClick = onClick,
|
onClick = onClick,
|
||||||
@@ -245,6 +249,20 @@ fun TimelineItems(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun MessagesTimelineItemState.key(): String {
|
||||||
|
return when (this) {
|
||||||
|
is MessagesTimelineItemState.MessageEvent -> id
|
||||||
|
is MessagesTimelineItemState.Virtual -> id
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun MessagesTimelineItemState.contentType(): Int {
|
||||||
|
return when (this) {
|
||||||
|
is MessagesTimelineItemState.MessageEvent -> 0
|
||||||
|
is MessagesTimelineItemState.Virtual -> 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun TimelineItemRow(
|
fun TimelineItemRow(
|
||||||
|
|||||||
+6
-1
@@ -122,7 +122,10 @@ fun RoomListContent(
|
|||||||
.nestedScroll(nestedScrollConnection),
|
.nestedScroll(nestedScrollConnection),
|
||||||
state = lazyListState,
|
state = lazyListState,
|
||||||
) {
|
) {
|
||||||
items(roomSummaries) { room ->
|
items(
|
||||||
|
items = roomSummaries,
|
||||||
|
contentType = { room -> room.contentType() },
|
||||||
|
) { room ->
|
||||||
RoomSummaryRow(room = room, onClick = ::onRoomClicked)
|
RoomSummaryRow(room = room, onClick = ::onRoomClicked)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,6 +137,8 @@ fun RoomListContent(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun RoomListRoomSummary.contentType() = isPlaceholder
|
||||||
|
|
||||||
private fun LazyListState.isScrolled(): Boolean {
|
private fun LazyListState.isScrolled(): Boolean {
|
||||||
return firstVisibleItemIndex > 0 || firstVisibleItemScrollOffset > 0
|
return firstVisibleItemIndex > 0 || firstVisibleItemScrollOffset > 0
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user