Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Sources/LegacyScrollView/Proxy/LegacyScrollViewProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import SwiftUI

public struct LegacyScrollViewProxy {

internal var getScrollView: () -> UIScrollView
internal var getScrollView: () -> UIScrollView?
internal var getRectOfContent: (_ id: Int) -> CGRect?
internal var performScrollToPoint: (_ point: CGPoint, _ animated: Bool) -> Void
internal var performScrollToId: (_ id: Int, _ anchor: UnitPoint, _ animated: Bool) -> Void
internal var performScrollToIdIfNeeded: (_ id: Int, _ anchor: UnitPoint) -> Void

/// Returns the UIScrollView
public var scrollView: UIScrollView { getScrollView() }
public var scrollView: UIScrollView? { getScrollView() }
/// returns the content's CGRect
public func rectOfContent<ID: Hashable>(id: ID) -> CGRect? { getRectOfContent(id.hashValue) }
/// performs a scroll to a specific `CGPoint`
Expand All @@ -31,7 +31,7 @@ public struct LegacyScrollViewProxy {
extension LegacyScrollViewReader {
func makeProxy(with view: LegacyUIScrollViewReader) -> LegacyScrollViewProxy {
LegacyScrollViewProxy {
view.scrollView!
view.scrollView
} getRectOfContent: { id in
getRectOfContent(with: id, in: view)
} performScrollToPoint: { point, animated in
Expand Down
4 changes: 4 additions & 0 deletions Sources/LegacyScrollView/Proxy/LegacyScrollViewReader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public struct LegacyScrollViewReader<Content: View>: UIViewRepresentable {
}

public func updateUIView(_ view: LegacyUIScrollViewReader, context: Context) {
guard let _ = view.scrollView else {
//Warning: updateUIView called before view was added to view hierarchy
return
}
let proxy = makeProxy(with: view)
let contentView = content(proxy)

Expand Down