Skip to content

Commit

Permalink
Move All Delegate Calls Outside Layout Pass
Browse files Browse the repository at this point in the history
  • Loading branch information
thecoolwinter committed Nov 17, 2024
1 parent 013566b commit 7456734
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,13 @@ public class TextLayoutManager: NSObject {
// Update the visible lines with the new set.
visibleLineIds = newVisibleLines

#if DEBUG
isInLayout = false
#endif

// These are fine to update outside of `isInLayout` as our internal data structures are finalized at this point
// so laying out again won't break our line storage or visible line.

if maxFoundLineWidth > maxLineWidth {
maxLineWidth = maxFoundLineWidth
}
Expand All @@ -274,15 +281,11 @@ public class TextLayoutManager: NSObject {
delegate?.layoutManagerYAdjustment(yContentAdjustment)
}

#if DEBUG
isInLayout = false
#endif
needsLayout = false

// This needs to happen after ``needsLayout`` is toggled. Things can be triggered by frame changes.
if originalHeight != lineStorage.height || layoutView?.frame.size.height != lineStorage.height {
delegate?.layoutManagerHeightDidUpdate(newHeight: lineStorage.height)
}

needsLayout = false
}

/// Lays out a single text line.
Expand Down
2 changes: 2 additions & 0 deletions Sources/CodeEditTextView/TextView/TextView+Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ extension TextView {
inputContext?.invalidateCharacterCoordinates()
}

/// Updates the view's frame if needed depending on wrapping lines, a new maximum width, or changed available size.
/// - Returns: Whether or not the view was updated.
@discardableResult
public func updateFrameIfNeeded() -> Bool {
var availableSize = scrollView?.contentSize ?? .zero
Expand Down

0 comments on commit 7456734

Please sign in to comment.