Ferrite-backup/Ferrite/Extensions/View.swift
kingbri 4d3a16f77e Library: Add history functionality
Action history is logged and displayed to the user's library.
These are triggered whenever the magnet choice sheet is displayed.

Also redo alerts and action sheets to avoid deprecation notices
for >iOS 14. These will be removed when iOS 14 support is dropped.

There was also a problem with sheet presentation not working after
a sheet was dismissed. Disable the appropriate view when a sheet
is being presented.

Signed-off-by: kingbri <bdashore3@proton.me>
2022-09-16 12:33:21 -04:00

72 lines
2.1 KiB
Swift

//
// View.swift
// Ferrite
//
// Created by Brian Dashore on 8/15/22.
//
import Introspect
import SwiftUI
extension View {
// MARK: Custom introspect functions
func introspectCollectionView(customize: @escaping (UICollectionView) -> Void) -> some View {
inject(UIKitIntrospectionView(
selector: { introspectionView in
guard let viewHost = Introspect.findViewHost(from: introspectionView) else {
return nil
}
return Introspect.previousSibling(containing: UICollectionView.self, from: viewHost)
},
customize: customize
))
}
// MARK: Modifiers
func dynamicAccentColor(_ color: Color) -> some View {
modifier(DynamicAccentColor(color: color))
}
func conditionalId<ID: Hashable>(_ id: ID) -> some View {
modifier(ConditionalId(id: id))
}
func disabledAppearance(_ disabled: Bool, dimmedOpacity: Double? = nil, animation: Animation? = nil) -> some View {
modifier(DisabledAppearance(disabled: disabled, dimmedOpacity: dimmedOpacity, animation: animation))
}
func inlinedList() -> some View {
modifier(InlinedList())
}
func conditionalContextMenu<InternalContent: View, ID: Hashable>(
id: ID,
@ViewBuilder _ internalContent: @escaping () -> InternalContent
) -> some View {
modifier(ConditionalContextMenu(internalContent, id: id))
}
func dynamicActionSheet(
isPresented: Binding<Bool>,
title: String,
message: String? = nil,
buttons: [AlertButton]) -> some View
{
modifier(DynamicActionSheet(isPresented: isPresented, title: title, message: message, buttons: buttons))
}
func dynamicAlert(
isPresented: Binding<Bool>,
title: String,
message: String? = nil,
buttons: [AlertButton]) -> some View
{
modifier(DynamicAlert(isPresented: isPresented, title: title, message: message, buttons: buttons))
}
func disableInteraction(_ disabled: Bool) -> some View {
modifier(DisableInteraction(disabled: disabled))
}
}