Skip to content

Commit

Permalink
Clairfy how scroll view monitoring works, and conditionalize it on init
Browse files Browse the repository at this point in the history
  • Loading branch information
mattmassicotte committed Oct 14, 2024
1 parent 672c96b commit d213695
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Sources/Neon/TextViewHighlighter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ public final class TextViewHighlighter {
private var lastVisibleRange = NSRange.zero
#endif

/// Create a instance.
///
/// This method will also invoke `observeEnclosingScrollView` if `textView` is within a scroll view. If not, you can invoke it directly after the view has been placed into a scroll view.
public init(
textView: TextView,
configuration: Configuration
Expand Down Expand Up @@ -128,7 +131,9 @@ public final class TextViewHighlighter {

try textView.getTextStorage().delegate = storageDelegate

observeEnclosingScrollView()
if textView.enclosingScrollView != nil {

Check failure on line 134 in Sources/Neon/TextViewHighlighter.swift

View workflow job for this annotation

GitHub Actions / Test (platform=iOS Simulator,name=iPhone 15)

value of type 'TextView' (aka 'UITextView') has no member 'enclosingScrollView'
observeEnclosingScrollView()
}

invalidate(.all)
}
Expand All @@ -145,6 +150,9 @@ public final class TextViewHighlighter {
}

extension TextViewHighlighter {
/// Begin monitoring for containing scroll view changes.
///
/// This method sets up all the necessary monitoring so the highlighter can react to scrolling. It should be called only once the view heirarchy is fully established.
public func observeEnclosingScrollView() {
#if os(macOS) && !targetEnvironment(macCatalyst)
guard let scrollView = textView.enclosingScrollView else {
Expand Down

0 comments on commit d213695

Please sign in to comment.