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

Use CDMarkdownLayoutManager in MessageBodyTextView #1399

Merged
merged 2 commits into from
Oct 24, 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
2 changes: 1 addition & 1 deletion NextcloudTalk.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3134,7 +3134,7 @@
repositoryURL = "https://github.com/nextcloud-deps/CDMarkdownKit.git";
requirement = {
kind = revision;
revision = a425cc36263996ce4d992178f9847760a166fe8e;
revision = 7675b9c3f8b55ffd129e4a93032efb6a4e00db75;
};
};
1F0ECBFB2A73F21A00921E90 /* XCRemoteSwiftPackageReference "realm-swift" */ = {
Expand Down
20 changes: 12 additions & 8 deletions NextcloudTalk/MessageBodyTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,22 @@
#import "NCUtils.h"
#import "OpenInFirefoxControllerObjC.h"

#import "NextcloudTalk-Swift.h"

@implementation MessageBodyTextView

- (instancetype)init
{
// Use TextKit1 to have the background of code/syntax blocks span the whole line
if (@available(iOS 16.0, *)) {
self = [MessageBodyTextView textViewUsingTextLayoutManager:false];
} else {
self = [super init];
}

NSTextStorage *textStorage = [NSTextStorage new];

NSLayoutManager *layoutManager = (NSLayoutManager *)[SwiftMarkdownObjCBridge getLayoutManager];
[textStorage addLayoutManager: layoutManager];

NSTextContainer *textContainer = [NSTextContainer new];
[layoutManager addTextContainer: textContainer];

self = [[MessageBodyTextView alloc] initWithFrame:CGRectZero textContainer:textContainer];

if (!self) {
return nil;
}
Expand All @@ -50,7 +55,6 @@ - (instancetype)init
self.editable = NO;
self.scrollEnabled = NO;
self.delegate = self;

return self;
}

Expand Down
6 changes: 6 additions & 0 deletions NextcloudTalk/SwiftMarkdownObjCBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,10 @@ import UIKit
static func parseMarkdown(markdownString: NSAttributedString) -> NSMutableAttributedString {
return NSMutableAttributedString(attributedString: markdownParser.parse(markdownString))
}

static func getLayoutManager() -> CDMarkdownLayoutManager {
let manager = CDMarkdownLayoutManager()
manager.roundAllCorners = true
return manager
}
}
Loading