├── .gitignore ├── .swiftpm └── xcode │ └── package.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ └── IDEWorkspaceChecks.plist ├── ExampleApp ├── SampleDragDrop.xcodeproj │ ├── project.pbxproj │ └── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ ├── IDEWorkspaceChecks.plist │ │ └── swiftpm │ │ └── Package.resolved └── SampleDragDrop │ ├── AppDelegate.swift │ ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json │ ├── Base.lproj │ └── LaunchScreen.storyboard │ ├── ContentView.swift │ ├── Info.plist │ ├── Preview Content │ └── Preview Assets.xcassets │ │ └── Contents.json │ └── SceneDelegate.swift ├── LICENSE ├── Package.swift ├── README.md ├── Sources └── DragDrop │ ├── Drag │ ├── DragElementModifier.swift │ ├── DraggableView.swift │ └── View+Draggable.swift │ ├── DragDropManager │ └── DragNDropManager.swift │ ├── Drop │ ├── DropContainer.swift │ ├── DropContainerModifier.swift │ └── View+Droppable.swift │ └── InteractiveContainer.swift └── Tests ├── DragDropTests ├── DragDropTests.swift └── XCTestManifests.swift └── LinuxMain.swift /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xccheckout 23 | *.xcscmblueprint 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | # Package.pins 40 | # Package.resolved 41 | .build/ 42 | 43 | # CocoaPods 44 | # 45 | # We recommend against adding the Pods directory to your .gitignore. However 46 | # you should judge for yourself, the pros and cons are mentioned at: 47 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 48 | # 49 | # Pods/ 50 | 51 | # Carthage 52 | # 53 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 54 | # Carthage/Checkouts 55 | 56 | Carthage/Build 57 | 58 | # fastlane 59 | # 60 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 61 | # screenshots whenever they are needed. 62 | # For more information about the recommended setup visit: 63 | # https://docs.fastlane.tools/best-practices/source-control/#source-control 64 | 65 | fastlane/report.xml 66 | fastlane/Preview.html 67 | fastlane/screenshots/**/*.png 68 | fastlane/test_output 69 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.swiftpm/xcode/package.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 52; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 87480ACE22DE0F0100588A9E /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87480ACD22DE0F0100588A9E /* AppDelegate.swift */; }; 11 | 87480AD022DE0F0100588A9E /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87480ACF22DE0F0100588A9E /* SceneDelegate.swift */; }; 12 | 87480AD222DE0F0100588A9E /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 87480AD122DE0F0100588A9E /* ContentView.swift */; }; 13 | 87480AD422DE0F0200588A9E /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 87480AD322DE0F0200588A9E /* Assets.xcassets */; }; 14 | 87480AD722DE0F0200588A9E /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 87480AD622DE0F0200588A9E /* Preview Assets.xcassets */; }; 15 | 87480ADA22DE0F0200588A9E /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 87480AD822DE0F0200588A9E /* LaunchScreen.storyboard */; }; 16 | 87480AE322DE112100588A9E /* DragDrop in Frameworks */ = {isa = PBXBuildFile; productRef = 87480AE222DE112100588A9E /* DragDrop */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | 87480ACA22DE0F0100588A9E /* SampleDragDrop.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SampleDragDrop.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 87480ACD22DE0F0100588A9E /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | 87480ACF22DE0F0100588A9E /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 23 | 87480AD122DE0F0100588A9E /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 24 | 87480AD322DE0F0200588A9E /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 87480AD622DE0F0200588A9E /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 26 | 87480AD922DE0F0200588A9E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 27 | 87480ADB22DE0F0200588A9E /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 28 | /* End PBXFileReference section */ 29 | 30 | /* Begin PBXFrameworksBuildPhase section */ 31 | 87480AC722DE0F0100588A9E /* Frameworks */ = { 32 | isa = PBXFrameworksBuildPhase; 33 | buildActionMask = 2147483647; 34 | files = ( 35 | 87480AE322DE112100588A9E /* DragDrop in Frameworks */, 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | 87480AC122DE0F0100588A9E = { 43 | isa = PBXGroup; 44 | children = ( 45 | 87480ACC22DE0F0100588A9E /* SampleDragDrop */, 46 | 87480ACB22DE0F0100588A9E /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | 87480ACB22DE0F0100588A9E /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | 87480ACA22DE0F0100588A9E /* SampleDragDrop.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | 87480ACC22DE0F0100588A9E /* SampleDragDrop */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | 87480ACD22DE0F0100588A9E /* AppDelegate.swift */, 62 | 87480ACF22DE0F0100588A9E /* SceneDelegate.swift */, 63 | 87480AD122DE0F0100588A9E /* ContentView.swift */, 64 | 87480AD322DE0F0200588A9E /* Assets.xcassets */, 65 | 87480AD822DE0F0200588A9E /* LaunchScreen.storyboard */, 66 | 87480ADB22DE0F0200588A9E /* Info.plist */, 67 | 87480AD522DE0F0200588A9E /* Preview Content */, 68 | ); 69 | path = SampleDragDrop; 70 | sourceTree = ""; 71 | }; 72 | 87480AD522DE0F0200588A9E /* Preview Content */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | 87480AD622DE0F0200588A9E /* Preview Assets.xcassets */, 76 | ); 77 | path = "Preview Content"; 78 | sourceTree = ""; 79 | }; 80 | /* End PBXGroup section */ 81 | 82 | /* Begin PBXNativeTarget section */ 83 | 87480AC922DE0F0100588A9E /* SampleDragDrop */ = { 84 | isa = PBXNativeTarget; 85 | buildConfigurationList = 87480ADE22DE0F0200588A9E /* Build configuration list for PBXNativeTarget "SampleDragDrop" */; 86 | buildPhases = ( 87 | 87480AC622DE0F0100588A9E /* Sources */, 88 | 87480AC722DE0F0100588A9E /* Frameworks */, 89 | 87480AC822DE0F0100588A9E /* Resources */, 90 | ); 91 | buildRules = ( 92 | ); 93 | dependencies = ( 94 | 8713C48622DE15D400B53C94 /* PBXTargetDependency */, 95 | ); 96 | name = SampleDragDrop; 97 | packageProductDependencies = ( 98 | 87480AE222DE112100588A9E /* DragDrop */, 99 | ); 100 | productName = SampleDragDrop; 101 | productReference = 87480ACA22DE0F0100588A9E /* SampleDragDrop.app */; 102 | productType = "com.apple.product-type.application"; 103 | }; 104 | /* End PBXNativeTarget section */ 105 | 106 | /* Begin PBXProject section */ 107 | 87480AC222DE0F0100588A9E /* Project object */ = { 108 | isa = PBXProject; 109 | attributes = { 110 | LastSwiftUpdateCheck = 1100; 111 | LastUpgradeCheck = 1100; 112 | ORGANIZATIONNAME = Bilescky; 113 | TargetAttributes = { 114 | 87480AC922DE0F0100588A9E = { 115 | CreatedOnToolsVersion = 11.0; 116 | }; 117 | }; 118 | }; 119 | buildConfigurationList = 87480AC522DE0F0100588A9E /* Build configuration list for PBXProject "SampleDragDrop" */; 120 | compatibilityVersion = "Xcode 9.3"; 121 | developmentRegion = en; 122 | hasScannedForEncodings = 0; 123 | knownRegions = ( 124 | en, 125 | Base, 126 | ); 127 | mainGroup = 87480AC122DE0F0100588A9E; 128 | packageReferences = ( 129 | 87480AE122DE112100588A9E /* XCRemoteSwiftPackageReference "SwiftUIDragDrop" */, 130 | ); 131 | productRefGroup = 87480ACB22DE0F0100588A9E /* Products */; 132 | projectDirPath = ""; 133 | projectRoot = ""; 134 | targets = ( 135 | 87480AC922DE0F0100588A9E /* SampleDragDrop */, 136 | ); 137 | }; 138 | /* End PBXProject section */ 139 | 140 | /* Begin PBXResourcesBuildPhase section */ 141 | 87480AC822DE0F0100588A9E /* Resources */ = { 142 | isa = PBXResourcesBuildPhase; 143 | buildActionMask = 2147483647; 144 | files = ( 145 | 87480ADA22DE0F0200588A9E /* LaunchScreen.storyboard in Resources */, 146 | 87480AD722DE0F0200588A9E /* Preview Assets.xcassets in Resources */, 147 | 87480AD422DE0F0200588A9E /* Assets.xcassets in Resources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXResourcesBuildPhase section */ 152 | 153 | /* Begin PBXSourcesBuildPhase section */ 154 | 87480AC622DE0F0100588A9E /* Sources */ = { 155 | isa = PBXSourcesBuildPhase; 156 | buildActionMask = 2147483647; 157 | files = ( 158 | 87480ACE22DE0F0100588A9E /* AppDelegate.swift in Sources */, 159 | 87480AD022DE0F0100588A9E /* SceneDelegate.swift in Sources */, 160 | 87480AD222DE0F0100588A9E /* ContentView.swift in Sources */, 161 | ); 162 | runOnlyForDeploymentPostprocessing = 0; 163 | }; 164 | /* End PBXSourcesBuildPhase section */ 165 | 166 | /* Begin PBXTargetDependency section */ 167 | 8713C48622DE15D400B53C94 /* PBXTargetDependency */ = { 168 | isa = PBXTargetDependency; 169 | productRef = 8713C48522DE15D400B53C94 /* DragDrop */; 170 | }; 171 | /* End PBXTargetDependency section */ 172 | 173 | /* Begin PBXVariantGroup section */ 174 | 87480AD822DE0F0200588A9E /* LaunchScreen.storyboard */ = { 175 | isa = PBXVariantGroup; 176 | children = ( 177 | 87480AD922DE0F0200588A9E /* Base */, 178 | ); 179 | name = LaunchScreen.storyboard; 180 | sourceTree = ""; 181 | }; 182 | /* End PBXVariantGroup section */ 183 | 184 | /* Begin XCBuildConfiguration section */ 185 | 87480ADC22DE0F0200588A9E /* Debug */ = { 186 | isa = XCBuildConfiguration; 187 | buildSettings = { 188 | ALWAYS_SEARCH_USER_PATHS = NO; 189 | CLANG_ANALYZER_NONNULL = YES; 190 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 191 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 192 | CLANG_CXX_LIBRARY = "libc++"; 193 | CLANG_ENABLE_MODULES = YES; 194 | CLANG_ENABLE_OBJC_ARC = YES; 195 | CLANG_ENABLE_OBJC_WEAK = YES; 196 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 197 | CLANG_WARN_BOOL_CONVERSION = YES; 198 | CLANG_WARN_COMMA = YES; 199 | CLANG_WARN_CONSTANT_CONVERSION = YES; 200 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 201 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 202 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 203 | CLANG_WARN_EMPTY_BODY = YES; 204 | CLANG_WARN_ENUM_CONVERSION = YES; 205 | CLANG_WARN_INFINITE_RECURSION = YES; 206 | CLANG_WARN_INT_CONVERSION = YES; 207 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 208 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 209 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 210 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 211 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 212 | CLANG_WARN_STRICT_PROTOTYPES = YES; 213 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 214 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 215 | CLANG_WARN_UNREACHABLE_CODE = YES; 216 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 217 | COPY_PHASE_STRIP = NO; 218 | DEBUG_INFORMATION_FORMAT = dwarf; 219 | ENABLE_STRICT_OBJC_MSGSEND = YES; 220 | ENABLE_TESTABILITY = YES; 221 | GCC_C_LANGUAGE_STANDARD = gnu11; 222 | GCC_DYNAMIC_NO_PIC = NO; 223 | GCC_NO_COMMON_BLOCKS = YES; 224 | GCC_OPTIMIZATION_LEVEL = 0; 225 | GCC_PREPROCESSOR_DEFINITIONS = ( 226 | "DEBUG=1", 227 | "$(inherited)", 228 | ); 229 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 230 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 231 | GCC_WARN_UNDECLARED_SELECTOR = YES; 232 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 233 | GCC_WARN_UNUSED_FUNCTION = YES; 234 | GCC_WARN_UNUSED_VARIABLE = YES; 235 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 236 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 237 | MTL_FAST_MATH = YES; 238 | ONLY_ACTIVE_ARCH = YES; 239 | SDKROOT = iphoneos; 240 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 241 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 242 | }; 243 | name = Debug; 244 | }; 245 | 87480ADD22DE0F0200588A9E /* Release */ = { 246 | isa = XCBuildConfiguration; 247 | buildSettings = { 248 | ALWAYS_SEARCH_USER_PATHS = NO; 249 | CLANG_ANALYZER_NONNULL = YES; 250 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 251 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 252 | CLANG_CXX_LIBRARY = "libc++"; 253 | CLANG_ENABLE_MODULES = YES; 254 | CLANG_ENABLE_OBJC_ARC = YES; 255 | CLANG_ENABLE_OBJC_WEAK = YES; 256 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 257 | CLANG_WARN_BOOL_CONVERSION = YES; 258 | CLANG_WARN_COMMA = YES; 259 | CLANG_WARN_CONSTANT_CONVERSION = YES; 260 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 261 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 262 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 263 | CLANG_WARN_EMPTY_BODY = YES; 264 | CLANG_WARN_ENUM_CONVERSION = YES; 265 | CLANG_WARN_INFINITE_RECURSION = YES; 266 | CLANG_WARN_INT_CONVERSION = YES; 267 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 268 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 269 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 270 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 271 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 272 | CLANG_WARN_STRICT_PROTOTYPES = YES; 273 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 274 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 275 | CLANG_WARN_UNREACHABLE_CODE = YES; 276 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 277 | COPY_PHASE_STRIP = NO; 278 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 279 | ENABLE_NS_ASSERTIONS = NO; 280 | ENABLE_STRICT_OBJC_MSGSEND = YES; 281 | GCC_C_LANGUAGE_STANDARD = gnu11; 282 | GCC_NO_COMMON_BLOCKS = YES; 283 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 284 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 285 | GCC_WARN_UNDECLARED_SELECTOR = YES; 286 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 287 | GCC_WARN_UNUSED_FUNCTION = YES; 288 | GCC_WARN_UNUSED_VARIABLE = YES; 289 | IPHONEOS_DEPLOYMENT_TARGET = 13.0; 290 | MTL_ENABLE_DEBUG_INFO = NO; 291 | MTL_FAST_MATH = YES; 292 | SDKROOT = iphoneos; 293 | SWIFT_COMPILATION_MODE = wholemodule; 294 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 295 | VALIDATE_PRODUCT = YES; 296 | }; 297 | name = Release; 298 | }; 299 | 87480ADF22DE0F0200588A9E /* Debug */ = { 300 | isa = XCBuildConfiguration; 301 | buildSettings = { 302 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 303 | CODE_SIGN_STYLE = Automatic; 304 | DEVELOPMENT_ASSET_PATHS = "SampleDragDrop/Preview\\ Content"; 305 | DEVELOPMENT_TEAM = Y5TK33KLVG; 306 | ENABLE_PREVIEWS = YES; 307 | INFOPLIST_FILE = SampleDragDrop/Info.plist; 308 | LD_RUNPATH_SEARCH_PATHS = ( 309 | "$(inherited)", 310 | "@executable_path/Frameworks", 311 | ); 312 | PRODUCT_BUNDLE_IDENTIFIER = com.bgondim.SampleDragDrop; 313 | PRODUCT_NAME = "$(TARGET_NAME)"; 314 | SWIFT_VERSION = 5.0; 315 | TARGETED_DEVICE_FAMILY = 1; 316 | }; 317 | name = Debug; 318 | }; 319 | 87480AE022DE0F0200588A9E /* Release */ = { 320 | isa = XCBuildConfiguration; 321 | buildSettings = { 322 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 323 | CODE_SIGN_STYLE = Automatic; 324 | DEVELOPMENT_ASSET_PATHS = "SampleDragDrop/Preview\\ Content"; 325 | DEVELOPMENT_TEAM = Y5TK33KLVG; 326 | ENABLE_PREVIEWS = YES; 327 | INFOPLIST_FILE = SampleDragDrop/Info.plist; 328 | LD_RUNPATH_SEARCH_PATHS = ( 329 | "$(inherited)", 330 | "@executable_path/Frameworks", 331 | ); 332 | PRODUCT_BUNDLE_IDENTIFIER = com.bgondim.SampleDragDrop; 333 | PRODUCT_NAME = "$(TARGET_NAME)"; 334 | SWIFT_VERSION = 5.0; 335 | TARGETED_DEVICE_FAMILY = 1; 336 | }; 337 | name = Release; 338 | }; 339 | /* End XCBuildConfiguration section */ 340 | 341 | /* Begin XCConfigurationList section */ 342 | 87480AC522DE0F0100588A9E /* Build configuration list for PBXProject "SampleDragDrop" */ = { 343 | isa = XCConfigurationList; 344 | buildConfigurations = ( 345 | 87480ADC22DE0F0200588A9E /* Debug */, 346 | 87480ADD22DE0F0200588A9E /* Release */, 347 | ); 348 | defaultConfigurationIsVisible = 0; 349 | defaultConfigurationName = Release; 350 | }; 351 | 87480ADE22DE0F0200588A9E /* Build configuration list for PBXNativeTarget "SampleDragDrop" */ = { 352 | isa = XCConfigurationList; 353 | buildConfigurations = ( 354 | 87480ADF22DE0F0200588A9E /* Debug */, 355 | 87480AE022DE0F0200588A9E /* Release */, 356 | ); 357 | defaultConfigurationIsVisible = 0; 358 | defaultConfigurationName = Release; 359 | }; 360 | /* End XCConfigurationList section */ 361 | 362 | /* Begin XCRemoteSwiftPackageReference section */ 363 | 87480AE122DE112100588A9E /* XCRemoteSwiftPackageReference "SwiftUIDragDrop" */ = { 364 | isa = XCRemoteSwiftPackageReference; 365 | repositoryURL = "https://github.com/brunogb/SwiftUIDragDrop"; 366 | requirement = { 367 | branch = master; 368 | kind = branch; 369 | }; 370 | }; 371 | /* End XCRemoteSwiftPackageReference section */ 372 | 373 | /* Begin XCSwiftPackageProductDependency section */ 374 | 8713C48522DE15D400B53C94 /* DragDrop */ = { 375 | isa = XCSwiftPackageProductDependency; 376 | package = 87480AE122DE112100588A9E /* XCRemoteSwiftPackageReference "SwiftUIDragDrop" */; 377 | productName = DragDrop; 378 | }; 379 | 87480AE222DE112100588A9E /* DragDrop */ = { 380 | isa = XCSwiftPackageProductDependency; 381 | package = 87480AE122DE112100588A9E /* XCRemoteSwiftPackageReference "SwiftUIDragDrop" */; 382 | productName = DragDrop; 383 | }; 384 | /* End XCSwiftPackageProductDependency section */ 385 | }; 386 | rootObject = 87480AC222DE0F0100588A9E /* Project object */; 387 | } 388 | -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved: -------------------------------------------------------------------------------- 1 | { 2 | "object": { 3 | "pins": [ 4 | { 5 | "package": "DragDrop", 6 | "repositoryURL": "https://github.com/brunogb/SwiftUIDragDrop", 7 | "state": { 8 | "branch": "master", 9 | "revision": "283f3ff02d07d811ff20509cd8c2e6922e99c577", 10 | "version": null 11 | } 12 | } 13 | ] 14 | }, 15 | "version": 1 16 | } 17 | -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SampleDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 17 | // Override point for customization after application launch. 18 | return true 19 | } 20 | 21 | // MARK: UISceneSession Lifecycle 22 | 23 | func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { 24 | // Called when a new scene session is being created. 25 | // Use this method to select a configuration to create the new scene with. 26 | return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) 27 | } 28 | 29 | func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { 30 | // Called when the user discards a scene session. 31 | // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. 32 | // Use this method to release any resources that were specific to the discarded scenes, as they will not return. 33 | } 34 | 35 | 36 | } 37 | 38 | -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop/ContentView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ContentView.swift 3 | // SampleDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | import DragDrop 11 | 12 | //struct ContentView : View { 13 | // 14 | // let container1ID = UUID() 15 | // let container2ID = UUID() 16 | // let dragID = UUID() 17 | // 18 | // var body: some View { 19 | // EmptyView() 20 | // } 21 | //} 22 | 23 | struct ContentView : View { 24 | 25 | let container1ID = UUID() 26 | let container2ID = UUID() 27 | let dragID = UUID() 28 | 29 | var body: some View { 30 | InteractiveContainer { 31 | VStack { 32 | DropContainer(id: container1ID) { canDrop in 33 | VStack { 34 | Text( canDrop ? "Drop view here": "You cant drop here") 35 | } 36 | .padding() 37 | .background(canDrop ? Color.yellow : Color.blue) 38 | } 39 | Spacer() 40 | .frame(height: 100) 41 | DropContainer(id: container2ID) { canDrop in 42 | VStack { 43 | Text( canDrop ? "Drop view here": "You cant drop here") 44 | } 45 | .padding() 46 | .background(canDrop ? Color.yellow : Color.green) 47 | } 48 | Spacer() 49 | .frame(height: 100) 50 | DraggableView(id: dragID) { dragInfo in 51 | HStack { 52 | Text("Drag me") 53 | } 54 | .padding() 55 | .background( dragInfo.isDragging ? Color.red : Color.white) 56 | } 57 | } 58 | } 59 | } 60 | } 61 | 62 | #if DEBUG 63 | struct ContentView_Previews : PreviewProvider { 64 | static var previews: some View { 65 | ContentView() 66 | } 67 | } 68 | #endif 69 | -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | $(PRODUCT_BUNDLE_PACKAGE_TYPE) 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UIApplicationSceneManifest 24 | 25 | UIApplicationSupportsMultipleScenes 26 | 27 | UISceneConfigurations 28 | 29 | UIWindowSceneSessionRoleApplication 30 | 31 | 32 | UILaunchStoryboardName 33 | LaunchScreen 34 | UISceneConfigurationName 35 | Default Configuration 36 | UISceneDelegateClassName 37 | $(PRODUCT_MODULE_NAME).SceneDelegate 38 | 39 | 40 | 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UISupportedInterfaceOrientations~ipad 55 | 56 | UIInterfaceOrientationPortrait 57 | UIInterfaceOrientationPortraitUpsideDown 58 | UIInterfaceOrientationLandscapeLeft 59 | UIInterfaceOrientationLandscapeRight 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop/Preview Content/Preview Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ExampleApp/SampleDragDrop/SceneDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SceneDelegate.swift 3 | // SampleDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import SwiftUI 11 | 12 | class SceneDelegate: UIResponder, UIWindowSceneDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { 18 | // Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`. 19 | // If using a storyboard, the `window` property will automatically be initialized and attached to the scene. 20 | // This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead). 21 | 22 | // Use a UIHostingController as window root view controller 23 | if let windowScene = scene as? UIWindowScene { 24 | let window = UIWindow(windowScene: windowScene) 25 | window.rootViewController = UIHostingController(rootView: ContentView()) 26 | self.window = window 27 | window.makeKeyAndVisible() 28 | } 29 | } 30 | 31 | func sceneDidDisconnect(_ scene: UIScene) { 32 | // Called as the scene is being released by the system. 33 | // This occurs shortly after the scene enters the background, or when its session is discarded. 34 | // Release any resources associated with this scene that can be re-created the next time the scene connects. 35 | // The scene may re-connect later, as its session was not neccessarily discarded (see `application:didDiscardSceneSessions` instead). 36 | } 37 | 38 | func sceneDidBecomeActive(_ scene: UIScene) { 39 | // Called when the scene has moved from an inactive state to an active state. 40 | // Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. 41 | } 42 | 43 | func sceneWillResignActive(_ scene: UIScene) { 44 | // Called when the scene will move from an active state to an inactive state. 45 | // This may occur due to temporary interruptions (ex. an incoming phone call). 46 | } 47 | 48 | func sceneWillEnterForeground(_ scene: UIScene) { 49 | // Called as the scene transitions from the background to the foreground. 50 | // Use this method to undo the changes made on entering the background. 51 | } 52 | 53 | func sceneDidEnterBackground(_ scene: UIScene) { 54 | // Called as the scene transitions from the foreground to the background. 55 | // Use this method to save data, release shared resources, and store enough scene-specific state information 56 | // to restore the scene back to its current state. 57 | } 58 | 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Bruno Bilescky 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:5.1 2 | // The swift-tools-version declares the minimum version of Swift required to build this package. 3 | 4 | import PackageDescription 5 | 6 | let package = Package( 7 | name: "DragDrop", 8 | platforms: [ 9 | .iOS(.v13) 10 | ], 11 | products: [ 12 | // Products define the executables and libraries produced by a package, and make them visible to other packages. 13 | .library( 14 | name: "DragDrop", 15 | targets: ["DragDrop"]), 16 | ], 17 | dependencies: [ 18 | // Dependencies declare other packages that this package depends on. 19 | // .package(url: /* package url */, from: "1.0.0"), 20 | ], 21 | targets: [ 22 | // Targets are the basic building blocks of a package. A target can define a module or a test suite. 23 | // Targets can depend on other targets in this package, and on products in packages which this package depends on. 24 | .target( 25 | name: "DragDrop", 26 | dependencies: []), 27 | .testTarget( 28 | name: "DragDropTests", 29 | dependencies: ["DragDrop"]), 30 | ] 31 | ) 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DragDrop 2 | 3 | A description of this package. 4 | -------------------------------------------------------------------------------- /Sources/DragDrop/Drag/DragElementModifier.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DragElementModifier.swift 3 | // SwiftUIDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | public struct DragElementModifier: ViewModifier { 12 | 13 | @EnvironmentObject var manager: DragNDropManager 14 | public let elementId: UUID 15 | 16 | public func body(content: Content) -> some View { 17 | return content 18 | .overlay(GeometryReader { r in 19 | Color.clear 20 | .onAppear { 21 | self.manager.registerFor(drag: self.elementId, frame: r.frame(in: .global)) 22 | } 23 | }) 24 | .gesture(DragGesture(coordinateSpace: .global).onChanged({ (value) in 25 | self.manager.report(drag: self.elementId, offset: value.translation) 26 | }).onEnded({ (value) in 27 | self.manager.draggingEnd(for: self.elementId) 28 | })) 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Sources/DragDrop/Drag/DraggableView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DraggableView.swift 3 | // SwiftUIDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | public struct DraggableView : View { 12 | 13 | @EnvironmentObject var manager: DragNDropManager 14 | public let elementId: UUID 15 | private let makeView: (DragInfo)-> V 16 | 17 | public struct DragInfo { 18 | public let isDragging: Bool 19 | public let offset: CGSize 20 | } 21 | 22 | public init(id: UUID, @ViewBuilder _ factory: @escaping (DragInfo) -> V) { 23 | self.elementId = id 24 | self.makeView = factory 25 | } 26 | 27 | public var body: some View { 28 | let info = DragInfo(isDragging: manager.isDragging(id: elementId), offset: manager.draggingOffset(for: elementId)) 29 | return makeView(info).offset(info.offset).draggable(id: elementId) 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Sources/DragDrop/Drag/View+Draggable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // View+Draggable.swift 3 | // SwiftUIDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | public extension View { 12 | func draggable(id: UUID) -> Self.Modified { 13 | Modified(content: self, modifier: DragElementModifier(elementId: id)) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/DragDrop/DragDropManager/DragNDropManager.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DragNDropManager.swift 3 | // SwiftUIDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | import Combine 11 | 12 | class DragNDropManager: Identifiable, BindableObject { 13 | 14 | let id: UUID = UUID() 15 | 16 | let didChange = PassthroughSubject() 17 | 18 | private var containersMap: [UUID: CGRect] = [:] 19 | private var draggableViewsMap: [UUID: CGRect] = [:] 20 | 21 | private var currentDraggingViewID: UUID? { 22 | didSet { 23 | if currentDraggingViewID != oldValue { 24 | self.didChange.send() 25 | } 26 | } 27 | } 28 | 29 | private var currentDraggingOffset: CGSize = .zero { 30 | didSet { 31 | if currentDraggingOffset.width != oldValue.width || currentDraggingOffset.height != oldValue.height { 32 | self.didChange.send() 33 | } 34 | } 35 | } 36 | 37 | func registerFor(drag id: UUID, frame: CGRect) { 38 | draggableViewsMap[id] = frame 39 | } 40 | 41 | func registerFor(drop id: UUID, frame: CGRect) { 42 | containersMap[id] = frame 43 | } 44 | 45 | func report(drag id: UUID, offset: CGSize) { 46 | self.currentDraggingViewID = id 47 | self.currentDraggingOffset = offset 48 | } 49 | 50 | func draggingOffset(for view: UUID) -> CGSize { 51 | guard currentDraggingViewID == view else { return .zero } 52 | return currentDraggingOffset 53 | } 54 | 55 | func draggingEnd(for view: UUID) { 56 | self.currentDraggingViewID = nil 57 | self.currentDraggingOffset = .zero 58 | } 59 | 60 | func canDrop(on container: UUID)-> Bool { 61 | guard let containerFrame = containersMap[container], 62 | let currentDraggingId = currentDraggingViewID, let dragFrame = draggableViewsMap[currentDraggingId] else { return false } 63 | let newFrame = dragFrame.offsetBy(dx: self.currentDraggingOffset.width, dy: self.currentDraggingOffset.height) 64 | return containerFrame.intersects(newFrame) 65 | } 66 | 67 | func isDragging(id: UUID)-> Bool { 68 | return id == currentDraggingViewID 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /Sources/DragDrop/Drop/DropContainer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DropContainer.swift 3 | // SwiftUIDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | public struct DropContainer : View { 12 | 13 | @EnvironmentObject var manager: DragNDropManager 14 | public let elementId: UUID 15 | private let makeView: (Bool)-> V 16 | 17 | public init(id: UUID, @ViewBuilder _ factory: @escaping (Bool) -> V) { 18 | self.elementId = id 19 | self.makeView = factory 20 | } 21 | 22 | public var body: some View { 23 | makeView(manager.canDrop(on: elementId)) 24 | .droppable(containerId: elementId) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Sources/DragDrop/Drop/DropContainerModifier.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DropContainerModifier.swift 3 | // SwiftUIDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | public struct DropContainerModifier: ViewModifier { 12 | @EnvironmentObject var manager: DragNDropManager 13 | public let elementId: UUID 14 | 15 | public func body(content: Content) -> some View { 16 | return content 17 | .overlay(GeometryReader { r in 18 | Color.clear 19 | .onAppear { 20 | self.manager.registerFor(drop: self.elementId, frame: r.frame(in: .global)) 21 | } 22 | }) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Sources/DragDrop/Drop/View+Droppable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // View+Droppable.swift 3 | // SwiftUIDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | 9 | import SwiftUI 10 | 11 | public extension View { 12 | func droppable(containerId: UUID)-> Self.Modified { 13 | Modified(content: self, modifier: DropContainerModifier(elementId: containerId)) 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Sources/DragDrop/InteractiveContainer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InteractiveContainer.swift 3 | // SwiftUIDragDrop 4 | // 5 | // Created by Bruno Bilescky on 16/07/2019. 6 | // Copyright © 2019 Bilescky. All rights reserved. 7 | // 8 | import Combine 9 | import SwiftUI 10 | 11 | public struct InteractiveContainer : View { 12 | 13 | let manager: DragNDropManager = DragNDropManager() 14 | 15 | public var body: AnyView 16 | 17 | public init(@ViewBuilder _ factory: () -> V) { 18 | self.body = AnyView(factory().environmentObject(manager)) 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /Tests/DragDropTests/DragDropTests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | @testable import DragDrop 3 | 4 | final class DragDropTests: XCTestCase { 5 | func testExample() { 6 | 7 | } 8 | 9 | static var allTests = [ 10 | ("testExample", testExample), 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /Tests/DragDropTests/XCTestManifests.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | #if !canImport(ObjectiveC) 4 | public func allTests() -> [XCTestCaseEntry] { 5 | return [ 6 | testCase(DragDropTests.allTests), 7 | ] 8 | } 9 | #endif 10 | -------------------------------------------------------------------------------- /Tests/LinuxMain.swift: -------------------------------------------------------------------------------- 1 | import XCTest 2 | 3 | import DragDropTests 4 | 5 | var tests = [XCTestCaseEntry]() 6 | tests += DragDropTests.allTests() 7 | XCTMain(tests) 8 | --------------------------------------------------------------------------------