Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
Velin92 committed Nov 20, 2023
1 parent 5a0a0f9 commit 40fe1ec
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Config/Project.xcconfig
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ KEYCHAIN_ACCESS_GROUP = $(AppIdentifierPrefix)$(BASE_BUNDLE_IDENTIFIER).keychain
BROADCAST_UPLOAD_EXTENSION_BUNDLE_IDENTIFIER = $(BASE_BUNDLE_IDENTIFIER).broadcastUploadExtension

// Build settings
IPHONEOS_DEPLOYMENT_TARGET = 14.0
IPHONEOS_DEPLOYMENT_TARGET = 15.0
SDKROOT = iphoneos
TARGETED_DEVICE_FAMILY = 1,2
SWIFT_VERSION = 5.6
Expand Down
4 changes: 2 additions & 2 deletions Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-wysiwyg-composer-swift",
"state" : {
"revision" : "1100b217c04d096dfe072afb4484660ff794d805",
"version" : "2.2.2"
"revision" : "dfb74c89bf54b41ea000d564d6435ac6444ba6b4",
"version" : "2.18.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ class HTMLFormatter: NSObject {

var options: [AnyHashable: Any] = [
DTUseiOS6Attributes: true,
DTDefaultFontDescriptor: font.fontDescriptor,
DTDefaultFontFamily: font.familyName,
DTDefaultFontName: font.fontName,
DTDefaultFontSize: font.pointSize,
DTDefaultLinkDecoration: false,
DTDefaultLinkColor: ThemeService.shared().theme.colors.links,
DTWillFlushBlockCallBack: sanitizeCallback
Expand Down
4 changes: 2 additions & 2 deletions Riot/Modules/Room/RoomViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,8 @@ extension RoomViewController: ComposerLinkActionBridgePresenterDelegate {
}

// MARK: - PermalinkReplacer
extension RoomViewController: PermalinkReplacer {
public func replacementForLink(_ url: String, text: String) -> NSAttributedString? {
extension RoomViewController: MentionReplacer {
public func replacementForMention(_ url: String, text: String) -> NSAttributedString? {
guard #available(iOS 15.0, *),
let url = URL(string: url),
let session = roomDataSource.mxSession,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
return (delegate as? RoomInputToolbarViewDelegate) ?? nil
}

private var permalinkReplacer: PermalinkReplacer? {
return (delegate as? PermalinkReplacer)
private var mentionReplacer: MentionReplacer? {
return (delegate as? MentionReplacer)
}

override func awakeFromNib() {
Expand Down Expand Up @@ -227,7 +227,7 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
private func setupComposerIfNeeded() {
guard hostingViewController == nil,
let toolbarViewDelegate,
let permalinkReplacer else { return }
let mentionReplacer else { return }

viewModel = ComposerViewModel(
initialViewState: ComposerViewState(textFormattingEnabled: RiotSettings.shared.enableWysiwygTextFormatting,
Expand All @@ -238,7 +238,7 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
self?.handleViewModelResult(result)
}
wysiwygViewModel.plainTextMode = !RiotSettings.shared.enableWysiwygTextFormatting
wysiwygViewModel.permalinkReplacer = permalinkReplacer
wysiwygViewModel.mentionReplacer = mentionReplacer

inputAccessoryViewForKeyboard = UIView(frame: .zero)

Expand Down Expand Up @@ -422,6 +422,10 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
toolbarViewDelegate?.didSendLinkAction(LinkActionWrapper(linkAction))
case let .suggestion(pattern):
toolbarViewDelegate?.didDetectTextPattern(SuggestionPatternWrapper(pattern))
case .sendMessage:
let content = wysiwygViewModel.content
sendWysiwygMessage(content: content)
wysiwygViewModel.clearContent()
}
}

Expand Down
4 changes: 3 additions & 1 deletion RiotSwiftUI/Modules/Room/Composer/Model/ComposerModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ extension FormatItem {

extension FormatType {
/// Convenience method to map it to the external ViewModel action
var action: WysiwygAction {
var action: ComposerAction {
switch self {
case .bold:
return .bold
Expand Down Expand Up @@ -230,13 +230,15 @@ enum ComposerViewAction: Equatable {
case linkTapped(linkAction: LinkAction)
case storeSelection(selection: NSRange)
case suggestion(pattern: SuggestionPattern?)
case sendMessage
}

enum ComposerViewModelResult: Equatable {
case cancel
case contentDidChange(isEmpty: Bool)
case linkTapped(LinkAction: LinkAction)
case suggestion(pattern: SuggestionPattern?)
case sendMessage
}

final class LinkActionWrapper: NSObject {
Expand Down
23 changes: 19 additions & 4 deletions RiotSwiftUI/Modules/Room/Composer/View/Composer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,20 @@ struct Composer: View {
}
HStack(alignment: shouldFixRoundCorner ? .top : .center, spacing: 0) {
WysiwygComposerView(
focused: $viewModel.focused,
viewModel: wysiwygViewModel
placeholder: viewModel.viewState.placeholder ?? "",
placeholderColor: theme.colors.tertiaryContent,
viewModel: wysiwygViewModel, itemProviderHelper: EmptyWysiwygProviderHelper(),
keyCommandHandler: { keyCommand in
switch keyCommand {
case .enter:
viewModel.send(viewAction: .sendMessage)
return true
case .shiftEnter:
return false
}
},
pasteHandler: { _ in }
)
.tintColor(theme.colors.accent)
.placeholder(viewModel.viewState.placeholder, color: theme.colors.tertiaryContent)
.onAppear {
if wysiwygViewModel.isContentEmpty {
wysiwygViewModel.setup()
Expand Down Expand Up @@ -318,3 +327,9 @@ struct Composer_Previews: PreviewProvider {
stateRenderer.screenGroup()
}
}

private struct EmptyWysiwygProviderHelper: WysiwygItemProviderHelper {
func isPasteSupported(for itemProvider: NSItemProvider) -> Bool {
false
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ final class ComposerViewModel: ComposerViewModelType, ComposerViewModelProtocol
selectionToRestore = selection
case let .suggestion(pattern: pattern):
callback?(.suggestion(pattern: pattern))
case .sendMessage:
callback?(.sendMessage)
}
}

Expand Down
4 changes: 2 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ packages:
branch: 0.0.1
WysiwygComposer:
url: https://github.com/matrix-org/matrix-wysiwyg-composer-swift
version: 2.2.2
version: 2.18.0
DeviceKit:
url: https://github.com/devicekit/DeviceKit
majorVersion: 4.7.0
DTCoreText:
url: https://github.com/Cocoanetics/DTCoreText
version: 1.6.27
version: 1.6.26

0 comments on commit 40fe1ec

Please sign in to comment.