airbnb / lottie-ios

An iOS library to natively render After Effects vector animations
http://airbnb.io/lottie/
Apache License 2.0
25.7k stars 3.74k forks source link

SwiftUI LottieView disappears when previewing preview with contextMenu #2354

Closed chuymaster closed 6 months ago

chuymaster commented 6 months ago

When using contextMenu with preview, if I long-press to open the context menu, Lottie view disappears, causing glitch in view transition.

Refer to the video:

https://github.com/airbnb/lottie-ios/assets/8290104/69aef245-2f0b-4823-8ba3-bea47081d610

Reproducing code, tested on iOS 17.2 simulator. (Confirmed same behavior on iPhone 15 iOS 17.4)

import SwiftUI
import Lottie

struct ContentView: View {
    var body: some View {
        VStack {
            Text("Normal Context Menu")
            LottieView(animation: .named("animation"))
                .looping()
                .contextMenu(menuItems: {
                    Text("Menu Item 1")
                    Text("Menu Item 2")
                    Text("Menu Item 3")
                })
            Text("Context Menu with Preview")
            LottieView(animation: .named("animation"))
                .looping()
                .contextMenu(menuItems: {
                    Text("Menu Item 1")
                    Text("Menu Item 2")
                    Text("Menu Item 3")
                }) {
                    Text("Context Menu Preview")
                }
        }
        .padding()
        .background(Color.gray.opacity(0.1))
    }
}

Which Version of Lottie are you using?

Lottie 4.4.1

Expected Behavior

LottieView keeps running animation during long-press and after the preview is closed, as in the context menu that has no preview.

Actual Behavior

LottieView disappears during long-press and after the preview is closed for a short period.

Animation JSON

https://lottiefiles.com/animations/sample-ac0sBj9eCw