This commit is contained in:
David Langley
2022-10-12 15:08:50 +01:00
parent 821a54e726
commit 4cbef854c9
12 changed files with 64 additions and 67 deletions
@@ -27,12 +27,12 @@ import Foundation
/// (mainly for integration in legacy view controllers). Each bridge should be removed once the underlying Coordinator has been integrated by another Coordinator.
@objcMembers
final class ComposerCreateActionListBridgePresenter: NSObject {
// MARK: - Constants
// MARK: - Properties
// MARK: Private
private let actions: [ComposerCreateAction]
private var coordinator: ComposerCreateActionListCoordinator?
@@ -43,7 +43,9 @@ final class ComposerCreateActionListBridgePresenter: NSObject {
// MARK: - Setup
init(actions: [Int]) {
self.actions = actions.compactMap({ ComposerCreateAction(rawValue: $0) })
self.actions = actions.compactMap {
ComposerCreateAction(rawValue: $0)
}
super.init()
}
@@ -55,7 +57,6 @@ final class ComposerCreateActionListBridgePresenter: NSObject {
// }
func present(from viewController: UIViewController, animated: Bool) {
let composerCreateActionListCoordinator = ComposerCreateActionListCoordinator(actions: actions)
composerCreateActionListCoordinator.callback = { [weak self] action in
guard let self = self else { return }
@@ -70,11 +71,11 @@ final class ComposerCreateActionListBridgePresenter: NSObject {
viewController.present(presentable, animated: animated, completion: nil)
composerCreateActionListCoordinator.start()
self.coordinator = composerCreateActionListCoordinator
coordinator = composerCreateActionListCoordinator
}
func dismiss(animated: Bool, completion: (() -> Void)?) {
guard let coordinator = self.coordinator else {
guard let coordinator = coordinator else {
return
}
// Dismiss modal
@@ -23,10 +23,10 @@ enum ComposerCreateActionListCoordinatorAction {
}
final class ComposerCreateActionListCoordinator: NSObject, Coordinator, Presentable, UISheetPresentationControllerDelegate {
// MARK: - Properties
// MARK: Private
private let hostingController: UIViewController
private var view: ComposerCreateActionList
private var viewModel: ComposerCreateActionListViewModel
@@ -41,7 +41,7 @@ final class ComposerCreateActionListCoordinator: NSObject, Coordinator, Presenta
init(actions: [ComposerCreateAction]) {
viewModel = ComposerCreateActionListViewModel(initialViewState: ComposerCreateActionListViewState(actions: actions))
self.view = ComposerCreateActionList(viewModel: viewModel.context)
view = ComposerCreateActionList(viewModel: viewModel.context)
let hostingVC = VectorHostingController(rootView: view)
hostingVC.bottomSheetPreferences = VectorHostingBottomSheetPreferences(detents: [.medium])
hostingController = hostingVC
@@ -62,10 +62,10 @@ final class ComposerCreateActionListCoordinator: NSObject, Coordinator, Presenta
}
func toPresentable() -> UIViewController {
return self.hostingController
hostingController
}
func presentationControllerDidDismiss(_ presentationController: UIPresentationController) {
self.callback?(.cancel)
}
callback?(.cancel)
}
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -31,7 +31,6 @@ enum ComposerCreateActionListViewModelResult: Equatable {
// MARK: View
struct ComposerCreateActionListViewState: BindableState {
/// The list of composer create actions to display to the user
let actions: [ComposerCreateAction]
}
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,7 +17,6 @@
import SwiftUI
struct ComposerCreateActionList: View {
// MARK: - Properties
// MARK: Private
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -19,7 +19,6 @@ import SwiftUI
typealias ComposerCreateActionListViewModelType = StateStoreViewModel<ComposerCreateActionListViewState, ComposerCreateActionListViewAction>
class ComposerCreateActionListViewModel: ComposerCreateActionListViewModelType, ComposerCreateActionListViewModelProtocol {
// MARK: - Properties
// MARK: Private
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -22,7 +22,6 @@ import WysiwygComposer
/// An item in the toolbar
struct FormatItem {
/// The type of the item
let type: FormatType
/// Whether it is active(highlighted)
@@ -48,7 +47,6 @@ extension FormatItem: Identifiable {
}
extension FormatItem {
/// The icon for the item
var icon: String {
switch type {
@@ -19,11 +19,11 @@ import SwiftUI
import WysiwygComposer
struct Composer: View {
// MARK: - Properties
// MARK: Private
@State var focused = false
private let borderHeight: CGFloat = 44
private let minTextViewHeight: CGFloat = 20
private var verticalPadding: CGFloat {
@@ -85,6 +85,11 @@ struct Composer: View {
.padding(.horizontal, 12)
.padding(.top, 8)
.padding(.bottom, 4)
.onTapGesture {
if !focused {
focused = true
}
}
HStack {
Button {
showSendMediaActions()
@@ -131,6 +136,7 @@ struct Composer: View {
}
// MARK: Previews
struct Composer_Previews: PreviewProvider {
static let stateRenderer = MockComposerScreenState.stateRenderer
static var previews: some View {
@@ -1,4 +1,4 @@
//
//
// Copyright 2022 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -18,8 +18,6 @@ import SwiftUI
import WysiwygComposer
struct FormattingToolbar: View {
// MARK: - Properties
// MARK: Private
@@ -31,25 +29,24 @@ struct FormattingToolbar: View {
/// The list of items to render in the toolbar
var formatItems: [FormatItem]
/// The action when an item is selected
var formatAction: (FormatType) -> ()
var formatAction: (FormatType) -> Void
var body: some View {
HStack {
ForEach(formatItems) { item in
Button {
formatAction(item.type)
} label: {
Image(item.icon)
.renderingMode(.template)
.foregroundColor(item.active ? theme.colors.accent : theme.colors.tertiaryContent)
}
.disabled(item.disabled)
.background(item.active ? theme.colors.accent.opacity(0.1) : theme.colors.background)
.cornerRadius(8)
.accessibilityIdentifier(item.accessibilityIdentifier)
}
}
ForEach(formatItems) { item in
Button {
formatAction(item.type)
} label: {
Image(item.icon)
.renderingMode(.template)
.foregroundColor(item.active ? theme.colors.accent : theme.colors.tertiaryContent)
}
.disabled(item.disabled)
.background(item.active ? theme.colors.accent.opacity(0.1) : theme.colors.background)
.cornerRadius(8)
.accessibilityIdentifier(item.accessibilityIdentifier)
}
}
}
}