Skip to content

Commit

Permalink
Forgot this file
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdholtz committed Nov 11, 2024
1 parent 49ecfa7 commit 582f6e3
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions RevenueCatUI/Templates/Components/SizeModifier.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//
// Copyright RevenueCat Inc. All Rights Reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// SizeModifier.swift
//
// Created by Josh Holtz on 11/11/24.

import RevenueCat
import SwiftUI

#if PAYWALL_COMPONENTS

struct SizeModifier: ViewModifier {

var size: PaywallComponent.Size

func body(content: Content) -> some View {
content
.applyWidth(size.width)
.applyHeight(size.height)
}

}

extension View {

@ViewBuilder
func applyWidth(_ sizeConstraint: PaywallComponent.SizeConstraint) -> some View {
switch sizeConstraint {
case .fit:
self
case .fill:
self
.frame(maxWidth: .infinity)
case .fixed(let value):
self
.frame(width: CGFloat(value))
}
}

@ViewBuilder
func applyHeight(_ sizeConstraint: PaywallComponent.SizeConstraint) -> some View {
switch sizeConstraint {
case .fit:
self
case .fill:
self
.frame(maxHeight: .infinity)
case .fixed(let value):
self
.frame(height: CGFloat(value))
}
}

}

extension View {

func size(_ size: PaywallComponent.Size) -> some View {
self.modifier(SizeModifier(size: size))
}

}

#endif

0 comments on commit 582f6e3

Please sign in to comment.