markiv / SwiftUI-Shimmer

Shimmer is a super-light modifier that adds a shimmering effect to any SwiftUI View, for example, to show that an operation is in progress. It works well on light and dark modes, and across iOS, macOS, tvOS, watchOS and visionOS.
MIT License
1.04k stars 60 forks source link

fix: Remove IfElse To Keep State Correct #18

Open vladyslavsosiuk opened 8 months ago

vladyslavsosiuk commented 8 months ago

Refs: #12

This PR addresses the SwiftUI identification issue. When a view to which the shimmering modifier is applied has its own state and toggles between shimmering active true or false the view would lose its state. Here's a video representing the issue:

https://github.com/markiv/SwiftUI-Shimmer/assets/24592433/d9502996-7b56-4c16-87e0-a145debef83a

Here is a video with the expected behavior:

https://github.com/markiv/SwiftUI-Shimmer/assets/24592433/75e6ca78-36e0-4eff-91f1-a0ab2f05f80b

why is this an issue described in the following article: https://www.objc.io/blog/2021/08/24/conditional-view-modifiers/

lbunicic commented 7 months ago

Thanks for this @vladyslavsosiuk. It's a critical issue imo, let's hope it gets merged sometime soon.

SoKamil commented 7 months ago

Did you notice that on the video with expected behavior part of the toggle button on the right is cut off?

vladyslavsosiuk commented 7 months ago

Did you notice that on the video with expected behavior part of the toggle button on the right is cut off?

Yes, it's just a preview