Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update composer library version to 1.1.0 #7365

Merged
merged 2 commits into from
Feb 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Riot.xcworkspace/xcshareddata/swiftpm/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/matrix-org/matrix-wysiwyg-composer-swift",
"state" : {
"revision" : "3f72aeab7d7e04b52ff3f735ab79a75993f97ef2",
"version" : "0.22.0"
"revision" : "f25189fb9b37eb77fad016ee8f0b0346c5310644",
"version" : "1.1.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,26 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp
private var voiceMessageBottomConstraint: NSLayoutConstraint?
private var hostingViewController: VectorHostingController!
private var wysiwygViewModel = WysiwygComposerViewModel(
parserStyle: HTMLParserStyle(textColor: ThemeService.shared().theme.colors.primaryContent,
linkColor: ThemeService.shared().theme.colors.links,
codeBackgroundColor: ThemeService.shared().theme.selectedBackgroundColor,
codeBorderColor: ThemeService.shared().theme.textQuinaryColor,
quoteBackgroundColor: ThemeService.shared().theme.selectedBackgroundColor,
quoteBorderColor: ThemeService.shared().theme.textQuinaryColor,
borderWidth: 1.0,
cornerRadius: 4.0)
parserStyle: WysiwygInputToolbarView.parserStyle
)
/// Compute current HTML parser style for composer.
private static var parserStyle: HTMLParserStyle {
return HTMLParserStyle(
textColor: ThemeService.shared().theme.colors.primaryContent,
linkColor: ThemeService.shared().theme.colors.links,
codeBlockStyle: BlockStyle(backgroundColor: ThemeService.shared().theme.selectedBackgroundColor,
borderColor: ThemeService.shared().theme.textQuinaryColor,
borderWidth: 1.0,
cornerRadius: 4.0,
padding: .init(horizontal: 10.0, vertical: 12.0),
type: .background),
quoteBlockStyle: BlockStyle(backgroundColor: ThemeService.shared().theme.selectedBackgroundColor,
borderColor: ThemeService.shared().theme.selectedBackgroundColor,
borderWidth: 0.0,
cornerRadius: 0.0,
padding: .init(horizontal: 25.0, vertical: 12.0),
type: .side(offset: 5, width: 4)))
}
private var viewModel: ComposerViewModelProtocol!

private var isLandscapePhone: Bool {
Expand Down Expand Up @@ -304,14 +315,7 @@ class WysiwygInputToolbarView: MXKRoomInputToolbarView, NibLoadable, HtmlRoomInp

private func update(theme: Theme) {
hostingViewController.view.backgroundColor = theme.colors.background
wysiwygViewModel.parserStyle = HTMLParserStyle(textColor: ThemeService.shared().theme.colors.primaryContent,
linkColor: ThemeService.shared().theme.colors.links,
codeBackgroundColor: ThemeService.shared().theme.selectedBackgroundColor,
codeBorderColor: ThemeService.shared().theme.textQuinaryColor,
quoteBackgroundColor: ThemeService.shared().theme.selectedBackgroundColor,
quoteBorderColor: ThemeService.shared().theme.textQuinaryColor,
borderWidth: 1.0,
cornerRadius: 4.0)
wysiwygViewModel.parserStyle = WysiwygInputToolbarView.parserStyle
}

private func updateTextViewHeight() {
Expand Down
28 changes: 20 additions & 8 deletions RiotSwiftUI/Modules/Room/Composer/Model/ComposerModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ enum FormatType {
case unorderedList
case orderedList
case indent
case unIndent
case unindent
case inlineCode
case codeBlock
case quote
Expand All @@ -48,6 +48,18 @@ extension FormatType: CaseIterable, Identifiable {
var id: Self { self }
}

extension FormatType {
/// Return true if the format type is an indentation action.
var isIndentType: Bool {
switch self {
case .indent, .unindent:
return true
default:
return false
}
}
}

extension FormatItem: Identifiable {
var id: FormatType { type }
}
Expand All @@ -70,7 +82,7 @@ extension FormatItem {
return Asset.Images.numberedList.name
case .indent:
return Asset.Images.indentIncrease.name
case .unIndent:
case .unindent:
return Asset.Images.indentDecrease.name
case .inlineCode:
return Asset.Images.code.name
Expand Down Expand Up @@ -99,7 +111,7 @@ extension FormatItem {
return "orderedListButton"
case .indent:
return "indentListButton"
case .unIndent:
case .unindent:
return "unIndentButton"
case .inlineCode:
return "inlineCodeButton"
Expand Down Expand Up @@ -128,7 +140,7 @@ extension FormatItem {
return VectorL10n.wysiwygComposerFormatActionOrderedList
case .indent:
return VectorL10n.wysiwygComposerFormatActionIndent
case .unIndent:
case .unindent:
return VectorL10n.wysiwygComposerFormatActionUnIndent
case .inlineCode:
return VectorL10n.wysiwygComposerFormatActionInlineCode
Expand Down Expand Up @@ -160,8 +172,8 @@ extension FormatType {
return .orderedList
case .indent:
return .indent
case .unIndent:
return .unIndent
case .unindent:
return .unindent
case .inlineCode:
return .inlineCode
case .codeBlock:
Expand Down Expand Up @@ -191,8 +203,8 @@ extension FormatType {
return .orderedList
case .indent:
return .indent
case .unIndent:
return .unIndent
case .unindent:
return .unindent
case .inlineCode:
return .inlineCode
case .codeBlock:
Expand Down
28 changes: 28 additions & 0 deletions RiotSwiftUI/Modules/Room/Composer/Test/UI/ComposerUITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,32 @@ final class ComposerUITests: MockScreenTestCase {
XCTAssertFalse(minimiseButton.exists)
XCTAssertTrue(maximiseButton.exists)
}

func testCreatingListDisplaysIndentButtons() throws {
app.goToScreenWithIdentifier(MockComposerScreenState.send.title)

XCTAssertFalse(composerToolbarButton(in: app, for: .indent).exists)
XCTAssertFalse(composerToolbarButton(in: app, for: .indent).exists)
// Create a list.
composerToolbarButton(in: app, for: .orderedList).tap()
XCTAssertTrue(composerToolbarButton(in: app, for: .indent).exists)
XCTAssertTrue(composerToolbarButton(in: app, for: .indent).exists)
// Remove the list
composerToolbarButton(in: app, for: .orderedList).tap()
XCTAssertFalse(composerToolbarButton(in: app, for: .indent).exists)
XCTAssertFalse(composerToolbarButton(in: app, for: .indent).exists)
}
}

private extension ComposerUITests {
/// Returns the button of the composer toolbar associated with given format type.
///
/// - Parameters:
/// - app: the running app
/// - formatType: format type to look for
/// - Returns: XCUIElement for the button
func composerToolbarButton(in app: XCUIApplication, for formatType: FormatType) -> XCUIElement {
// Note: state is irrelevant here, we're just building this to retrieve the accessibility identifier.
app.buttons[FormatItem(type: formatType, state: .enabled).accessibilityIdentifier]
}
}
22 changes: 16 additions & 6 deletions RiotSwiftUI/Modules/Room/Composer/View/Composer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,15 @@ struct Composer: View {
}

private var formatItems: [FormatItem] {
FormatType.allCases.map { type in
FormatItem(
type: type,
state: wysiwygViewModel.actionStates[type.composerAction] ?? .disabled
)
}
return FormatType.allCases
// Exclude indent type outside of lists.
.filter { wysiwygViewModel.isInList || !$0.isIndentType }
.map { type in
FormatItem(
type: type,
state: wysiwygViewModel.actionStates[type.composerAction] ?? .disabled
)
}
}

private var composerContainer: some View {
Expand Down Expand Up @@ -257,6 +260,13 @@ struct Composer: View {
}
}

private extension WysiwygComposerViewModel {
/// Return true if the selection of the composer is currently located in a list.
var isInList: Bool {
actionStates[.orderedList] == .reversed || actionStates[.unorderedList] == .reversed
}
}

// MARK: Previews

struct Composer_Previews: PreviewProvider {
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-7365.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Labs: Rich Text Editor: Update to version 1.1.0
2 changes: 1 addition & 1 deletion project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ packages:
branch: main
WysiwygComposer:
url: https://github.com/matrix-org/matrix-wysiwyg-composer-swift
version: 0.22.0
version: 1.1.0
DeviceKit:
url: https://github.com/devicekit/DeviceKit
majorVersion: 4.7.0
Expand Down