From 25670f3ed6f622d82f777bc6008b5c12cba75087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=81=E4=B8=9A=E5=8D=87?= Date: Sat, 29 May 2021 17:53:21 +0800 Subject: [PATCH] Add View+withPlaceholder.swift --- .../View/Utilities/View+withPlaceholder.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Source/Hollow/View/Utilities/View+withPlaceholder.swift diff --git a/Source/Hollow/View/Utilities/View+withPlaceholder.swift b/Source/Hollow/View/Utilities/View+withPlaceholder.swift new file mode 100644 index 00000000..d653c6fd --- /dev/null +++ b/Source/Hollow/View/Utilities/View+withPlaceholder.swift @@ -0,0 +1,17 @@ +// +// View+withPlaceholder.swift +// Hollow +// +// Created by liang2kl on 2021/5/29. +// Copyright © 2021 treehollow. All rights reserved. +// + +import SwiftUI + +extension View { + /// To hide the original view when used as source of `.matchedGeometryEffect()` + @ViewBuilder func withPlaceholder(_ hide: Bool, namespace: Namespace.ID?, id: HashableValue) -> some View { + if hide { self.opacity(0) } + else { self.conditionalMatchedGeometryEffect(id: id, in: namespace) } + } +}