nathantannar4 / Transmission

Bridges UIKit presentation APIs to a SwiftUI API so you can use presentation controllers, interactive transitions and more.
BSD 2-Clause "Simplified" License
378 stars 13 forks source link

Presentation scroll view detection conflicts with UITableView editing gesture #19

Open PhilipDukhov opened 9 months ago

PhilipDukhov commented 9 months ago

We don't like how onDrag behavior works, so switching to UITableView which looks much cleaner.

But table view reorder gesture gets interrupted by presentation scrolling detection

Sample:

struct ContentView: View {
    @State var visible = false

    var body: some View {
        Toggle("show sheet", isOn: $visible)
            .presentation(
                transition: .slide(
                    options: .init(
                        edge: .bottom,
                        prefersScaleEffect: true,
                        isInteractive: true,
                        options: .init(
                            shouldAutomaticallyDismissDestination: false,
                            modalPresentationCapturesStatusBarAppearance: true,
                            preferredPresentationBackgroundColor: .white
                        )
                    )
                ),
                isPresented: $visible
            ) {
                VStack {
                    UIList(editing: true)
                }
            }
    }

    struct UIList: UIViewRepresentable {
        let editing: Bool

        func makeUIView(context: Context) -> Table {
            Table()
        }

        func updateUIView(_ uiView: Table, context: Context) {
            uiView.set(editing: editing)
        }

        class Table: UITableView, UITableViewDelegate, UITableViewDataSource {
            init() {
                super.init(frame: .zero, style: .grouped)
                register(UITableViewCell.self, forCellReuseIdentifier: "id")
                delegate = self
                dataSource = self
                translatesAutoresizingMaskIntoConstraints = false
            }

            func set(editing: Bool) {
                setEditing(editing, animated: true)
            }

            required init?(coder: NSCoder) {
                fatalError("init(coder:) has not been implemented")
            }

            func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                10
            }

            func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                let cell = tableView.dequeueReusableCell(withIdentifier: "id", for: indexPath)
                cell.textLabel?.text = String(describing: indexPath)
                return cell
            }

            func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell.EditingStyle {
                .none
            }

            func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
                true
            }

            func tableView(_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {

            }
        }
    }
}
nathantannar4 commented 9 months ago

Fixed in 1.0.3

PhilipDukhov commented 3 hours ago

Hey @nathantannar4! The bug came back since 1.4.2, was working fine in 1.4.1.

You can reproduce it with the sample code from this question, could we reopen this issue?

Could we add UI tests that will run on CI? I think many use cases like this one should be easy to test. I can help you with the CI setup/writing tests!

nathantannar4 commented 2 hours ago

Sorry about that! Fixed again in 1.4.6. Yea I'd love to have CI and tests I just havent had the time to get that setup