Skip to content

Instantly share code, notes, and snippets.

@andrew-levy
Created January 27, 2025 00:26
Show Gist options
  • Save andrew-levy/98030368559f73a2e61c82b15ce7a9ef to your computer and use it in GitHub Desktop.
Save andrew-levy/98030368559f73a2e61c82b15ce7a9ef to your computer and use it in GitHub Desktop.
import ExpoModulesCore
import SwiftUI
class DraggableProps: ExpoSwiftUI.ViewProps {
@Field var text: String
}
struct DraggableView: ExpoSwiftUI.View {
@EnvironmentObject var props: DraggableProps
var body: some View {
if #available(iOS 16.0, *) {
Children().draggable(props.text)
} else {
Children()
}
}
}
class DropDestinationProps: ExpoSwiftUI.ViewProps {
var onDrop = EventDispatcher()
}
struct DropDestinationView: ExpoSwiftUI.View {
@EnvironmentObject var props: DropDestinationProps
var body: some View {
if #available(iOS 16.0, *) {
Children()
.dropDestination(for: String.self) { items, location in
props.onDrop(["onDrop": items.first ?? ""])
return true
}
} else {
EmptyView()
}
}
}
@Innei
Copy link

Innei commented Jan 28, 2025

Thank you for sharing.

But could you share how to write the entry of an expo module? Thank you.

@andrew-levy
Copy link
Author

@Innei Is this what you're asking about?

import ExpoModulesCore

public class DraggableModule: Module {
  public func definition() -> ModuleDefinition {
    Name("Draggable")
    View(DraggableView.self)
  }
}


public class DropDestinationModule: Module {
  public func definition() -> ModuleDefinition {
    Name("DropDestination")
    Events("onDrop")
    View(DropDestinationView.self)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment