mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-05 11:58:32 +00:00
Various optimisations (#1878)
* Cache TimelineBubbleLayout subview sizes * Cache MessageText sizes, avoid extra updates * Only use the `CollapsibleReactionLayout` if there's more than 5 reactions on a particular message * Upgrade Sentry to 8.13.0, disable various options as they're not useful and impact performance * Address PR comments, fix unit tests
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
//
|
||||
// Copyright 2023 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 SwiftUI
|
||||
|
||||
extension ProposedViewSize: Hashable {
|
||||
public func hash(into hasher: inout Hasher) {
|
||||
hasher.combine(width)
|
||||
hasher.combine(height)
|
||||
}
|
||||
}
|
||||
@@ -49,7 +49,13 @@ final class MessageTextView: UITextView {
|
||||
struct MessageText: UIViewRepresentable {
|
||||
@Environment(\.openURL) private var openURLAction: OpenURLAction
|
||||
@EnvironmentObject private var viewModel: RoomScreenViewModel.Context
|
||||
@State var attributedString: AttributedString
|
||||
@State private var computedSizes = [Double: CGSize]()
|
||||
|
||||
@State var attributedString: AttributedString {
|
||||
didSet {
|
||||
computedSizes.removeAll()
|
||||
}
|
||||
}
|
||||
|
||||
func makeUIView(context: Context) -> MessageTextView {
|
||||
// Need to use TextKit 1 for mentions
|
||||
@@ -81,13 +87,20 @@ struct MessageText: UIViewRepresentable {
|
||||
return textView
|
||||
}
|
||||
|
||||
func updateUIView(_ uiView: MessageTextView, context: Context) {
|
||||
uiView.attributedText = NSAttributedString(attributedString)
|
||||
context.coordinator.openURLAction = openURLAction
|
||||
}
|
||||
func updateUIView(_ uiView: MessageTextView, context: Context) { }
|
||||
|
||||
func sizeThatFits(_ proposal: ProposedViewSize, uiView: MessageTextView, context: Context) -> CGSize? {
|
||||
uiView.sizeThatFits(CGSize(width: proposal.width ?? UIView.layoutFittingExpandedSize.width, height: UIView.layoutFittingCompressedSize.height))
|
||||
let proposalWidth = proposal.width ?? UIView.layoutFittingExpandedSize.width
|
||||
|
||||
if let size = computedSizes[proposalWidth] {
|
||||
return size
|
||||
}
|
||||
|
||||
let size = uiView.sizeThatFits(CGSize(width: proposalWidth, height: UIView.layoutFittingCompressedSize.height))
|
||||
DispatchQueue.main.async {
|
||||
computedSizes[proposalWidth] = size
|
||||
}
|
||||
return size
|
||||
}
|
||||
|
||||
func makeCoordinator() -> Coordinator {
|
||||
|
||||
Reference in New Issue
Block a user