Skip to content

Conversation

@vdeaugustine
Copy link

Overview

Refactor the GlowBorder ViewModifier implementation. By using @ViewBuilder and avoiding type erasure with AnyView, we achieve a cleaner, more efficient implementation.

Changes

  • Replaced the AnyView type erasure in GlowBorder with a generic Content parameter and @ViewBuilder.
  • Modified the applyShadow function to be recursive without the need for type erasure, thereby preserving the view's type throughout the modification process.
  • Maintains the original functionality of applying a glowing border effect but does so in a more SwiftUI-native approach.

Benefits

  • Performance: By avoiding AnyView, the view hierarchy remains more streamlined, potentially improving rendering performance as SwiftUI can better optimize the view diffing.
  • Type Safety: The use of generic Content and @ViewBuilder ensures that the view types are preserved, leveraging Swift's type system for compile-time checks.
  • Readability and Maintenance: The new approach is more in line with SwiftUI's idiomatic patterns, making the code easier to understand and maintain.

Refactor GlowBorder to use @ViewBuilder for improved performance and type safety
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant