Created
January 27, 2025 00:26
-
-
Save andrew-levy/98030368559f73a2e61c82b15ce7a9ef to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 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
Thank you for sharing.
But could you share how to write the entry of an expo module? Thank you.