@@ -76,32 +76,32 @@ fun VerticalCallingPager(
76
76
.fillMaxWidth()
77
77
.height(contentHeight)
78
78
) {
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
+
82
93
Box {
83
94
VerticalPager (
84
95
state = pagerState,
85
96
modifier = Modifier .fillMaxSize()
86
97
) { pageIndex ->
87
98
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 })
101
101
102
- if (participantsChunkedList [pageIndex].size <= MAX_ITEMS_FOR_HORIZONTAL_VIEW ) {
102
+ if (participantsPages [pageIndex].size <= MAX_ITEMS_FOR_HORIZONTAL_VIEW ) {
103
103
CallingHorizontalView (
104
- participants = participantsChunkedList [pageIndex],
104
+ participants = participantsPages [pageIndex],
105
105
isSelfUserMuted = isSelfUserMuted,
106
106
isSelfUserCameraOn = isSelfUserCameraOn,
107
107
contentHeight = contentHeight,
@@ -114,7 +114,7 @@ fun VerticalCallingPager(
114
114
)
115
115
} else {
116
116
GroupCallGrid (
117
- participants = participantsChunkedList [pageIndex],
117
+ participants = participantsPages [pageIndex],
118
118
pageIndex = pageIndex,
119
119
isSelfUserMuted = isSelfUserMuted,
120
120
isSelfUserCameraOn = isSelfUserCameraOn,
@@ -134,12 +134,12 @@ fun VerticalCallingPager(
134
134
participantsWithScreenShareOn, // Request video stream when someone starts sharing screen
135
135
pagerState.currentPage // Request video stream when swiping to a different page on the grid
136
136
) {
137
- requestVideoStreams(participantsChunkedList [pagerState.currentPage])
137
+ requestVideoStreams(participantsPages [pagerState.currentPage])
138
138
}
139
139
}
140
140
}
141
141
// 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) {
143
143
Surface (
144
144
shape = RoundedCornerShape (dimensions().corner16x),
145
145
modifier = Modifier
@@ -160,18 +160,6 @@ fun VerticalCallingPager(
160
160
}
161
161
}
162
162
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
-
175
163
@Composable
176
164
private fun PreviewVerticalCallingPager (participants : List <UICallParticipant >) {
177
165
VerticalCallingPager (
0 commit comments