123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- import SwiftUI
- extension View {
- func complexModifier<V: View>(@ViewBuilder _ closure: (Self) -> V) -> some View {
- closure(self)
- }
-
-
- func frameForPreview() -> some View {
- return frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height)
- }
- func hiddenConditionally(isHidden: Bool) -> some View {
- isHidden ? AnyView(self.hidden()) : AnyView(self)
- }
-
-
-
-
-
- @ViewBuilder func `if`<Content: View>(_ condition: Bool, transform: (Self) -> Content) -> some View {
- if condition {
- transform(self)
- } else {
- self
- }
- }
- func onFirstAppear(perform action: @escaping () -> Void) -> some View {
- modifier(ViewFirstAppearModifier(perform: action))
- }
- }
- struct ViewFirstAppearModifier: ViewModifier {
- @State private var didAppearBefore = false
- private let action: () -> Void
- init(perform action: @escaping () -> Void) {
- self.action = action
- }
- func body(content: Content) -> some View {
- content.onAppear {
- guard !didAppearBefore else { return }
- didAppearBefore = true
- action()
- }
- }
- }
- var isRunningForPreviews: Bool {
- return ProcessInfo.processInfo.environment["XCODE_RUNNING_FOR_PREVIEWS"] == "1"
- }
|