Skip to content

Commit

Permalink
Move RTE feature flag to settings (#1703)
Browse files Browse the repository at this point in the history
* Update matrix-wysiwyg-composer-swift to 2.10.1

* Delete MessageComposerTextField

* Always use rte composer

* Fix corner radius

* Cleanup
  • Loading branch information
alfogrillo authored Sep 14, 2023
1 parent 24524a6 commit 058fe79
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 321 deletions.
6 changes: 1 addition & 5 deletions ElementX.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
1FEC0A4EC6E6DF693C16B32A /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CEBCB9676FCD1D0F13188DD /* StringTests.swift */; };
206F0DBAB6AF042CA1FF2C0D /* SettingsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D487C1185D658F8B15B8F55 /* SettingsViewModelTests.swift */; };
208C19811613F9A10F8A7B75 /* MediaLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AFCE895ECFFA53FEE64D62B /* MediaLoader.swift */; };
20BB987875F99190A3E28632 /* MessageComposerTextField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1756F24C1913F809A0039FD0 /* MessageComposerTextField.swift */; };
2185C1F6724C78FFF355D6FA /* WelcomeScreenScreenUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8AB10FA6570DD08B3966C159 /* WelcomeScreenScreenUITests.swift */; };
21BF2B7CEDFE3CA67C5355AD /* test_image.png in Resources */ = {isa = PBXBuildFile; fileRef = C733D11B421CFE3A657EF230 /* test_image.png */; };
22882C710BC99EC34A5024A0 /* UITestsScreenIdentifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CEBE5EA91E8691EDF364EC2 /* UITestsScreenIdentifier.swift */; };
Expand Down Expand Up @@ -935,7 +934,6 @@
16DC8C5B2991724903F1FA6A /* AppIcon.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = AppIcon.pdf; sourceTree = "<group>"; };
1715E3D7F53C0748AA50C91C /* PostHogAnalyticsClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PostHogAnalyticsClient.swift; sourceTree = "<group>"; };
1734A445A58ED855B977A0A8 /* TracingConfigurationTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TracingConfigurationTests.swift; sourceTree = "<group>"; };
1756F24C1913F809A0039FD0 /* MessageComposerTextField.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageComposerTextField.swift; sourceTree = "<group>"; };
184CF8C196BE143AE226628D /* DecorationTimelineItemProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DecorationTimelineItemProtocol.swift; sourceTree = "<group>"; };
1877038D1AD3D5A029F8AE2C /* TimelineReadReceiptsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimelineReadReceiptsView.swift; sourceTree = "<group>"; };
18F2958E6D247AE2516BEEE8 /* ClientProxy.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ClientProxy.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2305,7 +2303,6 @@
D121B4FCFC38DBCC17BCC6D6 /* ComposerToolbar.swift */,
0AE449DFBA7CC863EEB2FD2A /* FormattingToolbar.swift */,
A0A01AECFF54281CF35909A6 /* MessageComposer.swift */,
1756F24C1913F809A0039FD0 /* MessageComposerTextField.swift */,
3E6A9B9DFEE964962C179DE3 /* RoomAttachmentPicker.swift */,
);
path = View;
Expand Down Expand Up @@ -4686,7 +4683,6 @@
9B872FF37DBE6BE054903831 /* MediaUploadPreviewScreenViewModelProtocol.swift in Sources */,
8A0BD60CA4A6004DB06B5403 /* MediaUploadingPreprocessor.swift in Sources */,
858B0A45257174AAFD448EA0 /* MessageComposer.swift in Sources */,
20BB987875F99190A3E28632 /* MessageComposerTextField.swift in Sources */,
C8E0FA0FF2CD6613264FA6B9 /* MessageForwardingScreen.swift in Sources */,
2BBA132149DEBED6624084A8 /* MessageForwardingScreenCoordinator.swift in Sources */,
695825D20A761C678809345D /* MessageForwardingScreenModels.swift in Sources */,
Expand Down Expand Up @@ -5665,7 +5661,7 @@
repositoryURL = "https://github.com/matrix-org/matrix-wysiwyg-composer-swift";
requirement = {
kind = exactVersion;
version = 2.8.0;
version = 2.10.1;
};
};
96495DD8554E2F39D3954354 /* XCRemoteSwiftPackageReference "posthog-ios" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-wysiwyg-composer-swift",
"state" : {
"revision" : "30d41b07b636f67e06bc50d8982c98ee3b97d4ae",
"version" : "2.8.0"
"revision" : "73a2e76929c02c7ca85ca1132e8974ec330cdc04",
"version" : "2.10.1"
}
},
{
Expand Down
8 changes: 4 additions & 4 deletions ElementX/Sources/Application/AppSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ final class AppSettings {
case logLevel
case otlpTracingEnabled
case viewSourceEnabled
case richTextEditorEnabled

// Feature flags
case shouldCollapseRoomStateEvents
case userSuggestionsEnabled
case readReceiptsEnabled
case hasShownWelcomeScreen
case swiftUITimelineEnabled
case richTextEditorEnabled
}

private static var suiteName: String = InfoPlistReader.main.appGroupIdentifier
Expand Down Expand Up @@ -191,6 +191,9 @@ final class AppSettings {

@UserPreference(key: UserDefaultsKeys.viewSourceEnabled, defaultValue: false, storageType: .userDefaults(store))
var viewSourceEnabled

@UserPreference(key: UserDefaultsKeys.richTextEditorEnabled, defaultValue: true, storageType: .userDefaults(store))
var richTextEditorEnabled

// MARK: - Notifications

Expand Down Expand Up @@ -241,7 +244,4 @@ final class AppSettings {

@UserPreference(key: UserDefaultsKeys.swiftUITimelineEnabled, defaultValue: false, storageType: .volatile)
var swiftUITimelineEnabled

@UserPreference(key: UserDefaultsKeys.richTextEditorEnabled, defaultValue: false, storageType: .userDefaults(store))
var richTextEditorEnabled
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import UIKit
import WysiwygComposer

enum ComposerToolbarViewModelAction {
case sendMessage(plain: String, html: String, mode: RoomScreenComposerMode)
case sendPlainTextMessage(message: String, mode: RoomScreenComposerMode)

case sendMessage(plain: String, html: String?, mode: RoomScreenComposerMode)
case displayCameraPicker
case displayMediaPicker
case displayDocumentPicker
Expand Down Expand Up @@ -56,16 +54,11 @@ struct ComposerToolbarViewState: BindableState {
var bindings: ComposerToolbarViewStateBindings

var sendButtonDisabled: Bool {
if ServiceLocator.shared.settings.richTextEditorEnabled {
return composerEmpty
} else {
return bindings.composerPlainText.isEmpty
}
composerEmpty
}
}

struct ComposerToolbarViewStateBindings {
var composerPlainText = ""
var composerFocused = false
var composerActionsEnabled = false
var composerExpanded = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,10 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
wysiwygViewModel.setup()
case .sendMessage:
guard !state.sendButtonDisabled else { return }

if ServiceLocator.shared.settings.richTextEditorEnabled {
actionsSubject.send(.sendMessage(plain: wysiwygViewModel.content.markdown,
html: wysiwygViewModel.content.html,
mode: state.composerMode))
} else {
actionsSubject.send(.sendPlainTextMessage(message: context.composerPlainText,
mode: state.composerMode))
}
let sendHTML = ServiceLocator.shared.settings.richTextEditorEnabled
actionsSubject.send(.sendMessage(plain: wysiwygViewModel.content.markdown,
html: sendHTML ? wysiwygViewModel.content.html : nil,
mode: state.composerMode))
case .cancelReply:
set(mode: .default)
case .cancelEdit:
Expand Down Expand Up @@ -156,11 +151,7 @@ final class ComposerToolbarViewModel: ComposerToolbarViewModelType, ComposerTool
}

private func set(text: String) {
if ServiceLocator.shared.settings.richTextEditorEnabled {
wysiwygViewModel.setMarkdownContent(text)
} else {
state.bindings.composerPlainText = text
}
wysiwygViewModel.setMarkdownContent(text)
}

private func createLinkAlert() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ struct ComposerToolbar: View {
}

private var messageComposer: some View {
MessageComposer(plainText: $context.composerPlainText,
composerView: composerView,
MessageComposer(composerView: composerView,
mode: context.viewState.composerMode,
showResizeGrabber: context.viewState.bindings.composerActionsEnabled,
isExpanded: $context.composerExpanded) {
Expand Down
44 changes: 10 additions & 34 deletions ElementX/Sources/Screens/ComposerToolbar/View/MessageComposer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ typealias EnterKeyHandler = () -> Void
typealias PasteHandler = (NSItemProvider) -> Void

struct MessageComposer: View {
@Binding var plainText: String
let composerView: WysiwygComposerView
let mode: RoomScreenComposerMode
let showResizeGrabber: Bool
Expand All @@ -33,7 +32,6 @@ struct MessageComposer: View {
let onAppearAction: () -> Void
@FocusState private var focused: Bool

@State private var isMultiline = false
@State private var composerTranslation: CGFloat = 0

var body: some View {
Expand All @@ -42,6 +40,7 @@ struct MessageComposer: View {
resizeGrabber
}

let borderRadius: CGFloat = 21
mainContent
.padding(.horizontal, 12.0)
.clipShape(RoundedRectangle(cornerRadius: borderRadius))
Expand All @@ -67,28 +66,15 @@ struct MessageComposer: View {
private var mainContent: some View {
VStack(alignment: .leading, spacing: -6) {
header
HStack(alignment: .bottom) {
if ServiceLocator.shared.settings.richTextEditorEnabled {
composerView
.frame(minHeight: composerHeight, alignment: .top)
.tint(.compound.iconAccentTertiary)
.padding(.vertical, 10)
.focused($focused)
.onAppear {
onAppearAction()
}
} else {
MessageComposerTextField(placeholder: L10n.richTextEditorComposerPlaceholder,
text: $plainText,
isMultiline: $isMultiline,
maxHeight: 300,
enterKeyHandler: sendAction,
pasteHandler: pasteAction)
.tint(.compound.iconAccentTertiary)
.padding(.vertical, 10)
.focused($focused)

composerView
.frame(minHeight: composerHeight, alignment: .top)
.tint(.compound.iconAccentTertiary)
.padding(.vertical, 10)
.focused($focused)
.onAppear {
onAppearAction()
}
}
}
}

Expand All @@ -108,15 +94,6 @@ struct MessageComposer: View {
EmptyView()
}
}

private var borderRadius: CGFloat {
switch mode {
case .default:
return isMultiline ? 20 : 28
case .reply, .edit:
return 20
}
}

private var resizeGrabber: some View {
Capsule()
Expand Down Expand Up @@ -213,8 +190,7 @@ struct MessageComposer_Previews: PreviewProvider {
keyCommandHandler: nil,
pasteHandler: nil)

return MessageComposer(plainText: .constant(content),
composerView: composerView,
return MessageComposer(composerView: composerView,
mode: mode,
showResizeGrabber: false,
isExpanded: .constant(false),
Expand Down
Loading

0 comments on commit 058fe79

Please sign in to comment.