Sunday, December 15, 2024
HomeiOS Developmentiphone - onDrag "lagging" concern in iOS 18

iphone – onDrag “lagging” concern in iOS 18


Has anybody else gotten a response from Apple or have run throughout an answer to onDrag lagging when launched to drop on iOS 18? I have been chasing this for per week pondering it was me after which I wakened and began testing it on older iOS variations and the problem goes away. I occurs on simulators and actual telephones. A little bit extra digging and I am seeing occasional chatter about this .5 to 1 second delay.

This is a code instance that reproduces it:

import SwiftUI
import UniformTypeIdentifiers

struct ContentView: View {
    @State non-public var draggableText: String = "Transfer this"

    var physique: some View {
        VStack(spacing: 80) {
            DraggableItem(content material: $draggableText)
            
            DropZone {
                Textual content("Place Right here!")
                    .font(.headline)
                    .foregroundColor(.white)
            }
            .body(width: 150, peak: 150)
            .background(Coloration.inexperienced)
            .cornerRadius(12)
        }
        .padding()
    }
}

struct DraggableItem: View {
    @Binding var content material: String

    var physique: some View {
        Textual content(content material)
            .body(width: 120, peak: 120)
            .background(Coloration.crimson)
            .foregroundColor(.white)
            .cornerRadius(8)
            .onDrag {
                NSItemProvider(object: NSString(string: content material))
            }
    }
}

struct DropZone: View {
    var content material: () -> Content material

    var physique: some View {
        ZStack {
            content material()
        }
        .onDrop(of: [UTType.text], delegate: DropHandler())
    }
}

struct DropHandler: DropDelegate {
    func performDrop(data: DropInfo) -> Bool {
        // Add logic to deal with the drop
        print("Merchandise dropped!")
        return true
    }
}

#Preview {
    ContentView()
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments