Add SwiftFormat to the project. (#129)

* Run swiftformat for whitespace.
* Run swiftformat with some rules.
This commit is contained in:
Doug
2022-07-06 14:49:05 +01:00
committed by GitHub
parent 26d8affaa8
commit 02eb4b35e2
188 changed files with 759 additions and 717 deletions
@@ -6,8 +6,8 @@
// Copyright © 2022 Element. All rights reserved.
//
import UIKit
import MatrixRustSDK
import UIKit
@MainActor
protocol AuthenticationCoordinatorDelegate: AnyObject {
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,8 +14,8 @@
// limitations under the License.
//
import SwiftUI
import MatrixRustSDK
import SwiftUI
struct LoginCoordinatorParameters {
/// The service used to authenticate the user.
@@ -56,7 +56,7 @@ final class LoginCoordinator: Coordinator, Presentable {
// Must be used only internally
var childCoordinators: [Coordinator] = []
var callback: (@MainActor (LoginCoordinatorAction) -> Void)?
var callback: (@MainActor(LoginCoordinatorAction) -> Void)?
// MARK: - Setup
@@ -73,6 +73,7 @@ final class LoginCoordinator: Coordinator, Presentable {
}
// MARK: - Public
func start() {
MXLog.debug("[LoginCoordinator] did start.")
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -53,7 +53,7 @@ struct LoginViewState: BindableState {
/// Data about the selected homeserver.
var homeserver: LoginHomeserver
/// Whether a new homeserver is currently being loaded.
var isLoading: Bool = false
var isLoading = false
/// View state that can be bound to from SwiftUI.
var bindings: LoginBindings
@@ -24,7 +24,7 @@ class LoginViewModel: LoginViewModelType, LoginViewModelProtocol {
// MARK: Public
var callback: (@MainActor (LoginViewModelAction) -> Void)?
var callback: (@MainActor(LoginViewModelAction) -> Void)?
// MARK: - Setup
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,7 @@ import Foundation
@MainActor
protocol LoginViewModelProtocol {
var callback: (@MainActor (LoginViewModelAction) -> Void)? { get set }
var callback: (@MainActor(LoginViewModelAction) -> Void)? { get set }
var context: LoginViewModelType.Context { get }
/// Update the view to reflect that a new homeserver is being loaded.
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -46,7 +46,7 @@ final class ServerSelectionCoordinator: Coordinator, Presentable {
// Must be used only internally
var childCoordinators: [Coordinator] = []
var callback: (@MainActor (ServerSelectionCoordinatorAction) -> Void)?
var callback: (@MainActor(ServerSelectionCoordinatorAction) -> Void)?
// MARK: - Setup
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -26,7 +26,7 @@ class ServerSelectionViewModel: ServerSelectionViewModelType, ServerSelectionVie
// MARK: Public
var callback: (@MainActor (ServerSelectionViewModelAction) -> Void)?
var callback: (@MainActor(ServerSelectionViewModelAction) -> Void)?
// MARK: - Setup
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,7 @@ import Foundation
@MainActor
protocol ServerSelectionViewModelProtocol {
var callback: (@MainActor (ServerSelectionViewModelAction) -> Void)? { get set }
var callback: (@MainActor(ServerSelectionViewModelAction) -> Void)? { get set }
var context: ServerSelectionViewModelType.Context { get }
/// Displays an error to the user.
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,7 +18,7 @@ import SwiftUI
@available(iOS 14, *)
typealias BugReportViewModelType = StateStoreViewModel<BugReportViewState,
BugReportViewAction>
BugReportViewAction>
@available(iOS 14, *)
class BugReportViewModel: BugReportViewModelType, BugReportViewModelProtocol {
@@ -50,7 +50,7 @@ class BugReportViewModel: BugReportViewModelType, BugReportViewModelProtocol {
files: files)
MXLog.info("[BugReportViewModel] submitBugReport succeeded, result: \(result.reportUrl)")
callback?(.submitFinished)
} catch let error {
} catch {
MXLog.error("[BugReportViewModel] submitBugReport failed: \(error)")
callback?(.submitFailed(error: error))
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -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 SwiftUI
import Combine
import SwiftUI
struct HomeScreenCoordinatorParameters {
let userSession: UserSessionProtocol
@@ -108,12 +108,11 @@ final class HomeScreenCoordinator: Coordinator, Presentable {
}
// MARK: - Public
func start() {
}
func start() { }
func toPresentable() -> UIViewController {
return self.hostingController
hostingController
}
// MARK: - Private
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -34,14 +34,14 @@ struct HomeScreenViewState: BindableState {
var userDisplayName: String?
var userAvatar: UIImage?
var showSessionVerificationBanner: Bool = false
var showSessionVerificationBanner = false
var rooms: [HomeScreenRoom] = []
var isLoadingRooms: Bool = false
var isLoadingRooms = false
var visibleDMs: [HomeScreenRoom] {
searchFilteredRooms.filter { $0.isDirect }
searchFilteredRooms.filter(\.isDirect)
}
var visibleRooms: [HomeScreenRoom] {
@@ -62,7 +62,7 @@ struct HomeScreenViewState: BindableState {
}
struct HomeScreenViewStateBindings {
var searchQuery: String = ""
var searchQuery = ""
}
struct HomeScreenRoom: Identifiable, Equatable {
@@ -14,8 +14,8 @@
// limitations under the License.
//
import SwiftUI
import Combine
import SwiftUI
typealias HomeScreenViewModelType = StateStoreViewModel<HomeScreenViewState, HomeScreenViewAction>
@@ -65,7 +65,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
roomUpdateListeners.removeAll()
roomSummaries.forEach({ roomSummary in
roomSummaries.forEach { roomSummary in
roomSummary.callbacks
.receive(on: DispatchQueue.main)
.sink { [weak self] callback in
@@ -81,7 +81,7 @@ class HomeScreenViewModel: HomeScreenViewModelType, HomeScreenViewModelProtocol
}
}
.store(in: &roomUpdateListeners)
})
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -167,7 +167,7 @@ struct RoomCell: View {
}
private func roomName(_ room: HomeScreenRoom) -> String {
room.displayName ?? room.id + (room.isEncrypted ? "🛡": "")
room.displayName ?? room.id + (room.isEncrypted ? "🛡" : "")
}
}
@@ -55,11 +55,10 @@ final class RoomScreenCoordinator: Coordinator, Presentable {
}
// MARK: - Public
func start() {
}
func start() { }
func toPresentable() -> UIViewController {
return self.roomScreenHostingController
roomScreenHostingController
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,9 +17,7 @@
import Foundation
import UIKit
enum RoomScreenViewModelAction {
}
enum RoomScreenViewModelAction { }
enum TimelineItemContextMenuAction: Hashable {
case copy
@@ -35,14 +33,14 @@ enum RoomScreenViewAction {
}
struct RoomScreenViewState: BindableState {
var roomTitle: String = ""
var roomTitle = ""
var roomAvatar: UIImage?
var roomEncryptionBadge: UIImage?
var items: [RoomTimelineViewProvider] = []
var isBackPaginating = false
var bindings: RoomScreenViewStateBindings
var contextMenuBuilder: (@MainActor (_ itemId: String) -> TimelineItemContextMenu)?
var contextMenuBuilder: (@MainActor(_ itemId: String) -> TimelineItemContextMenu)?
var sendButtonDisabled: Bool {
bindings.composerText.count == 0
@@ -20,7 +20,7 @@ typealias RoomScreenViewModelType = StateStoreViewModel<RoomScreenViewState, Roo
class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol {
private struct Constants {
private enum Constants {
static let backPaginationPageSize: UInt = 30
}
@@ -96,7 +96,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
// MARK: - Private
private func buildTimelineViews() {
let stateItems = timelineController.timelineItems.map { item in
let stateItems = timelineController.timelineItems.map { item in
timelineViewFactory.buildTimelineViewFor(timelineItem: item)
}
@@ -106,13 +106,13 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
// MARK: ContextMenus
private func buildContexMenuForItemId(_ itemId: String) -> TimelineItemContextMenu {
TimelineItemContextMenu(contextMenuActions: self.contextMenuActionsForItemId(itemId)) { [weak self] action in
TimelineItemContextMenu(contextMenuActions: contextMenuActionsForItemId(itemId)) { [weak self] action in
self?.processContentMenuAction(action, itemId: itemId)
}
}
private func contextMenuActionsForItemId(_ itemId: String) -> [TimelineItemContextMenuAction] {
guard let timelineItem = self.timelineController.timelineItems.first(where: { $0.id == itemId }),
guard let timelineItem = timelineController.timelineItems.first(where: { $0.id == itemId }),
timelineItem is EventBasedTimelineItemProtocol else {
return []
}
@@ -121,7 +121,7 @@ class RoomScreenViewModel: RoomScreenViewModelType, RoomScreenViewModelProtocol
}
private func processContentMenuAction(_ action: TimelineItemContextMenuAction, itemId: String) {
guard let timelineItem = self.timelineController.timelineItems.first(where: { $0.id == itemId }),
guard let timelineItem = timelineController.timelineItems.first(where: { $0.id == itemId }),
let item = timelineItem as? EventBasedTimelineItemProtocol else {
return
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -6,8 +6,8 @@
// Copyright © 2022 Element. All rights reserved.
//
import UIKit
import Combine
import UIKit
class ListTableViewAdapter: NSObject, UITableViewDelegate {
@@ -79,8 +79,8 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate {
}
guard let tableView = tableView,
tableView.numberOfSections > 0 else {
return
tableView.numberOfSections > 0 else {
return
}
let currentItemCount = tableView.numberOfRows(inSection: 0)
@@ -89,7 +89,7 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate {
case .bottomOffset:
tableView.scrollToRow(at: .init(row: max(0, currentItemCount - 1), section: 0), at: .bottom, animated: false)
case .topOffset(let indexPath, let previousItemCount):
let row = indexPath.row + max(0, (currentItemCount - previousItemCount))
let row = indexPath.row + max(0, currentItemCount - previousItemCount)
if row < currentItemCount {
tableView.scrollToRow(at: .init(row: row, section: 0), at: .top, animated: false)
}
@@ -108,8 +108,8 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate {
func scrollToBottom(animated: Bool = false) {
guard let tableView = tableView,
tableView.numberOfSections > 0 else {
return
tableView.numberOfSections > 0 else {
return
}
let currentItemCount = tableView.numberOfRows(inSection: 0)
@@ -180,9 +180,9 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate {
scrollViewBottomVisiblePublisher.send(isBottomVisible)
}
if !draggingInitiated && tableView.isDragging {
if !draggingInitiated, tableView.isDragging {
draggingInitiated = true
} else if draggingInitiated && !tableView.isDragging {
} else if draggingInitiated, !tableView.isDragging {
draggingInitiated = false
scrollViewDidRestPublisher.send(())
}
@@ -193,7 +193,7 @@ class ListTableViewAdapter: NSObject, UITableViewDelegate {
sender.state == .ended,
draggingInitiated == true,
!tableView.isDecelerating else {
return
return
}
draggingInitiated = false
@@ -23,7 +23,7 @@ struct MessageComposerTextField: View {
init(placeholder: String, text: Binding<String>, maxHeight: CGFloat) {
self.placeholder = placeholder
self._text = text
_text = text
self.maxHeight = maxHeight
}
@@ -36,7 +36,7 @@ struct MessageComposerTextField: View {
}
private var borderWidth: CGFloat {
return isEditing ? 2.0 : 1.0
isEditing ? 2.0 : 1.0
}
var body: some View {
@@ -89,18 +89,18 @@ private struct UITextViewWrapper: UIViewRepresentable {
}
func updateUIView(_ view: UITextView, context: UIViewRepresentableContext<UITextViewWrapper>) {
if view.text != self.text {
view.text = self.text
if view.text != text {
view.text = text
}
UITextViewWrapper.recalculateHeight(view: view, result: $calculatedHeight, maxHeight: maxHeight)
}
func makeCoordinator() -> Coordinator {
return Coordinator(text: $text,
height: $calculatedHeight,
isEditing: $isEditing,
maxHeight: maxHeight)
Coordinator(text: $text,
height: $calculatedHeight,
isEditing: $isEditing,
maxHeight: maxHeight)
}
fileprivate static func recalculateHeight(view: UIView, result: Binding<CGFloat>, maxHeight: CGFloat) {
@@ -124,7 +124,7 @@ private struct UITextViewWrapper: UIViewRepresentable {
init(text: Binding<String>, height: Binding<CGFloat>, isEditing: Binding<Bool>, maxHeight: CGFloat) {
self.text = text
self.calculatedHeight = height
calculatedHeight = height
self.isEditing = isEditing
self.maxHeight = maxHeight
}
@@ -137,7 +137,7 @@ private struct UITextViewWrapper: UIViewRepresentable {
}
func textView(_ textView: UITextView, shouldChangeTextIn range: NSRange, replacementText text: String) -> Bool {
return true
true
}
func textViewDidBeginEditing(_ textView: UITextView) {
@@ -6,9 +6,9 @@
// Copyright © 2022 Element. All rights reserved.
//
import Combine
import Foundation
import SwiftUI
import Combine
import Introspect
@@ -65,8 +65,7 @@ struct RoomHeaderView_Previews: PreviewProvider {
let viewModel = RoomScreenViewModel(timelineController: MockRoomTimelineController(),
timelineViewFactory: RoomTimelineViewFactory(),
roomName: "Some Room name",
roomAvatar: Asset.Images.appLogo.image
)
roomAvatar: Asset.Images.appLogo.image)
RoomHeaderView(context: viewModel.context)
.previewLayout(.sizeThatFits)
@@ -79,8 +78,7 @@ struct RoomHeaderView_Previews: PreviewProvider {
timelineViewFactory: RoomTimelineViewFactory(),
roomName: "Some Room name",
roomAvatar: nil,
roomEncryptionBadge: Asset.Images.encryptionTrusted.image
)
roomEncryptionBadge: Asset.Images.encryptionTrusted.image)
RoomHeaderView(context: viewModel.context)
.previewLayout(.sizeThatFits)
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -89,7 +89,7 @@ struct TimelineItemBubbledStylerView<Content: View>: View {
}
private var shouldAvoidBubbling: Bool {
return timelineItem is ImageRoomTimelineItem
timelineItem is ImageRoomTimelineItem
}
private var bubbleColor: Color {
@@ -108,7 +108,7 @@ struct TimelineItemBubbledStylerView_Previews: PreviewProvider {
@ViewBuilder
static var body: some View {
VStack(alignment: .leading) {
ForEach((1..<MockRoomTimelineController().timelineItems.count), id: \.self) { index in
ForEach(1..<MockRoomTimelineController().timelineItems.count, id: \.self) { index in
let item = MockRoomTimelineController().timelineItems[index]
RoomTimelineViewFactory().buildTimelineViewFor(timelineItem: item)
}
@@ -48,7 +48,7 @@ struct TimelineItemPlainStylerView_Previews: PreviewProvider {
@ViewBuilder
static var body: some View {
VStack(alignment: .leading) {
ForEach((1..<MockRoomTimelineController().timelineItems.count), id: \.self) { index in
ForEach(1..<MockRoomTimelineController().timelineItems.count, id: \.self) { index in
let item = MockRoomTimelineController().timelineItems[index]
RoomTimelineViewFactory().buildTimelineViewFor(timelineItem: item)
}
@@ -48,11 +48,11 @@ struct EmoteRoomTimelineView_Previews: PreviewProvider {
}
private static func itemWith(text: String, timestamp: String, senderId: String) -> EmoteRoomTimelineItem {
return EmoteRoomTimelineItem(id: UUID().uuidString,
text: text,
timestamp: timestamp,
shouldShowSenderDetails: true,
isOutgoing: false,
senderId: senderId)
EmoteRoomTimelineItem(id: UUID().uuidString,
text: text,
timestamp: timestamp,
shouldShowSenderDetails: true,
isOutgoing: false,
senderId: senderId)
}
}
@@ -45,25 +45,26 @@ struct FormattedBodyText_Previews: PreviewProvider {
@ViewBuilder
static var body: some View {
let htmlStrings = [
"""
Text before blockquote
<blockquote>
<b>bold</b> <i>italic</i>
</blockquote>
Text after blockquote
""",
"""
<blockquote>First blockquote with a <a href=\"https://www.matrix.org/\">link</a> in it</blockquote>
<blockquote>Second blockquote with a <a href=\"https://www.matrix.org/\">link</a> in it</blockquote>
<blockquote>Third blockquote with a <a href=\"https://www.matrix.org/\">link</a> in it</blockquote>
""",
"""
<code>Hello world</code>
<p>Text</p>
<code><b>Hello</b> <i>world</i></code>
<p>Text</p>
<code>Hello world</code>
"""]
"""
Text before blockquote
<blockquote>
<b>bold</b> <i>italic</i>
</blockquote>
Text after blockquote
""",
"""
<blockquote>First blockquote with a <a href=\"https://www.matrix.org/\">link</a> in it</blockquote>
<blockquote>Second blockquote with a <a href=\"https://www.matrix.org/\">link</a> in it</blockquote>
<blockquote>Third blockquote with a <a href=\"https://www.matrix.org/\">link</a> in it</blockquote>
""",
"""
<code>Hello world</code>
<p>Text</p>
<code><b>Hello</b> <i>world</i></code>
<p>Text</p>
<code>Hello world</code>
"""
]
let attributedStringBuilder = AttributedStringBuilder()
VStack(alignment: .leading, spacing: 24.0) {
@@ -49,11 +49,11 @@ struct NoticeRoomTimelineView_Previews: PreviewProvider {
}
private static func itemWith(text: String, timestamp: String, senderId: String) -> NoticeRoomTimelineItem {
return NoticeRoomTimelineItem(id: UUID().uuidString,
text: text,
timestamp: timestamp,
shouldShowSenderDetails: true,
isOutgoing: false,
senderId: senderId)
NoticeRoomTimelineItem(id: UUID().uuidString,
text: text,
timestamp: timestamp,
shouldShowSenderDetails: true,
isOutgoing: false,
senderId: senderId)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -52,24 +52,24 @@ struct TextRoomTimelineView_Previews: PreviewProvider {
shouldShowSenderDetails: true,
isOutgoing: false,
senderId: "Bob"))
.timelineStyle(.plain)
.timelineStyle(.plain)
TextRoomTimelineView(timelineItem: itemWith(text: "Some other text",
timestamp: "Later",
shouldShowSenderDetails: true,
isOutgoing: true,
senderId: "Anne"))
.timelineStyle(.plain)
.timelineStyle(.plain)
}
.padding(.horizontal, 8)
}
private static func itemWith(text: String, timestamp: String, shouldShowSenderDetails: Bool, isOutgoing: Bool, senderId: String) -> TextRoomTimelineItem {
return TextRoomTimelineItem(id: UUID().uuidString,
text: text,
timestamp: timestamp,
shouldShowSenderDetails: shouldShowSenderDetails,
isOutgoing: isOutgoing,
senderId: senderId)
TextRoomTimelineItem(id: UUID().uuidString,
text: text,
timestamp: timestamp,
shouldShowSenderDetails: shouldShowSenderDetails,
isOutgoing: isOutgoing,
senderId: senderId)
}
}
@@ -6,13 +6,13 @@
// Copyright © 2022 Element. All rights reserved.
//
import SwiftUI
import Combine
import Introspect
import SwiftUI
struct TimelineItemList: View {
@State private var tableViewObserver: ListTableViewAdapter = ListTableViewAdapter()
@State private var tableViewObserver = ListTableViewAdapter()
@State private var timelineItems: [RoomTimelineViewProvider] = []
@State private var hasPendingChanges = false
@ObservedObject private var settings = ElementSettings.shared
@@ -65,7 +65,7 @@ struct TimelineItemList: View {
}
tableViewObserver = ListTableViewAdapter(tableView: tableView,
topDetectionOffset: (tableView.bounds.size.height / 3.0),
topDetectionOffset: tableView.bounds.size.height / 3.0,
bottomDetectionOffset: 10.0)
tableViewObserver.scrollToBottom()
@@ -136,11 +136,11 @@ struct TimelineItemList: View {
}
private var isPreview: Bool {
#if DEBUG
#if DEBUG
return ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
#else
#else
return false
#endif
#endif
}
}
@@ -6,9 +6,9 @@
// Copyright © 2022 Element. All rights reserved.
//
import Combine
import Foundation
import SwiftUI
import Combine
import Introspect
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -61,20 +61,20 @@ class SessionVerificationStateMachine {
// swiftlint:disable cyclomatic_complexity
init() {
stateMachine = StateMachine(state: .initial) { machine in
machine.addRoutes(event: .requestVerification, transitions: [ .initial => .requestingVerification ])
machine.addRoutes(event: .didFail, transitions: [ .requestingVerification => .initial ])
machine.addRoutes(event: .requestVerification, transitions: [.initial => .requestingVerification])
machine.addRoutes(event: .didFail, transitions: [.requestingVerification => .initial])
machine.addRoutes(event: .cancel, transitions: [ .requestingVerification => .cancelling ])
machine.addRoutes(event: .didCancel, transitions: [ .requestingVerification => .cancelled ])
machine.addRoutes(event: .cancel, transitions: [.requestingVerification => .cancelling])
machine.addRoutes(event: .didCancel, transitions: [.requestingVerification => .cancelled])
// Cancellation request from the other party should either take us from `.cancelling`
// to `.cancelled` or keep us in `.cancelled` if already there. There is more `.didCancel`
// handling in `addRouteMapping` for states containing associated values
machine.addRoutes(event: .didCancel, transitions: [ .cancelling => .cancelled ])
machine.addRoutes(event: .didCancel, transitions: [ .cancelled => .cancelled ])
machine.addRoutes(event: .didFail, transitions: [ .cancelled => .cancelled ])
machine.addRoutes(event: .didCancel, transitions: [.cancelling => .cancelled])
machine.addRoutes(event: .didCancel, transitions: [.cancelled => .cancelled])
machine.addRoutes(event: .didFail, transitions: [.cancelled => .cancelled])
machine.addRoutes(event: .restart, transitions: [ .cancelled => .initial ])
machine.addRoutes(event: .restart, transitions: [.cancelled => .initial])
// Transitions with associated values need to be handled through `addRouteMapping`
machine.addRouteMapping { event, fromState, _ in
@@ -115,6 +115,7 @@ class SessionVerificationStateMachine {
}
}
}
// swiftlint:enable cyclomatic_complexity
/// Attempt to move the state machine to another state through an event
@@ -75,8 +75,8 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer
callback?(.finished)
case .cancel:
guard stateMachine.state == .initial ||
stateMachine.state == .verified ||
stateMachine.state == .cancelled else {
stateMachine.state == .verified ||
stateMachine.state == .cancelled else {
stateMachine.processEvent(.cancel)
return
}
@@ -119,7 +119,7 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer
private func requestVerification() {
Task {
switch await sessionVerificationControllerProxy.requestVerification() {
case.success:
case .success:
// Need to wait for the callback from the remote
break
case .failure:
@@ -131,7 +131,7 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer
private func cancelVerification() {
Task {
switch await sessionVerificationControllerProxy.cancelVerification() {
case.success:
case .success:
stateMachine.processEvent(.didCancel)
case .failure:
stateMachine.processEvent(.didFail)
@@ -142,7 +142,7 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer
private func acceptChallenge() {
Task {
switch await sessionVerificationControllerProxy.approveVerification() {
case.success:
case .success:
// Need to wait for the callback from the remote
break
case .failure:
@@ -154,7 +154,7 @@ class SessionVerificationViewModel: SessionVerificationViewModelType, SessionVer
private func declineChallenge() {
Task {
switch await sessionVerificationControllerProxy.declineVerification() {
case.success:
case .success:
stateMachine.processEvent(.didCancel)
case .failure:
stateMachine.processEvent(.didFail)
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -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 SwiftUI
import MatrixRustSDK
import SwiftUI
struct SessionVerificationScreen: View {
@@ -109,7 +109,7 @@ final class SettingsCoordinator: Coordinator, Presentable {
add(childCoordinator: coordinator)
coordinator.start()
self.parameters.navigationRouter.push(coordinator, animated: true) { [weak self] in
parameters.navigationRouter.push(coordinator, animated: true) { [weak self] in
guard let self = self else { return }
self.remove(childCoordinator: coordinator)
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,9 +32,7 @@ struct SettingsViewState: BindableState {
var bindings: SettingsViewStateBindings
}
struct SettingsViewStateBindings {
}
struct SettingsViewStateBindings { }
enum SettingsViewAction {
case reportBug
@@ -18,7 +18,7 @@ import SwiftUI
@available(iOS 14, *)
typealias SettingsViewModelType = StateStoreViewModel<SettingsViewState,
SettingsViewAction>
SettingsViewAction>
@available(iOS 14, *)
class SettingsViewModel: SettingsViewModelType, SettingsViewModelProtocol {
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,7 +44,7 @@ struct SettingsScreen: View {
role: .destructive) { context.send(viewAction: .crash)
}
.accessibilityIdentifier("crashButton")
.accessibilityIdentifier("crashButton")
}
}
.listRowBackground(rowBackgroundColor)
@@ -8,6 +8,4 @@
import UIKit
class SplashViewController: UIViewController {
}
class SplashViewController: UIViewController { }
@@ -46,6 +46,7 @@ final class SplashScreenCoordinator: Coordinator, Presentable {
}
// MARK: - Public
func start() {
MXLog.debug("[SplashScreenCoordinator] did start.")
splashScreenViewModel.callback = { [weak self] action in
@@ -59,7 +60,7 @@ final class SplashScreenCoordinator: Coordinator, Presentable {
}
func toPresentable() -> UIViewController {
return splashScreenHostingController
splashScreenHostingController
}
/// Stops any ongoing activities in the coordinator.
@@ -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 SwiftUI
import Combine
import SwiftUI
typealias SplashScreenViewModelType = StateStoreViewModel<SplashScreenViewState, SplashScreenViewAction>
@@ -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 SwiftUI
import DesignKit
import SwiftUI
/// The splash screen shown at the beginning of the onboarding flow.
struct SplashScreen: View {
@@ -152,7 +152,7 @@ struct SplashScreen: View {
private func showPreviousPage() {
// Prevent the hidden page at index -1 from being shown.
context.pageIndex = max(0, (context.pageIndex - 1))
context.pageIndex = max(0, context.pageIndex - 1)
}
private func showHiddenPage() {
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
//
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -33,8 +33,8 @@ struct SplashScreenPageView: View {
.resizable()
.scaledToFit()
.frame(maxWidth: 310) // This value is problematic. 300 results in dropped frames
// on iPhone 12/13 Mini. 305 the same on iPhone 12/13. As of
// iOS 15, 310 seems fine on all supported screen widths 🤞.
// on iPhone 12/13 Mini. 305 the same on iPhone 12/13. As of
// iOS 15, 310 seems fine on all supported screen widths 🤞.
.padding(20)
.accessibilityHidden(true)