Configured and applied SwiftFormat

This commit is contained in:
Stefan Ceriu
2022-09-27 10:17:22 +03:00
committed by Stefan Ceriu
parent ff2e6ddfa7
commit 43c28d23b7
663 changed files with 2329 additions and 2840 deletions
@@ -14,8 +14,8 @@
// limitations under the License.
//
import SwiftUI
import CommonKit
import SwiftUI
struct SpaceSelectorCoordinatorParameters {
let session: MXSession
@@ -38,7 +38,6 @@ struct SpaceSelectorCoordinatorParameters {
}
final class SpaceSelectorCoordinator: Coordinator, Presentable {
// MARK: - Properties
// MARK: Private
@@ -99,7 +98,7 @@ final class SpaceSelectorCoordinator: Coordinator, Presentable {
}
func toPresentable() -> UIViewController {
return self.hostingViewController
hostingViewController
}
// MARK: - Private
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -38,7 +38,7 @@ enum MockSpaceSelectorScreenState: MockScreenState, CaseIterable {
}
/// Generate the view struct for the screen state.
var screenView: ([Any], AnyView) {
var screenView: ([Any], AnyView) {
let service: MockSpaceSelectorService
switch self {
case .emptyList:
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,12 +14,11 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
import MatrixSDK
class SpaceSelectorService: SpaceSelectorServiceProtocol {
// MARK: - Properties
// MARK: Private
@@ -65,7 +64,7 @@ class SpaceSelectorService: SpaceSelectorServiceProtocol {
var itemList: [SpaceSelectorListItemData] = []
itemList.append(contentsOf: invitedSpaces)
if showHomeSpace && parentSpaceId == nil {
if showHomeSpace, parentSpaceId == nil {
itemList.append(SpaceSelectorListItemData(id: SpaceSelectorConstants.homeSpaceId, icon: Asset.Images.sideMenuActionIconFeedback.image, displayName: VectorL10n.allChatsTitle, isJoined: true))
}
itemList.append(contentsOf: joinedSpaces)
@@ -93,14 +92,14 @@ class SpaceSelectorService: SpaceSelectorServiceProtocol {
self.session = session
self.parentSpaceId = parentSpaceId
self.showHomeSpace = showHomeSpace
self.spaceListSubject = CurrentValueSubject([])
self.parentSpaceNameSubject = CurrentValueSubject(nil)
spaceListSubject = CurrentValueSubject([])
parentSpaceNameSubject = CurrentValueSubject(nil)
self.selectedSpaceId = selectedSpaceId
spaceListSubject.send(spaceList)
parentSpaceNameSubject.send(parentSpaceName)
NotificationCenter.default.addObserver(self, selector: #selector(self.spaceServiceDidUpdate), name: MXSpaceService.didBuildSpaceGraph, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(spaceServiceDidUpdate), name: MXSpaceService.didBuildSpaceGraph, object: nil)
}
@objc private func spaceServiceDidUpdate() {
@@ -108,7 +107,7 @@ class SpaceSelectorService: SpaceSelectorServiceProtocol {
}
}
fileprivate extension SpaceSelectorListItemData {
private extension SpaceSelectorListItemData {
static func itemData(with space: MXSpace, notificationCounter: MXSpaceNotificationCounter) -> SpaceSelectorListItemData? {
guard let summary = space.summary else {
return nil
@@ -116,7 +115,7 @@ fileprivate extension SpaceSelectorListItemData {
let notificationState = notificationCounter.notificationState(forSpaceWithId: space.spaceId)
return SpaceSelectorListItemData(id:summary.roomId,
return SpaceSelectorListItemData(id: summary.roomId,
avatar: summary.room.avatarData,
displayName: summary.displayname,
notificationCount: notificationState?.groupMissedDiscussionsCount ?? 0,
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,12 +14,11 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
import UIKit
class MockSpaceSelectorService: SpaceSelectorServiceProtocol {
static let homeItem = SpaceSelectorListItemData(id: SpaceSelectorConstants.homeSpaceId, avatar: nil, icon: UIImage(systemName: "house"), displayName: "All Chats", notificationCount: 0, highlightedNotificationCount: 0, hasSubItems: false)
static let defaultSpaceList = [
homeItem,
@@ -35,8 +34,8 @@ class MockSpaceSelectorService: SpaceSelectorServiceProtocol {
var selectedSpaceId: String?
init(spaceList: [SpaceSelectorListItemData] = defaultSpaceList, parentSpaceName: String? = nil, selectedSpaceId: String = SpaceSelectorConstants.homeSpaceId) {
self.spaceListSubject = CurrentValueSubject(spaceList)
self.parentSpaceNameSubject = CurrentValueSubject(parentSpaceName)
spaceListSubject = CurrentValueSubject(spaceList)
parentSpaceNameSubject = CurrentValueSubject(parentSpaceName)
self.selectedSpaceId = selectedSpaceId
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +14,8 @@
// limitations under the License.
//
import Foundation
import Combine
import Foundation
protocol SpaceSelectorServiceProtocol {
var spaceListSubject: CurrentValueSubject<[SpaceSelectorListItemData], Never> { get }
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -76,7 +76,7 @@ struct SpaceSelectorListItemData {
}
}
extension SpaceSelectorListItemData: Identifiable, Equatable {}
extension SpaceSelectorListItemData: Identifiable, Equatable { }
enum SpaceSelectorViewModelResult {
/// Cancel button has been presed
@@ -14,15 +14,14 @@
// limitations under the License.
//
import SwiftUI
import Combine
import SwiftUI
typealias SpaceSelectorViewModelType = StateStoreViewModel<SpaceSelectorViewState,
Never,
SpaceSelectorViewAction>
Never,
SpaceSelectorViewAction>
class SpaceSelectorViewModel: SpaceSelectorViewModelType, SpaceSelectorViewModelProtocol {
// MARK: - Properties
// MARK: Private
@@ -36,7 +35,7 @@ class SpaceSelectorViewModel: SpaceSelectorViewModelType, SpaceSelectorViewModel
// MARK: - Setup
static func makeViewModel(service: SpaceSelectorServiceProtocol, showCancel: Bool) -> SpaceSelectorViewModelProtocol {
return SpaceSelectorViewModel(service: service, showCancel: showCancel)
SpaceSelectorViewModel(service: service, showCancel: showCancel)
}
private init(service: SpaceSelectorServiceProtocol, showCancel: Bool) {
@@ -55,7 +54,7 @@ class SpaceSelectorViewModel: SpaceSelectorViewModelType, SpaceSelectorViewModel
private func setupObservers() {
service.spaceListSubject.sink { [weak self] spaceList in
self?.state.items = spaceList
self?.state.items = spaceList
}
.store(in: &cancellables)
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import Foundation
protocol SpaceSelectorViewModelProtocol {
var completion: ((SpaceSelectorViewModelResult) -> Void)? { get set }
static func makeViewModel(service: SpaceSelectorServiceProtocol, showCancel: Bool) -> SpaceSelectorViewModelProtocol
var context: SpaceSelectorViewModelType.Context { get }
@@ -14,16 +14,15 @@
// limitations under the License.
//
import XCTest
import RiotSwiftUI
import XCTest
class SpaceSelectorUITests: MockScreenTestCase {
func testInitialDisplay() {
app.goToScreenWithIdentifier(MockSpaceSelectorScreenState.initialList.title)
let disclosureButtons = app.buttons.matching(identifier: "disclosureButton").allElementsBoundByIndex
XCTAssertEqual(disclosureButtons.count, MockSpaceSelectorService.defaultSpaceList.filter { $0.hasSubItems }.count)
XCTAssertEqual(disclosureButtons.count, MockSpaceSelectorService.defaultSpaceList.filter(\.hasSubItems).count)
let notificationBadges = app.staticTexts.matching(identifier: "notificationBadge").allElementsBoundByIndex
let itemsWithNotifications = MockSpaceSelectorService.defaultSpaceList.filter { $0.notificationCount > 0 || !$0.isJoined }
@@ -65,5 +64,4 @@ class SpaceSelectorUITests: MockScreenTestCase {
XCTAssertEqual(app.staticTexts["emptyListPlaceholderMessage"].exists, exists)
XCTAssertEqual(app.buttons["createSpaceButton"].exists, exists)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,13 +14,12 @@
// limitations under the License.
//
import XCTest
import Combine
import XCTest
@testable import RiotSwiftUI
class SpaceSelectorViewModelTests: XCTestCase {
var service: MockSpaceSelectorService!
var viewModel: SpaceSelectorViewModelProtocol!
var context: SpaceSelectorViewModelType.Context!
@@ -37,5 +36,4 @@ class SpaceSelectorViewModelTests: XCTestCase {
XCTAssertEqual(context.viewState.items, MockSpaceSelectorService.defaultSpaceList)
XCTAssertEqual(context.viewState.navigationTitle, VectorL10n.spaceSelectorTitle)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
struct SpaceSelector: View {
// MARK: - Properties
// MARK: Private
@@ -53,12 +52,11 @@ struct SpaceSelector: View {
notificationCount: item.notificationCount,
highlightedNotificationCount: item.highlightedNotificationCount,
disclosureAction: {
viewModel.send(viewAction: .spaceDisclosure(item))
viewModel.send(viewAction: .spaceDisclosure(item))
})
.onTapGesture {
viewModel.send(viewAction: .spaceSelected(item))
}
)
.onTapGesture {
viewModel.send(viewAction: .spaceSelected(item))
}
}
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -70,7 +70,7 @@ struct SpaceSelectorListRow: View {
.renderingMode(.template)
.foregroundColor(theme.colors.secondaryContent)
}
if hasSubItems && isJoined {
if hasSubItems, isJoined {
Button {
disclosureAction?()
} label: {
@@ -91,7 +91,7 @@ struct SpaceSelectorListRow: View {
}
private func badge(with text: String, color: Color) -> some View {
return Text(text)
Text(text)
.multilineTextAlignment(.center)
.foregroundColor(theme.colors.background)
.font(theme.fonts.footnote)
@@ -106,7 +106,6 @@ struct SpaceSelectorListRow: View {
// MARK: - Previews
struct SpaceSelectorListRow_Previews: PreviewProvider {
static var previews: some View {
sampleView.theme(.light).preferredColorScheme(.light)
sampleView.theme(.dark).preferredColorScheme(.dark)
@@ -121,5 +120,4 @@ struct SpaceSelectorListRow_Previews: PreviewProvider {
SpaceSelectorListRow(avatar: nil, icon: UIImage(systemName: "house"), displayName: "Space name", hasSubItems: true, isJoined: true, isSelected: true, notificationCount: 99, highlightedNotificationCount: 1, disclosureAction: nil)
}
}
}