2023-08-09 20:51:03 -07:00
|
|
|
//
|
2023-08-24 14:18:04 -07:00
|
|
|
// 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
|
|
|
|
|
//
|
2023-08-22 17:02:05 -05:00
|
|
|
// FooterHidingModifier.swift
|
2023-08-09 20:51:03 -07:00
|
|
|
//
|
|
|
|
|
// Created by Nacho Soto on 8/9/23.
|
|
|
|
|
|
|
|
|
|
import RevenueCat
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
2023-11-08 07:35:19 -08:00
|
|
|
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
|
2023-08-09 20:51:03 -07:00
|
|
|
extension View {
|
|
|
|
|
|
2023-08-22 17:02:05 -05:00
|
|
|
func hideFooterContent(
|
2023-08-14 07:36:39 -07:00
|
|
|
_ configuration: TemplateViewConfiguration,
|
2023-08-22 18:27:43 -05:00
|
|
|
hide: Bool
|
2023-08-14 07:36:39 -07:00
|
|
|
) -> some View {
|
2023-08-22 17:02:05 -05:00
|
|
|
return self.modifier(FooterHidingModifier(configuration: configuration,
|
2023-08-22 18:27:43 -05:00
|
|
|
hide: hide))
|
2023-08-09 20:51:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-08 07:35:19 -08:00
|
|
|
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
|
2023-08-22 17:02:05 -05:00
|
|
|
private struct FooterHidingModifier: ViewModifier {
|
2023-08-09 20:51:03 -07:00
|
|
|
|
2023-08-14 07:36:39 -07:00
|
|
|
@State
|
|
|
|
|
private var height: CGFloat = 10
|
|
|
|
|
|
|
|
|
|
var configuration: TemplateViewConfiguration
|
2023-08-09 20:51:03 -07:00
|
|
|
var hide: Bool
|
|
|
|
|
|
|
|
|
|
func body(content: Content) -> some View {
|
2023-08-14 07:36:39 -07:00
|
|
|
switch self.configuration.mode {
|
2023-08-22 18:27:43 -05:00
|
|
|
case .fullScreen:
|
2023-08-14 07:36:39 -07:00
|
|
|
// These modes don't support hiding the content
|
|
|
|
|
content
|
|
|
|
|
.padding(.vertical)
|
|
|
|
|
|
2023-08-22 18:27:43 -05:00
|
|
|
case .footer:
|
|
|
|
|
content
|
2023-08-14 07:36:39 -07:00
|
|
|
|
2023-08-22 18:27:43 -05:00
|
|
|
case .condensedFooter:
|
|
|
|
|
content
|
2023-11-03 13:08:06 -07:00
|
|
|
.onHeightChange { if $0 > 0 { self.height = $0 } }
|
2023-08-22 18:27:43 -05:00
|
|
|
.opacity(self.hide ? 0 : 1)
|
|
|
|
|
.offset(
|
|
|
|
|
y: self.hide
|
|
|
|
|
? self.height
|
|
|
|
|
: 0
|
|
|
|
|
)
|
|
|
|
|
.frame(height: self.hide ? 0 : nil)
|
|
|
|
|
.blur(radius: self.hide ? Self.blurRadius : 0)
|
2023-08-14 07:36:39 -07:00
|
|
|
}
|
2023-08-09 20:51:03 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static let blurRadius: CGFloat = 20
|
|
|
|
|
|
|
|
|
|
}
|