mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
creating the coordinator for the link action view
This commit is contained in:
parent
c0b1f1d260
commit
bb1155b9f1
9 changed files with 116 additions and 3 deletions
|
@ -34,6 +34,7 @@
|
|||
@class ThreadsCoordinatorBridgePresenter;
|
||||
@class LiveLocationSharingBannerView;
|
||||
@class VoiceBroadcastService;
|
||||
@class ComposerLinkActionBridgePresenter;
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
|
@ -122,6 +123,8 @@ extern NSTimeInterval const kResizeComposerAnimationDuration;
|
|||
|
||||
@property (nonatomic) CGFloat wysiwygTranslation;
|
||||
|
||||
@property (nonatomic, strong) ComposerLinkActionBridgePresenter *composerLinkActionBridgePresenter;
|
||||
|
||||
|
||||
/**
|
||||
Retrieve the live data source in cases where the timeline is not live.
|
||||
|
|
|
@ -243,6 +243,11 @@ extension RoomViewController {
|
|||
roomInputToolbarContainer.superview?.isHidden = isHidden
|
||||
}
|
||||
}
|
||||
|
||||
@objc func didSendLinkAction(_ linkAction: LinkActionWrapper) {
|
||||
composerLinkActionBridgePresenter = ComposerLinkActionBridgePresenter(linkAction: linkAction)
|
||||
composerLinkActionBridgePresenter.delegate = self
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private Helpers
|
||||
|
@ -281,3 +286,7 @@ private extension RoomViewController {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension RoomViewController: ComposerLinkActionBridgePresenterDelegate {
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
@class RoomActionsBar;
|
||||
@class RoomInputToolbarView;
|
||||
@class LinkActionWrapper;
|
||||
|
||||
/**
|
||||
Destination of the message in the composer
|
||||
|
@ -77,6 +78,8 @@ typedef NS_ENUM(NSUInteger, RoomInputToolbarViewSendMode)
|
|||
|
||||
- (void)didChangeMaximisedState: (BOOL) isMaximised;
|
||||
|
||||
- (void)didSendLinkAction: (LinkActionWrapper *)linkAction;
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
|
|
|
@ -258,9 +258,11 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
|
|||
private func handleViewModelResult(_ result: ComposerViewModelResult) {
|
||||
switch result {
|
||||
case .cancel:
|
||||
self.toolbarViewDelegate?.roomInputToolbarViewDidTapCancel(self)
|
||||
toolbarViewDelegate?.roomInputToolbarViewDidTapCancel(self)
|
||||
case let .contentDidChange(isEmpty):
|
||||
setVoiceMessageToolbarIsHidden(!isEmpty)
|
||||
case let .linkTapped(linkAction):
|
||||
toolbarViewDelegate?.didSendLinkAction(LinkActionWrapper(linkAction))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
protocol ComposerLinkActionBridgePresenterDelegate: AnyObject {
|
||||
|
||||
}
|
||||
|
||||
|
||||
final class ComposerLinkActionBridgePresenter: NSObject {
|
||||
private var coordinator: ComposerLinkActionCoordinator?
|
||||
private var linkAction: LinkActionWrapper
|
||||
|
||||
weak var delegate: ComposerLinkActionBridgePresenterDelegate?
|
||||
|
||||
init(linkAction: LinkActionWrapper) {
|
||||
self.linkAction = linkAction
|
||||
super.init()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// Copyright 2022 New Vector Ltd
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
final class ComposerLinkActionCoordinator: Coordinator, Presentable {
|
||||
var childCoordinators: [Coordinator] = []
|
||||
|
||||
func start() {
|
||||
|
||||
}
|
||||
|
||||
func toPresentable() -> UIViewController {
|
||||
fatalError()
|
||||
}
|
||||
}
|
|
@ -36,6 +36,7 @@ enum FormatType {
|
|||
case italic
|
||||
case underline
|
||||
case strikethrough
|
||||
case link
|
||||
}
|
||||
|
||||
extension FormatType: CaseIterable, Identifiable {
|
||||
|
@ -58,6 +59,8 @@ extension FormatItem {
|
|||
return Asset.Images.strikethrough.name
|
||||
case .underline:
|
||||
return Asset.Images.underlined.name
|
||||
case .link:
|
||||
return Asset.Images.link.name
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,6 +74,8 @@ extension FormatItem {
|
|||
return "strikethroughButton"
|
||||
case .underline:
|
||||
return "underlineButton"
|
||||
case .link:
|
||||
return "linkButton"
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -84,6 +89,9 @@ extension FormatItem {
|
|||
return VectorL10n.wysiwygComposerFormatActionStrikethrough
|
||||
case .underline:
|
||||
return VectorL10n.wysiwygComposerFormatActionUnderline
|
||||
case .link:
|
||||
// TODO: Add link accessibility label translation
|
||||
return "link"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -100,11 +108,12 @@ extension FormatType {
|
|||
return .strikeThrough
|
||||
case .underline:
|
||||
return .underline
|
||||
case .link:
|
||||
return .link
|
||||
}
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
@ -116,6 +125,8 @@ extension FormatType {
|
|||
return .strikeThrough
|
||||
case .underline:
|
||||
return .underline
|
||||
case .link:
|
||||
return .link
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,11 +141,22 @@ enum ComposerSendMode: Equatable {
|
|||
enum ComposerViewAction: Equatable {
|
||||
case cancel
|
||||
case contentDidChange(isEmpty: Bool)
|
||||
case linkTapped(linkAction: LinkAction)
|
||||
}
|
||||
|
||||
enum ComposerViewModelResult: Equatable {
|
||||
case cancel
|
||||
case contentDidChange(isEmpty: Bool)
|
||||
case linkTapped(LinkAction: LinkAction)
|
||||
}
|
||||
|
||||
final class LinkActionWrapper: NSObject {
|
||||
let linkAction: LinkAction
|
||||
|
||||
init(_ linkAction: LinkAction) {
|
||||
self.linkAction = linkAction
|
||||
super.init()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -226,7 +226,11 @@ struct Composer: View {
|
|||
HStack(alignment: .center, spacing: 0) {
|
||||
sendMediaButton
|
||||
FormattingToolbar(formatItems: formatItems) { type in
|
||||
wysiwygViewModel.apply(type.action)
|
||||
if type.action == .link {
|
||||
sendLinkAction()
|
||||
} else {
|
||||
wysiwygViewModel.apply(type.action)
|
||||
}
|
||||
}
|
||||
.frame(height: 44)
|
||||
Spacer()
|
||||
|
@ -242,6 +246,11 @@ struct Composer: View {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func sendLinkAction() {
|
||||
let linkAction = wysiwygViewModel.getLinkAction()
|
||||
viewModel.send(viewAction: .linkTapped(linkAction: linkAction))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Previews
|
||||
|
|
|
@ -84,6 +84,8 @@ final class ComposerViewModel: ComposerViewModelType, ComposerViewModelProtocol
|
|||
callback?(.cancel)
|
||||
case let .contentDidChange(isEmpty):
|
||||
callback?(.contentDidChange(isEmpty: isEmpty))
|
||||
case let .linkTapped(linkAction):
|
||||
callback?(.linkTapped(LinkAction: linkAction))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue