Skip to content

Commit

Permalink
Expose public API
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-onyschuk committed Sep 20, 2024
1 parent 4117810 commit 265041f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
10 changes: 0 additions & 10 deletions Sources/Geometry/Extensions/CGPathExt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,16 +82,6 @@ extension CGPath {

// MARK: - Helper Functions

/// Limits the precision of a CGFloat to a specified number of decimal places.
/// - Parameters:
/// - value: The CGFloat value to limit.
/// - places: The number of decimal places to retain.
/// - Returns: A CGFloat rounded to the specified number of decimal places.
private func limitPrecision(_ value: CGFloat, toDecimalPlaces places: Int) -> CGFloat {
let multiplier = pow(10.0, CGFloat(places))
return (value * multiplier).rounded() / multiplier
}

/// Creates a CGVector from two CGPoints.
/// - Parameters:
/// - from: The starting CGPoint.
Expand Down
17 changes: 14 additions & 3 deletions Sources/Geometry/SwiftUI View Modifiers/FrameListModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,26 @@ private enum FrameListModifier<ID>: ViewModifier where ID: Hashable {
}

extension View {
func frames<ID>(_ value: Binding<[ID: CGRect]>) -> some View where ID: Hashable {

/// A modifier which observes changes to view frames with corresponding IDs
/// - Parameter value: a binding to a dictionary of IDs to frame rectangle
/// - Returns: a View
public func frames<ID>(_ value: Binding<[ID: CGRect]>) -> some View where ID: Hashable {
readFrames { value.wrappedValue = $0 }
}

func writeFrame<ID>(id: ID, coordinates: CoordinateSpace) -> some View where ID: Hashable {
/// A modifier which writes changes to the current view's frame with corresponding `id`
/// - Parameter id: the current view's corresponding ID
/// - Parameter coordinates: the coordinate space in which the frame is expressed
/// - Returns: a View
public func writeFrame<ID>(id: ID, coordinates: CoordinateSpace) -> some View where ID: Hashable {
self.modifier(FrameListModifier<ID>.writer(id: id, coordinates: coordinates))
}

func readFrames<ID>(onChange: @escaping ([ID: CGRect])-> ()) -> some View where ID: Hashable {
/// A modifier which reads changes to view frames with corresponding IDs
/// - Parameter value: a binding to a dictionary of IDs to frame rectangle
/// - Returns: a View
public func readFrames<ID>(onChange: @escaping ([ID: CGRect])-> ()) -> some View where ID: Hashable {
self.modifier(FrameListModifier<ID>.reader(onChange: onChange))
}
}
6 changes: 3 additions & 3 deletions Sources/Geometry/SwiftUI View Modifiers/FrameModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private struct FrameModifier: ViewModifier {

extension View {

/// An extension whose `value` tracks the enclosed view's bounding rectangle in `coordinates`
/// A modifier whose `value` tracks the enclosed view's bounding rectangle in `coordinates`
/// - Parameters:
/// - value: a `CGRect` binding
/// - coordinates: a coordinate space
Expand All @@ -47,7 +47,7 @@ extension View {
})
}

/// An extension whose `value` tracks the enclosed view's size in `coordinates`
/// A modifier whose `value` tracks the enclosed view's size in `coordinates`
/// - Parameters:
/// - value: a `CGSize` binding
/// - coordinates: a coordinate space
Expand All @@ -58,7 +58,7 @@ extension View {
})
}

/// An extension whose `value` tracks the enclosed view's origin in `coordinates`
/// A modifier whose `value` tracks the enclosed view's origin in `coordinates`
/// - Parameters:
/// - value: a `CGPoint` binding
/// - coordinates: a coordinate space
Expand Down

0 comments on commit 265041f

Please sign in to comment.