mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-05-03 06:36:58 +02:00
Merge branch 'langleyd/6830_wysiwyg_core_formatting' into mauroromito/wysiwyg_edit_reply_UI
# Conflicts: # RiotSwiftUI/Modules/Room/Composer/View/Composer.swift
This commit is contained in:
+6
-5
@@ -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
|
||||
|
||||
+5
-5
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
+7
-3
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -18,15 +18,19 @@ import Foundation
|
||||
|
||||
// MARK: View model
|
||||
|
||||
enum ComposerCreateActionListViewModelResult: Equatable {
|
||||
enum ComposerCreateActionListViewAction {
|
||||
// The user selected an action
|
||||
case selectAction(ComposerCreateAction)
|
||||
}
|
||||
|
||||
enum ComposerCreateActionListViewModelResult: Equatable {
|
||||
// The user selected an action and is done with the screen
|
||||
case done(ComposerCreateAction)
|
||||
}
|
||||
|
||||
// MARK: View
|
||||
|
||||
struct ComposerCreateActionListViewState: BindableState {
|
||||
|
||||
/// The list of composer create actions to display to the user
|
||||
let actions: [ComposerCreateAction]
|
||||
}
|
||||
|
||||
+1
-2
@@ -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
-1
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
|
||||
-1
@@ -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");
|
||||
@@ -18,12 +18,19 @@ import Foundation
|
||||
import SwiftUI
|
||||
import WysiwygComposer
|
||||
|
||||
// MARK: View
|
||||
|
||||
/// An item in the toolbar
|
||||
struct FormatItem {
|
||||
/// The type of the item
|
||||
let type: FormatType
|
||||
/// Whether it is active(highlighted)
|
||||
let active: Bool
|
||||
/// Whether it is disabled or enabled
|
||||
let disabled: Bool
|
||||
}
|
||||
|
||||
/// The types of formatting actions
|
||||
enum FormatType {
|
||||
case bold
|
||||
case italic
|
||||
@@ -35,12 +42,12 @@ extension FormatType: CaseIterable, Identifiable {
|
||||
var id: Self { self }
|
||||
}
|
||||
|
||||
|
||||
extension FormatItem: Identifiable {
|
||||
var id: FormatType { type }
|
||||
}
|
||||
|
||||
extension FormatItem {
|
||||
/// The icon for the item
|
||||
var icon: String {
|
||||
switch type {
|
||||
case .bold:
|
||||
@@ -69,6 +76,7 @@ extension FormatItem {
|
||||
}
|
||||
|
||||
extension FormatType {
|
||||
/// Convenience method to map it to the external ViewModel action
|
||||
var action: WysiwygAction {
|
||||
switch self {
|
||||
case .bold:
|
||||
@@ -82,6 +90,9 @@ extension FormatType {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: We probably don't need to expose this, clean up.
|
||||
|
||||
/// Convenience method to map it to the external rust binging action
|
||||
var composerAction: ComposerAction {
|
||||
switch self {
|
||||
case .bold:
|
||||
|
||||
@@ -19,6 +19,11 @@ import SwiftUI
|
||||
import WysiwygComposer
|
||||
|
||||
struct Composer: View {
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
@State var focused = false
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
|
||||
@@ -53,6 +58,17 @@ struct Composer: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
@ObservedObject var viewModel: WysiwygComposerViewModel
|
||||
let sendMessageAction: (WysiwygComposerContent) -> Void
|
||||
let showSendMediaActions: () -> Void
|
||||
var textColor = Color(.label)
|
||||
|
||||
@State private var showSendButton = false
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
let rect = RoundedRectangle(cornerRadius: cornerRadius)
|
||||
@@ -112,6 +128,11 @@ struct Composer: View {
|
||||
.padding(.horizontal, horizontalPadding)
|
||||
.padding(.top, 8)
|
||||
.padding(.bottom, 4)
|
||||
.onTapGesture {
|
||||
if !focused {
|
||||
focused = true
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Button {
|
||||
showSendMediaActions()
|
||||
@@ -162,13 +183,11 @@ struct Composer: View {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Previews
|
||||
|
||||
struct Composer_Previews: PreviewProvider {
|
||||
static let stateRenderer = MockComposerScreenState.stateRenderer
|
||||
static var previews: some View {
|
||||
stateRenderer.screenGroup()
|
||||
}
|
||||
}
|
||||
|
||||
enum ComposerCreateActionListViewAction {
|
||||
case selectAction(ComposerCreateAction)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//
|
||||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@@ -18,33 +18,40 @@ import SwiftUI
|
||||
import WysiwygComposer
|
||||
|
||||
struct FormattingToolbar: View {
|
||||
// MARK: - Properties
|
||||
|
||||
// MARK: Private
|
||||
|
||||
// MARK: Public
|
||||
|
||||
@Environment(\.theme) private var theme: ThemeSwiftUI
|
||||
|
||||
/// The list of items to render in the toolbar
|
||||
var formatItems: [FormatItem]
|
||||
var formatAction: (FormatType) -> ()
|
||||
/// The action when an item is selected
|
||||
var formatAction: (FormatType) -> Void
|
||||
|
||||
var body: some View {
|
||||
HStack {
|
||||
ForEach(formatItems) { item in
|
||||
Button {
|
||||
print("action")
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Previews
|
||||
|
||||
struct FormattingToolbar_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
FormattingToolbar(formatItems: [
|
||||
|
||||
Reference in New Issue
Block a user