{"id":42091,"date":"2024-02-13T16:24:38","date_gmt":"2024-02-13T21:24:38","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=42091"},"modified":"2024-02-14T10:53:34","modified_gmt":"2024-02-14T15:53:34","slug":"dragging-from-a-list-with-swiftui","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2024\/02\/13\/dragging-from-a-list-with-swiftui\/","title":{"rendered":"Dragging From a List With SwiftUI"},"content":{"rendered":"<p><a href=\"https:\/\/mastodon.social\/@marcoarment\/111908085001697137\">Marco Arment<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@marcoarment\/111908085001697137\"><p>I wish so badly that SwiftUI&rsquo;s <code>.onMove<\/code> supported multiple-item selection in a <code>List<\/code>.<\/p><p>I should never need to tell my customers, &ldquo;That was too difficult to achieve in SwiftUI, so that feature is gone.&rdquo;<\/p><\/blockquote>\n\n<p>It&rsquo;s scary reading stuff like this because, glancing at <a href=\"https:\/\/developer.apple.com\/documentation\/swiftui\/dynamicviewcontent\/onmove(perform:)\">the API<\/a>, the source is an <code>IndexSet<\/code>, so it seems like it was designed to handle multiple items. How are you supposed to know ahead of time that this doesn&rsquo;t work? I was hoping to see someone reply, telling Arment what he was doing wrong, but instead there were two links to <a href=\"https:\/\/forums.developer.apple.com\/forums\/thread\/707679\">forum<\/a> <a href=\"https:\/\/forums.developer.apple.com\/forums\/thread\/730367\">threads<\/a> about list dragging being broken.<\/p>\n\n<p><a href=\"https:\/\/mastodon.social\/@Timschmitz\/111908166660789249\">Tim Schmitz<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@Timschmitz\/111908166660789249\">\n<p>This category of problem still really concerns me about the future of Apple&rsquo;s UI frameworks. There are some things that were possible in UIKit that just aren&rsquo;t in SwiftUI, and Apple doesn&rsquo;t seem too bothered by some of them.<\/p>\n<\/blockquote>\n\n<p>This is basic stuff, not obscure features. The iOS and macOS interfaces make heavy use of lists and tables. And SwiftUI was introduced almost <em>5 years ago<\/em>.<\/p>\n\n<p><a href=\"https:\/\/mastodon.social\/@Arcticulate@toot.community\/111908617406596752\">Arcticulate<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@Arcticulate@toot.community\/111908617406596752\">\n<p>SwiftUI 5 feels mostly feature complete on the iOS side, but <code>List<\/code> keeps being hard for Apple to get right it seems. In terms of <code>onDelete<\/code> and <code>onMove<\/code>, they have improved a bit over the years but still problematic.<\/p>\n<\/blockquote>\n\n<p>On the Mac side, I periodically take a look at Shortcuts to see how it&rsquo;s doing. It still doesn&rsquo;t support dragging and dropping shortcuts from the list into a folder in the sidebar (even if you only drag one). It does let me re-order a multiple selection, though it also lets me try when a sort is in effect, which of course doesn&rsquo;t work. Whenever I click on something in the sidebar it loses the sort and goes back to the manual ordering. I don&rsquo;t know what the thinking was here.<\/p>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/08\/11\/appkit-vs-swiftui-stable-vs-shiny\/\">AppKit vs. SwiftUI: Stable vs. Shiny<\/a><\/li>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2021\/06\/08\/shortcuts-for-mac\/\">Shortcuts for Mac<\/a><\/li>\n<\/ul>\n\n<p id=\"dragging-from-a-list-with-swiftui-update-2024-02-14\">Update (2024-02-14): <a href=\"https:\/\/rogersfam.co\/@rhett\/111926330685013650\">Rhett Rogers<\/a>:<\/p>\n<blockquote cite=\"https:\/\/rogersfam.co\/@rhett\/111926330685013650\">\n<p>Every time I attempt to use a SwiftUI List, I think it is perfect.<\/p>\n<p>Then I actually have to make something real and it almost always falls short whenever I have to do anything with custom colors or animations.  And I fall back to a <code>ScrollView { VStack {} }<\/code>.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/mastodon.social\/@helge\/111926353410214272\">Helge He&szlig;<\/a>:<\/p>\n<blockquote cite=\"https:\/\/mastodon.social\/@helge\/111926353410214272\">\n<p>It would be ok if it would just affect customization, I just want the stuff that is builtin. But it&rsquo;s flickering and has all sorts of other weird side effects (transitions etc).<\/p>\n<p>[&#8230;]<\/p>\n<p>I was converting a like 3y old SwiftUI app to <code>List<\/code> end of last year assuming that it should have gotten OK by now. Still the same mess (same for <code>LazyVStack<\/code> fwiw, so as you went back to <code>ScrollView<\/code> + non-lazy <code>VStack<\/code>).<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Marco Arment: I wish so badly that SwiftUI&rsquo;s .onMove supported multiple-item selection in a List.I should never need to tell my customers, &ldquo;That was too difficult to achieve in SwiftUI, so that feature is gone.&rdquo; It&rsquo;s scary reading stuff like this because, glancing at the API, the source is an IndexSet, so it seems like [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2024-02-13T21:24:41Z","apple_news_api_id":"216421eb-9811-4df7-a73c-78b692e95cdb","apple_news_api_modified_at":"2024-02-14T15:53:37Z","apple_news_api_revision":"AAAAAAAAAAAAAAAAAAAAAQ==","apple_news_api_share_url":"https:\/\/apple.news\/AIWQh65gRTfenPHi2kulc2w","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[4],"tags":[31,2321,30,2385,71,1686,1812],"class_list":["post-42091","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-ios","tag-ios-17","tag-mac","tag-macos-14-sonoma","tag-programming","tag-shortcuts","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42091","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=42091"}],"version-history":[{"count":3,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42091\/revisions"}],"predecessor-version":[{"id":42102,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/42091\/revisions\/42102"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=42091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=42091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=42091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}