Skip to content

Commit

Permalink
Rounded corners
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Aug 4, 2023
1 parent c6e68e7 commit 7b12bb4
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 6 deletions.
46 changes: 46 additions & 0 deletions RevenueCatUI/Modifiers/ViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ extension View {
}
}

}

// MARK: - Scrolling

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension View {

@ViewBuilder
func scrollable(
_ axes: Axis.Set = .vertical,
Expand Down Expand Up @@ -60,6 +67,12 @@ extension View {
}
}
}
}

// MARK: - Size changes

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension View {

/// Invokes the given closure whethever the view size changes.
func onSizeChange(_ closure: @escaping (CGSize) -> Void) -> some View {
Expand Down Expand Up @@ -96,6 +109,39 @@ extension View {

}

// MARK: - Rounded corners

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
extension View {

func roundedCorner(
_ radius: CGFloat,
corners: UIRectCorner,
edgesIgnoringSafeArea edges: Edge.Set = []
) -> some View {
self.mask(
RoundedCorner(radius: radius, corners: corners)
.edgesIgnoringSafeArea(edges)
)
}

}

@available(iOS 13.0, tvOS 13.0, macOS 10.15, watchOS 6.2, *)
private struct RoundedCorner: Shape {

var radius: CGFloat
var corners: UIRectCorner

func path(in rect: CGRect) -> Path {
let path = UIBezierPath(roundedRect: rect,
byRoundingCorners: self.corners,
cornerRadii: CGSize(width: self.radius, height: self.radius))
return Path(path.cgPath)
}

}

// MARK: - Preference Keys

/// `PreferenceKey` for keeping track of a view dimension.
Expand Down
9 changes: 3 additions & 6 deletions RevenueCatUI/Templates/MultiPackageHorizontalTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,9 @@ struct MultiPackageHorizontalTemplate: TemplateViewType {
.edgesIgnoringSafeArea(.bottom)
.frame(maxWidth: .infinity, alignment: .bottom)
.background(self.configuration.colors.backgroundColor)
// TODO: relative shape?
// TODO: bottom corners
.mask(
RoundedRectangle(cornerRadius: Self.cornerRadius)
.edgesIgnoringSafeArea(.bottom)
)
.roundedCorner(Self.cornerRadius,
corners: [.topLeft, .topRight],
edgesIgnoringSafeArea: .bottom)
}
}

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7b12bb4

Please sign in to comment.