Created
May 3, 2023 23:00
-
-
Save pmark/0953b4619d825d7450cd37505efc9e01 to your computer and use it in GitHub Desktop.
RenderCounterModifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
USAGE | |
someView.renderCounter() | |
*/ | |
import SwiftUI | |
struct RenderCounterModifier: ViewModifier { | |
@State private var renderCount: Int = 0 | |
func body(content: Content) -> some View { | |
content | |
.onAppear { | |
renderCount += 1 | |
} | |
.overlay( | |
Text("Rendered: \(renderCount)") | |
.font(.system(size: 10)) | |
.foregroundColor(.red) | |
.padding(4) | |
.background(Color.white.opacity(0.8)) | |
.cornerRadius(5) | |
.padding(4), | |
alignment: .topTrailing | |
) | |
} | |
} | |
extension View { | |
func renderCounter() -> some View { | |
self.modifier(RenderCounterModifier()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment