diff --git a/Riot/Modules/Application/AppDelegate.swift b/Riot/Modules/Application/AppDelegate.swift index c92e2e21c..e112fa7e0 100644 --- a/Riot/Modules/Application/AppDelegate.swift +++ b/Riot/Modules/Application/AppDelegate.swift @@ -61,7 +61,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { // Register pills provider. if #available(iOS 15.0, *) { - NSTextAttachment.registerViewProviderClass(PillAttachmentViewProvider.self, forFileType: "im.vector.app.pills") + NSTextAttachment.registerViewProviderClass(PillAttachmentViewProvider.self, forFileType: StringPillsUtils.pillUTType) } // Create AppCoordinator diff --git a/Riot/Modules/Pills/PillAttachmentView.swift b/Riot/Modules/Pills/PillAttachmentView.swift index 4ed0b2d4f..4f2061e4d 100644 --- a/Riot/Modules/Pills/PillAttachmentView.swift +++ b/Riot/Modules/Pills/PillAttachmentView.swift @@ -17,6 +17,8 @@ import UIKit /// Base view class for mention Pills. +@available (iOS 15.0, *) +@objcMembers class PillAttachmentView: UIView { /// Computes size required to display a pill for given room member. /// diff --git a/Riot/Modules/Pills/PillTextAttachment.swift b/Riot/Modules/Pills/PillTextAttachment.swift index 5b939627c..3469cb17f 100644 --- a/Riot/Modules/Pills/PillTextAttachment.swift +++ b/Riot/Modules/Pills/PillTextAttachment.swift @@ -18,7 +18,9 @@ import UIKit import MatrixSDK /// Text attachment for pills display. -@objcMembers class PillTextAttachment: NSTextAttachment { +@available (iOS 15.0, *) +@objcMembers +class PillTextAttachment: NSTextAttachment { // MARK: - Internal Properties var roomMember: MXRoomMember? var isCurrentUser: Bool = false @@ -38,7 +40,7 @@ import MatrixSDK } init(withRoomMember roomMember: MXRoomMember, isCurrentUser: Bool) { - super.init(data: nil, ofType: "im.vector.app.pills") + super.init(data: nil, ofType: StringPillsUtils.pillUTType) self.roomMember = roomMember self.isCurrentUser = isCurrentUser let pillSize = PillAttachmentView.size(forRoomMember: roomMember) @@ -52,7 +54,7 @@ import MatrixSDK } super.init(coder: coder) - self.fileType = "im.vector.app.pills" + self.fileType = StringPillsUtils.pillUTType self.roomMember = roomMember self.isCurrentUser = coder.decodeBool(forKey: Constants.isCurrentUserKey) diff --git a/Riot/Modules/Pills/StringPillsUtils.swift b/Riot/Modules/Pills/StringPillsUtils.swift index 8665db3b8..6240f03f5 100644 --- a/Riot/Modules/Pills/StringPillsUtils.swift +++ b/Riot/Modules/Pills/StringPillsUtils.swift @@ -21,6 +21,10 @@ import UIKit @available (iOS 15.0, *) @objcMembers class StringPillsUtils: NSObject { + // MARK: - Internal Properties + /// UTType identifier for pills. Should be declared as Document type & Exported type identifier inside Info.plist + static let pillUTType: String = "im.vector.app.pills" + // MARK: - Internal Methods /// Insert text attachments for pills inside given message attributed string. /// diff --git a/Riot/Modules/Room/CellData/RoomBubbleCellData.m b/Riot/Modules/Room/CellData/RoomBubbleCellData.m index 2792de1c2..d367d244d 100644 --- a/Riot/Modules/Room/CellData/RoomBubbleCellData.m +++ b/Riot/Modules/Room/CellData/RoomBubbleCellData.m @@ -433,9 +433,11 @@ NSString *const URLPreviewDidUpdateNotification = @"URLPreviewDidUpdateNotificat { // Apply alpha to blur this component componentString = [Tools setTextColorAlpha:.2 inAttributedString:componentString]; - [Tools setPillAlpha:.2 inAttributedString:componentString]; + if (@available(iOS 15.0, *)) { + [Tools setPillAlpha:.2 inAttributedString:componentString]; + } } - else + else if (@available(iOS 15.0, *)) { // PillTextAttachment are not created again every time, we have to set alpha back to standard if needed. [Tools setPillAlpha:1.f inAttributedString:componentString]; @@ -478,9 +480,11 @@ NSString *const URLPreviewDidUpdateNotification = @"URLPreviewDidUpdateNotificat { // Apply alpha to blur this component componentString = [Tools setTextColorAlpha:.2 inAttributedString:componentString]; - [Tools setPillAlpha:.2 inAttributedString:componentString]; + if (@available(iOS 15.0, *)) { + [Tools setPillAlpha:.2 inAttributedString:componentString]; + } } - else + else if (@available(iOS 15.0, *)) { // PillTextAttachment are not created again every time, we have to set alpha back to standard if needed. [Tools setPillAlpha:1.f inAttributedString:componentString]; diff --git a/Riot/Utils/Tools.swift b/Riot/Utils/Tools.swift index 1dc840222..e2f1954a0 100644 --- a/Riot/Utils/Tools.swift +++ b/Riot/Utils/Tools.swift @@ -41,6 +41,7 @@ extension Tools { /// - Parameters: /// - alpha: Alpha value to apply /// - attributedString: Attributed string containing the pills + @available (iOS 15.0, *) @objc static func setPillAlpha(_ alpha: CGFloat, inAttributedString attributedString: NSAttributedString) { let totalRange = NSRange(location: 0, length: attributedString.length) attributedString.vc_enumerateAttribute(.attachment,