Post

Replies

Boosts

Views

Activity

Combining asymmetric and modifier transitions
I'm trying to use a different version of view modifier when a view is inserted and when its being removed. However combining .asymmetric and .modifier transitions don't quite work as expected. Here's a test that attempts to print out the combination of states the view transitions between: struct TransitionPrinting: ViewModifier {  var isInsertion: Bool  var isActive: Bool     func body(content: Content) -> some View {   content    .onAppear {     print("isInsertion", isInsertion, "isActive", isActive)    }  } } struct ContentView: View {  @State var toggled = false  var body: some View {   VStack {         Toggle("Toggle", isOn: $toggled)         if toggled {     Text("Hello, world!")      .transition(       .asymmetric(        insertion: .modifier(         active: TransitionPrinting(isInsertion: true, isActive: true),         identity: TransitionPrinting(isInsertion: true, isActive: false)        ),        removal: .modifier(         active: TransitionPrinting(isInsertion: false, isActive: true),         identity: TransitionPrinting(isInsertion: false, isActive: false)        )       )      )    }         Spacer()   }   .padding()  } } When the above is run, I only see the following in the simulator (with 2 of the states missing): isInsertion true isActive true isInsertion false isActive false What's wrong here?
0
0
522
Jul ’22
Interpolating corner radius with matched geometry effect
In the following snippet, it's obvious that matched geometry effect is overlaying both views and crossfading between them. Is there a way to evenly animate the corner radius change? struct ContentView: View {  @State var toggled = false  @Namespace var namespace  var body: some View {   VStack(spacing: 16) {    Toggle("Toggle", isOn: $toggled.animation(.linear(duration: 5)))    if toggled {     RoundedRectangle(cornerRadius: 24, style: .continuous)      .fill(.red)      .matchedGeometryEffect(id: "box", in: namespace)      .frame(width: 200, height: 100)     Spacer()    } else {     Spacer()     RoundedRectangle(cornerRadius: 12, style: .continuous)      .fill(.blue)      .matchedGeometryEffect(id: "box", in: namespace)      .frame(width: 100, height: 200)    }   }   .padding(24)  } }
1
0
1.3k
Jun ’22
What's the best way to handle view controller teardowns in Swift 6?
Previously we could have some code in deinit that tears down local state: class ViewController: UIViewController { var displayLink: CADisplayLink? deinit { displayLink?.invalidate() } } However this doesn't work in Swift 6 because we cannot access property 'displayLink' with a non-sendable type 'CADisplayLink?' from non-isolated context in deinit. What's the right way to resolve this? Is the following a reasonable approach using Task to create an async context? deinit { Task { await MainActor.run { displayLink?.invalidate() } } }
0
2
843
Jun ’22
Changing the end point of an in-flight transition animation
It's generally pretty easy to change the end point of an in-flight animation for a view that's on-screen by repeatedly mutating state: withAnimation { state = ... } var body: some View { ... child .opacity(state) } For a subview that is being removed, using the .transition modifier we have one chance to setup the endpoint like this: disappearingChild .transition( .modifier(active: EndStateViewModifier(), identity: ...) ) struct EndStateViewModifier: ViewModifier { func body(content: Content) -> some View { content .opacity(0) } } Is it possible to change the end point mid way through the animation?
0
0
377
Jun ’22
Is there a way to turn off the new objc stubs optimizations in Xcode 14?
My app depends on some precompiled libraries that aren't built with Xcode 14 and I'm running into linker errors when building for device like the following: Undefined symbol: _objc_msgSend$CGColor Undefined symbol: _objc_msgSend$CGImage Undefined symbol: _objc_msgSend$CGPointValue Undefined symbol: _objc_msgSend$CGRectValue Undefined symbol: _objc_msgSend$CPUArchForCPUType:subType: Undefined symbol: _objc_msgSend$HTTPBody Undefined symbol: _objc_msgSend$HTTPCookieRepresentationForDomain: Undefined symbol: _objc_msgSend$HTTPHeaders Undefined symbol: _objc_msgSend$HTTPMaximumConnectionsPerHost Undefined symbol: _objc_msgSend$HTTPMethod Can I turn off this optimization?
4
0
2.9k
Jun ’22
Animating shadow path using UIViewPropertyAnimator
I'm trying to animate a layer's shadowPath property using UIViewPropertyAnimator but it looks like it's getting instantaneously set (instead of animating or being able to set the fraction complete on the animation.) Is there an alternative way to do this? view.layer.shadowPath = UIBezierPath(roundedRect: .init(origin: .zero, size: .init(width: 100, height: 100)), cornerRadius: 12).cgPath let animator = UIViewPropertyAnimator(duration: 2.0, curve: .easeInOut) { view.layer.shadowPath = UIBezierPath(roundedRect: .init(origin: .zero, size: .init(width: 200, height: 200)), cornerRadius: 12).cgPath } animator.scrubsLinearly = false animator.pauseAnimation() animator.fractionComplete = 0
Topic: UI Frameworks SubTopic: UIKit Tags:
1
0
968
Mar ’22
ScrollView positions content outside bounds
I'm trying to allow scrolling in both axes when the content is larger than the screen.``` var body: some View { ScrollView([.horizontal, .vertical]) { Rectangle() .foregroundColor(Color.red) .frame(width: 500, height: 500)}```1. The scroll view centers the content instead of beginning at the top-leading.2. When scrolled to the trailing edge there's some whitespace (similarly the content bleeds past the leading edge.)How do I fix the above issues?
2
0
3.3k
May ’20