Mijick / NavigationView

Navigation made simple (SwiftUI)
MIT License
238 stars 9 forks source link

About NavigationView conflicts with other libraries #50

Open ByLiangCheng opened 1 month ago

ByLiangCheng commented 1 month ago

Hello, when I use NavigationView 1.1.3 and https://github.com/guoyingtao/Mantis 2.21.0 at the same time, NavigationView will cause drag errors in Mantis

When NavigationView is not used:

https://github.com/user-attachments/assets/c1e6f753-5d4e-4e6a-a3a0-1f532e64df3b

After using NavigationView:

https://github.com/user-attachments/assets/5e823950-6e66-46af-998b-9747f62b8011

Code Sample:

import Mantis
import MijickNavigationView
import SwiftUI

@main
struct TestMantisDragApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .implementNavigationView()
                .preferredColorScheme(.light)
        }
    }
}

struct ContentView: NavigatableView {
    @State var image: UIImage? = UIImage(named: "EnglishImage")

    var body: some View {
        ImageCropper(image: $image)
            .ignoresSafeArea()
    }
}

#Preview {
    ContentView()
}

struct ImageCropper: UIViewControllerRepresentable {
    @Binding var image: UIImage?

    @Environment(\.presentationMode) var presentationMode

    class Coordinator: CropViewControllerDelegate {
        var parent: ImageCropper

        init(_ parent: ImageCropper) {
            self.parent = parent
        }

        func cropViewControllerDidCrop(_ cropViewController: Mantis.CropViewController, cropped: UIImage, transformation: Transformation, cropInfo: CropInfo) {
            parent.image = cropped
            print("transformation is \(transformation)")
            parent.presentationMode.wrappedValue.dismiss()
        }

        func cropViewControllerDidCancel(_ cropViewController: Mantis.CropViewController, original: UIImage) {
            parent.presentationMode.wrappedValue.dismiss()
        }
    }

    func makeCoordinator() -> Coordinator {
        Coordinator(self)
    }

    func makeUIViewController(context: Context) -> UIViewController {
        makeCustom(context: context)
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}

extension ImageCropper {
    func makeCustom(context: Context) -> UIViewController {
        var config = Mantis.Config()
        config.cropToolbarConfig.mode = .normal
        let cropViewController = Mantis.cropViewController(image: image!, config: config)
        return cropViewController
    }
}

Test image:

EnglishImage

Steps to reproduce:

When the line “.implementNavigationView()” is commented, it works fine. When it is added, the problem occurs

This problem does not appear when previewing with #Preview. I only discovered it when I was packaging the simulator or debugging on the real device. I am very confused now

FulcrumOne commented 1 month ago

Hey @ByLiangCheng,

I'll check it at the beginning of next week as I'm literally swamped with work this week

Sorry for this and have a good day!

ByLiangCheng commented 1 month ago

Thank you, don't worry, I found another solution. Now there is no problem in presenting the view corresponding to the Mantis library through fullScreenCover