mirror of
https://gitlab.opencode.de/bwi/bundesmessenger/clients/bundesmessenger-ios.git
synced 2026-04-21 17:12:45 +02:00
18a2360296
#7409: Permalinks to a room/space are pillified #7411: Permalinks to a matrix user are pillified #7412: Permalinks to messages are pillified
61 lines
2.6 KiB
Swift
61 lines
2.6 KiB
Swift
//
|
|
// 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 UIKit
|
|
|
|
/// Provider for mention Pills attachment view.
|
|
@available(iOS 15.0, *)
|
|
@objc class PillAttachmentViewProvider: NSTextAttachmentViewProvider {
|
|
// MARK: - Properties
|
|
static let pillAttachmentViewSizes = PillAttachmentView.Sizes(verticalMargin: 2.0,
|
|
horizontalMargin: 6.0,
|
|
avatarLeading: 2.0,
|
|
avatarSideLength: 20.0,
|
|
itemSpacing: 4)
|
|
private weak var messageTextView: MXKMessageTextView?
|
|
|
|
// MARK: - Override
|
|
override init(textAttachment: NSTextAttachment, parentView: UIView?, textLayoutManager: NSTextLayoutManager?, location: NSTextLocation) {
|
|
super.init(textAttachment: textAttachment, parentView: parentView, textLayoutManager: textLayoutManager, location: location)
|
|
|
|
self.messageTextView = parentView?.superview as? MXKMessageTextView
|
|
}
|
|
|
|
override func loadView() {
|
|
super.loadView()
|
|
|
|
guard let textAttachment = self.textAttachment as? PillTextAttachment else {
|
|
MXLog.debug("[PillAttachmentViewProvider]: attachment is missing or not of expected class")
|
|
return
|
|
}
|
|
|
|
guard let pillData = textAttachment.data else {
|
|
MXLog.debug("[PillAttachmentViewProvider]: attachment misses pill data")
|
|
return
|
|
}
|
|
|
|
let mainSession = AppDelegate.theDelegate().mxSessions.first as? MXSession
|
|
|
|
let pillView = PillAttachmentView(frame: CGRect(origin: .zero, size: textAttachment.size(forFont: pillData.font)),
|
|
sizes: Self.pillAttachmentViewSizes,
|
|
theme: ThemeService.shared().theme,
|
|
mediaManager: mainSession?.mediaManager,
|
|
andPillData: pillData)
|
|
view = pillView
|
|
messageTextView?.registerPillView(pillView)
|
|
}
|
|
}
|