{"id":40240,"date":"2023-08-03T19:40:15","date_gmt":"2023-08-03T23:40:15","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=40240"},"modified":"2023-08-03T19:41:04","modified_gmt":"2023-08-03T23:41:04","slug":"how-nshostingview-determines-its-sizing","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2023\/08\/03\/how-nshostingview-determines-its-sizing\/","title":{"rendered":"How NSHostingView Determines Its Sizing"},"content":{"rendered":"<p><a href=\"https:\/\/brian-webster.tumblr.com\/post\/723846294121152512\/how-nshostingview-determines-its-sizing\">Brian Webster<\/a>:<\/p>\n<blockquote cite=\"https:\/\/brian-webster.tumblr.com\/post\/723846294121152512\/how-nshostingview-determines-its-sizing\"><p>I couldn&rsquo;t get my SwiftUI view to expand to fill up the entire superview that the <code>NSHostingView<\/code> was being added to.<\/p><p>[&#8230;]<\/p><p>The next thing I came across was a property on <code>NSHostingView<\/code> called <code>sizingOptions<\/code>, which is described in the documentation as &ldquo;The options for how the hosting view creates and updates constraints based on the size of its SwiftUI content.&rdquo; Well that sounds promising! The default setting is all three options, <code>[.minSize, .intrinsicContentSize, .maxSize]<\/code>, so I tried setting it to just <code>[.minSize]<\/code> and lo and behold, it worked! The Spacer was now growing to take up the whole height of the superview! (setting <code>[.minSize, .maxSize]<\/code> also worked)<\/p><p>But, there&rsquo;s just one problem&#8230; this property was introduced in macOS 13 and I&rsquo;m still targeting macOS 12. &#x1F62D; But, after seeing this property and how it works, I <em>think <\/em>I now understand what was going on with the size proposals earlier. I believe what <code>NSHostingView<\/code> does is to probe its rootView once each so it can set up constraints for a minimum size, intrinsic content size, and maximum size. [&#8230;] So what I need to do is basically reimplement what the <code>sizingOptions<\/code> property is doing, which is to ignore the intrinsic content size of the SwiftUI view.<\/p><\/blockquote>\n\n<p>Previously:<\/p>\n<ul>\n<li><a href=\"https:\/\/mjtsai.com\/blog\/2023\/07\/20\/the-auto-layout-comprehendium\/\">The Auto Layout Comprehendium<\/a><\/li>\n<\/ul>","protected":false},"excerpt":{"rendered":"<p>Brian Webster: I couldn&rsquo;t get my SwiftUI view to expand to fill up the entire superview that the NSHostingView was being added to.[&#8230;]The next thing I came across was a property on NSHostingView called sizingOptions, which is described in the documentation as &ldquo;The options for how the hosting view creates and updates constraints based on [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2023-08-03T23:40:18Z","apple_news_api_id":"0409e1f6-c2b6-44a7-8e23-c8a5d876e2d0","apple_news_api_modified_at":"2023-08-03T23:40:18Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/ABAnh9sK2RKeOI8il2Hbi0A","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":[200,69,30,2077,2223,71,1812],"class_list":["post-40240","post","type-post","status-publish","format-standard","hentry","category-programming-category","tag-autolayout","tag-cocoa","tag-mac","tag-macos-12","tag-macos-13-ventura","tag-programming","tag-swiftui"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40240","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=40240"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40240\/revisions"}],"predecessor-version":[{"id":40241,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/40240\/revisions\/40241"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=40240"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=40240"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=40240"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}