func getChunkedCellViewModelArray()

in AzureCommunicationUI/sdk/AzureCommunicationUICalling/Sources/Presentation/SwiftUI/Calling/Grid/ParticipantGridLayoutView.swift [40:67]


    func getChunkedCellViewModelArray() -> [[ParticipantGridCellViewModel]] {
        let cellCount = cellViewModels.count
        let vGridLayout = screenSize == .iphonePortraitScreenSize
        let isPortrait = orientation.isPortrait
        let isiPadLanscape = orientation.isLandscape && (screenSize == .ipadScreenSize)
        let isiPadPortrait = isPortrait && screenSize == .ipadScreenSize

        var screenBasedRowSize = 2
        if screenSize != .ipadScreenSize {
            // iPhone layout is kept the same way as before
            screenBasedRowSize = cellViewModels.count == 2 ? 1 : 2
        } else if cellCount <= 2 {
            // iPad layout for having 1 and 2 remote participants
            screenBasedRowSize = cellCount == 2 && isiPadPortrait ? 2 : 1
        } else if cellCount % 2 == 0 {
            // iPad layout for having 4, 6 and 8 remote participants
            screenBasedRowSize = (isiPadLanscape && cellCount < 8) || (isPortrait && cellCount < 6) ? 2 : 3
        } else if cellCount % 3 == 0 {
            // iPad layout for having 3 and 9 remote participants
            screenBasedRowSize = cellCount < 9 ? 2 : 3
        } else {
            // iPad layout for having 5 and 7 remote participants
            screenBasedRowSize = cellCount < 5 ? 2 : 3
        }

        return cellViewModels.chunkedAndReversed(into: screenBasedRowSize,
                                                 vGridLayout: vGridLayout || isiPadLanscape)
    }