Post

Replies

Boosts

Views

Activity

Color.clear the best way to draw an invisible view?
Sometimes we just want to use modifiers but don't have a view to draw to the screen, for example an .overlay {} modifier on a view needs a view inside it before you can add modifiers on to that overlay view. The current approach for this type of thing seems to be Color.clear and while I've seen this almost everywhere I'm not sure if this is a) the officially recommended way to do this in SwiftUI and b) the only way to do this in SwiftUI? I have the following custom view in my project just to avoid the explicit use of Color.clear import SwiftUI struct ClearView: View { var body: some View { Color.clear } } Are there any other ways to do this? Note - this is of course not the same as EmptyView() - where Color.clear renders a view with a transparent colour and EmptyView which doesn't render anything at all.
0
0
960
Mar ’24
SwiftUI symbol effects animate on scrolling list only when in Stack view
When: Embedding a Image with a symbol effect in a stack view in SwiftUI, and putting this in a List Actual: The symbols animate when scrolling that item in and out of the view Expected: The symbol doesn't animate until the value changes. I have the following code which is boiled down from my actual code where the animating value is a @Model object property (other animations work fine when their animation's value is watching the same property.) I've boiled it down to the below examples: The top example works as expected (no symbol animations on scroll) The bottom example animates the symbols every time they scroll in to view #Preview { VStack { List { ForEach(1...100, id: \.self) { index in Image(systemName: "square.3.layers.3d") .symbolEffect(.bounce, value: index) } } List { ForEach(1...100, id: \.self) { index in HStack { Image(systemName: "square.3.layers.3d") .symbolEffect(.bounce, value: index) } } } } } This happens on Mac and iOS. I'm running Xcode 15.3 RC2 but it also happens in Xcode 15.2 I've found this will happen whether embedding in a HStack, VStack or ZStack but seems fine in a Group. I've tried adding a id() modifier to the HStack to give it an explicit identifier but this doesn't seem to work. Is there something I'm missing here?
1
0
1.2k
Mar ’24
Color.clear the best way to draw an invisible view?
Sometimes we just want to use modifiers but don't have a view to draw to the screen, for example an .overlay {} modifier on a view needs a view inside it before you can add modifiers on to that overlay view. The current approach for this type of thing seems to be Color.clear and while I've seen this almost everywhere I'm not sure if this is a) the officially recommended way to do this in SwiftUI and b) the only way to do this in SwiftUI? I have the following custom view in my project just to avoid the explicit use of Color.clear import SwiftUI struct ClearView: View { var body: some View { Color.clear } } Are there any other ways to do this? Note - this is of course not the same as EmptyView() - where Color.clear renders a view with a transparent colour and EmptyView which doesn't render anything at all.
Replies
0
Boosts
0
Views
960
Activity
Mar ’24
SwiftUI symbol effects animate on scrolling list only when in Stack view
When: Embedding a Image with a symbol effect in a stack view in SwiftUI, and putting this in a List Actual: The symbols animate when scrolling that item in and out of the view Expected: The symbol doesn't animate until the value changes. I have the following code which is boiled down from my actual code where the animating value is a @Model object property (other animations work fine when their animation's value is watching the same property.) I've boiled it down to the below examples: The top example works as expected (no symbol animations on scroll) The bottom example animates the symbols every time they scroll in to view #Preview { VStack { List { ForEach(1...100, id: \.self) { index in Image(systemName: "square.3.layers.3d") .symbolEffect(.bounce, value: index) } } List { ForEach(1...100, id: \.self) { index in HStack { Image(systemName: "square.3.layers.3d") .symbolEffect(.bounce, value: index) } } } } } This happens on Mac and iOS. I'm running Xcode 15.3 RC2 but it also happens in Xcode 15.2 I've found this will happen whether embedding in a HStack, VStack or ZStack but seems fine in a Group. I've tried adding a id() modifier to the HStack to give it an explicit identifier but this doesn't seem to work. Is there something I'm missing here?
Replies
1
Boosts
0
Views
1.2k
Activity
Mar ’24