Ferrite-backup/Ferrite/Views/CommonViews/SearchableContent.swift
kingbri 438e48be66 Ferrite: Format
Signed-off-by: kingbri <bdashore3@proton.me>
2023-03-03 15:09:34 -05:00

37 lines
1 KiB
Swift

//
// SearchableContent.swift
// Ferrite
//
// Created by Brian Dashore on 2/11/23.
//
// View to link animations together with searchbar
// Passes through geometry proxy and last height vars for any comparison
//
import SwiftUI
struct SearchableContent<Content: View>: View {
@Binding var searching: Bool
@State private var lastHeight: CGFloat = 0.0
@ViewBuilder var content: (Bool) -> Content
var body: some View {
GeometryReader { geom in
// Return if the height has changed as a closure variable for child transactions
content(geom.size.height != lastHeight)
.backport.onAppear {
lastHeight = geom.size.height
}
.onChange(of: geom.size.height) { newHeight in
lastHeight = newHeight
}
.transaction {
if geom.size.height != lastHeight, searching {
$0.animation = .default.speed(2)
}
}
}
}
}