- Fix: CollapsingMarkdownView was not reloading properly during layoutSubviews phase

This commit is contained in:
mahee96
2025-02-28 02:28:34 +05:30
parent cfaf79f878
commit 2197161d55
3 changed files with 12 additions and 19 deletions

View File

@@ -282,11 +282,8 @@ private extension MyAppsViewController
} }
cell.versionDescriptionTextView.toggleButton.addTarget(self, action: #selector(MyAppsViewController.toggleUpdateCellMode(_:)), for: .primaryActionTriggered) cell.versionDescriptionTextView.toggleButton.addTarget(self, action: #selector(MyAppsViewController.toggleUpdateCellMode(_:)), for: .primaryActionTriggered)
cell.setNeedsLayout() cell.setNeedsLayout()
// Below lines are necessary to avoid "more" button layout issues.
cell.versionDescriptionTextView.setNeedsLayout()
cell.layoutIfNeeded() cell.layoutIfNeeded()
} }
dataSource.prefetchHandler = { (installedApp, indexPath, completionHandler) in dataSource.prefetchHandler = { (installedApp, indexPath, completionHandler) in

View File

@@ -92,16 +92,16 @@ extension UpdateCollectionViewCell
} }
} }
override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize // override func systemLayoutSizeFitting(_ targetSize: CGSize, withHorizontalFittingPriority horizontalFittingPriority: UILayoutPriority, verticalFittingPriority: UILayoutPriority) -> CGSize
{ // {
// Ensure cell is laid out so it will report correct size. // // Ensure cell is laid out so it will report correct size.
self.versionDescriptionTextView.setNeedsLayout() // self.versionDescriptionTextView.setNeedsLayout()
self.versionDescriptionTextView.layoutIfNeeded() // self.versionDescriptionTextView.layoutIfNeeded()
//
let size = super.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: horizontalFittingPriority, verticalFittingPriority: verticalFittingPriority) // let size = super.systemLayoutSizeFitting(targetSize, withHorizontalFittingPriority: horizontalFittingPriority, verticalFittingPriority: verticalFittingPriority)
//
return size // return size
} // }
} }
private extension UpdateCollectionViewCell private extension UpdateCollectionViewCell

View File

@@ -64,14 +64,12 @@ final class CollapsingMarkdownView: UIView {
var text: String = "" { var text: String = "" {
didSet { didSet {
self.updateMarkdownContent() self.updateMarkdownContent()
self.shouldResetLayout = true
self.setNeedsLayout() self.setNeedsLayout()
} }
} }
var lineSpacing: Double = 2 { var lineSpacing: Double = 2 {
didSet { didSet {
self.shouldResetLayout = true
self.setNeedsLayout() self.setNeedsLayout()
} }
} }
@@ -81,7 +79,6 @@ final class CollapsingMarkdownView: UIView {
private let textView = UITextView() private let textView = UITextView()
private let markdownParser = MarkdownManager().markdownParser private let markdownParser = MarkdownManager().markdownParser
private var shouldResetLayout: Bool = false
private var previousSize: CGSize? private var previousSize: CGSize?
// MARK: - Initialization // MARK: - Initialization
@@ -212,9 +209,8 @@ final class CollapsingMarkdownView: UIView {
textView.frame = bounds textView.frame = bounds
// Check if content needs collapsing when layout changes // Check if content needs collapsing when layout changes
if shouldResetLayout || previousSize?.width != bounds.width { if previousSize?.width != bounds.width {
checkIfNeedsCollapsing() checkIfNeedsCollapsing()
shouldResetLayout = false
previousSize = bounds.size previousSize = bounds.size
} }