Skip to content

Commit e9bbdae

Browse files
authored
fix: Crash on scroll pager in Call #WPB-16064 (#3883)
1 parent a42e7f5 commit e9bbdae

File tree

1 file changed

+21
-33
lines changed

1 file changed

+21
-33
lines changed

app/src/main/kotlin/com/wire/android/ui/calling/ongoing/participantsview/VerticalCallingPager.kt

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -76,32 +76,32 @@ fun VerticalCallingPager(
7676
.fillMaxWidth()
7777
.height(contentHeight)
7878
) {
79-
val pagerState = rememberPagerState(
80-
pageCount = { pagesCount(participants.size) }
81-
)
79+
// if PiP is enabled and more than one participant is present,
80+
// we need to remove the first participant(self user) from the list
81+
val participantsWithoutPip =
82+
if (BuildConfig.PICTURE_IN_PICTURE_ENABLED && participants.size > 1) {
83+
participants.subList(1, participants.size)
84+
} else {
85+
participants
86+
}
87+
val participantsPages = remember(participantsWithoutPip) {
88+
participantsWithoutPip.chunked(MAX_TILES_PER_PAGE)
89+
}
90+
91+
val pagerState = rememberPagerState(pageCount = { participantsPages.size })
92+
8293
Box {
8394
VerticalPager(
8495
state = pagerState,
8596
modifier = Modifier.fillMaxSize()
8697
) { pageIndex ->
8798
if (participants.isNotEmpty()) {
88-
// if PiP is enabled and more than one participant is present,
89-
// we need to remove the first participant(self user) from the list
90-
val newParticipants =
91-
if (BuildConfig.PICTURE_IN_PICTURE_ENABLED && participants.size > 1) {
92-
participants.subList(1, participants.size)
93-
} else {
94-
participants
95-
}
96-
val participantsChunkedList = remember(newParticipants) {
97-
newParticipants.chunked(MAX_TILES_PER_PAGE)
98-
}
99-
val participantsWithCameraOn by rememberUpdatedState(newParticipants.count { it.isCameraOn })
100-
val participantsWithScreenShareOn by rememberUpdatedState(newParticipants.count { it.isSharingScreen })
99+
val participantsWithCameraOn by rememberUpdatedState(participantsWithoutPip.count { it.isCameraOn })
100+
val participantsWithScreenShareOn by rememberUpdatedState(participantsWithoutPip.count { it.isSharingScreen })
101101

102-
if (participantsChunkedList[pageIndex].size <= MAX_ITEMS_FOR_HORIZONTAL_VIEW) {
102+
if (participantsPages[pageIndex].size <= MAX_ITEMS_FOR_HORIZONTAL_VIEW) {
103103
CallingHorizontalView(
104-
participants = participantsChunkedList[pageIndex],
104+
participants = participantsPages[pageIndex],
105105
isSelfUserMuted = isSelfUserMuted,
106106
isSelfUserCameraOn = isSelfUserCameraOn,
107107
contentHeight = contentHeight,
@@ -114,7 +114,7 @@ fun VerticalCallingPager(
114114
)
115115
} else {
116116
GroupCallGrid(
117-
participants = participantsChunkedList[pageIndex],
117+
participants = participantsPages[pageIndex],
118118
pageIndex = pageIndex,
119119
isSelfUserMuted = isSelfUserMuted,
120120
isSelfUserCameraOn = isSelfUserCameraOn,
@@ -134,12 +134,12 @@ fun VerticalCallingPager(
134134
participantsWithScreenShareOn, // Request video stream when someone starts sharing screen
135135
pagerState.currentPage // Request video stream when swiping to a different page on the grid
136136
) {
137-
requestVideoStreams(participantsChunkedList[pagerState.currentPage])
137+
requestVideoStreams(participantsPages[pagerState.currentPage])
138138
}
139139
}
140140
}
141141
// we don't need to display the indicator if we have one page and when it's in PiP mode
142-
if (pagesCount(participants.size) > 1 && !isInPictureInPictureMode) {
142+
if (participantsPages.size > 1 && !isInPictureInPictureMode) {
143143
Surface(
144144
shape = RoundedCornerShape(dimensions().corner16x),
145145
modifier = Modifier
@@ -160,18 +160,6 @@ fun VerticalCallingPager(
160160
}
161161
}
162162

163-
/**
164-
* Returns number of pages(with an already defined max number of tiles) needed to display x participants
165-
*/
166-
private fun pagesCount(size: Int): Int {
167-
val pages = size / MAX_TILES_PER_PAGE
168-
return if (size % MAX_TILES_PER_PAGE > 0) {
169-
pages + 1
170-
} else {
171-
pages
172-
}
173-
}
174-
175163
@Composable
176164
private fun PreviewVerticalCallingPager(participants: List<UICallParticipant>) {
177165
VerticalCallingPager(

0 commit comments

Comments
 (0)