From 7b91510fe1685b4ed7f18cf0e6558f84c30f422c Mon Sep 17 00:00:00 2001 From: Mark Villacampa Date: Mon, 16 Dec 2024 18:23:09 +0100 Subject: [PATCH] do not extract Text view --- .../V2/ViewHelpers/BadgeModifier.swift | 40 ++++++++++++------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/RevenueCatUI/Templates/V2/ViewHelpers/BadgeModifier.swift b/RevenueCatUI/Templates/V2/ViewHelpers/BadgeModifier.swift index c1dd1d348f..4178cbc55e 100644 --- a/RevenueCatUI/Templates/V2/ViewHelpers/BadgeModifier.swift +++ b/RevenueCatUI/Templates/V2/ViewHelpers/BadgeModifier.swift @@ -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 { @@ -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( @@ -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) } @@ -92,6 +91,7 @@ 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 { @@ -99,7 +99,11 @@ fileprivate extension View { 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) @@ -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) @@ -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)