PhaseAnimator
seems a good fit to play gifs in SwiftUI:
struct ContentView: View {
let frames = [UIImage(named: "frame-1")!, UIImage(named: "frame-2")!]
var body: some View {
PhaseAnimator(frames.indices) { index in
Image(uiImage: frames[index])
}
}
}
The problem is that by default, there's an opacity transition between phases. So I tried using transition(.identity)
:
Image(uiImage: gif[index])
.transition(.identity)
.id(index)
It doesn't work. It stays frozen on the first frame.
It does work if I set the transition to a small offset value:
Image(uiImage: gif[index])
.transition(.offset(x: 0, y: 0.1))
.id(index)
It does feel a bit hacky, though.
Is this the expected behavior for .transition(.identity)
, or is it a bug?