Skip to content

Commit

Permalink
do not extract Text view
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkVillacampa committed Dec 16, 2024
1 parent 782ab80 commit 7b91510
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions RevenueCatUI/Templates/V2/ViewHelpers/BadgeModifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,6 @@ struct BadgeModifier: ViewModifier {
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
fileprivate extension View {

@ViewBuilder
func text(badge: BadgeModifier.BadgeInfo, textComponentViewModel: TextComponentViewModel) -> some View {
VStack {
TextComponentView(viewModel: textComponentViewModel)
.backgroundStyle(badge.backgroundColor.backgroundStyle)
.shape(border: nil, shape: effectiveShape(badge: badge))
}
}

@ViewBuilder
func apply(badge: BadgeModifier.BadgeInfo, textComponentViewModel: TextComponentViewModel) -> some View {
switch badge.style {
Expand All @@ -69,7 +60,11 @@ fileprivate extension View {
case .overlaid:
self.overlay(
VStack(alignment: .leading) {
self.text(badge: badge, textComponentViewModel: textComponentViewModel)
VStack {
TextComponentView(viewModel: textComponentViewModel)
.backgroundStyle(badge.backgroundColor.backgroundStyle)
.shape(border: nil, shape: effectiveShape(badge: badge))
}
.fixedSize()
.padding(effectiveMargin(badge: badge).edgeInsets)
.alignmentGuide(
Expand All @@ -81,7 +76,11 @@ fileprivate extension View {
case .nested:
self.overlay(
VStack(alignment: .leading) {
self.text(badge: badge, textComponentViewModel: textComponentViewModel)
VStack {
TextComponentView(viewModel: textComponentViewModel)
.backgroundStyle(badge.backgroundColor.backgroundStyle)
.shape(border: nil, shape: effectiveShape(badge: badge))
}
.fixedSize()
.padding(effectiveMargin(badge: badge).edgeInsets)
}
Expand All @@ -92,14 +91,19 @@ fileprivate extension View {

// Helper to apply the edge-to-edge badge style
@ViewBuilder
// swiftlint:disable:next function_body_length
private func appleBadgeEdgeToEdge(
badge: BadgeModifier.BadgeInfo,
textComponentViewModel: TextComponentViewModel) -> some View {
switch badge.alignment {
case .bottom:
self.background(
VStack(alignment: .leading) {
self.text(badge: badge, textComponentViewModel: textComponentViewModel)
VStack {
TextComponentView(viewModel: textComponentViewModel)
.backgroundStyle(badge.backgroundColor.backgroundStyle)
.shape(border: nil, shape: effectiveShape(badge: badge))
}
.alignmentGuide(.bottom) { dim in dim[VerticalAlignment.top] }
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: badge.alignment.stackAlignment)
Expand All @@ -117,7 +121,11 @@ fileprivate extension View {
case .top:
self.background(
VStack(alignment: .leading) {
self.text(badge: badge, textComponentViewModel: textComponentViewModel)
VStack {
TextComponentView(viewModel: textComponentViewModel)
.backgroundStyle(badge.backgroundColor.backgroundStyle)
.shape(border: nil, shape: effectiveShape(badge: badge))
}
.alignmentGuide(.top) { dim in dim[VerticalAlignment.bottom] }
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: badge.alignment.stackAlignment)
Expand All @@ -135,7 +143,11 @@ fileprivate extension View {
case .bottomLeading, .bottomTrailing, .topLeading, .topTrailing:
self.overlay(
VStack(alignment: .leading) {
self.text(badge: badge, textComponentViewModel: textComponentViewModel)
VStack {
TextComponentView(viewModel: textComponentViewModel)
.backgroundStyle(badge.backgroundColor.backgroundStyle)
.shape(border: nil, shape: effectiveShape(badge: badge))
}
.fixedSize()
}
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: badge.alignment.stackAlignment)
Expand Down

0 comments on commit 7b91510

Please sign in to comment.