728x90
๋ฐ˜์‘ํ˜•
[SwiftUI] re-rendering, re-draw ์ปค์Šคํ„ฐ๋งˆ์ด์ง• (?)

[SwiftUI] re-rendering, re-draw ์ถ”์ธก ์—์„œ SwiftUI๊ฐ€ ๋‚ด๋ถ€์ ์œผ๋กœ ๋ฆฌ๋ Œ๋”๋ง์„ ์–ด๋–ป๊ฒŒ ๊ฒฐ์ •ํ•˜๋Š” ์ง€ ์ถ”์ธกํ•ด๋ณด์•˜๋Š”๋ฐ์š” ๋ฆฌ๋ Œ๋”๋ง์„ ์ปค์Šคํ„ฐ๋งˆ์ด์ง• (?) ํ•  ์ˆ˜ ์žˆ๋Š” ๋ฐฉ๋ฒ•๋„ ์žˆ์Šต๋‹ˆ๋‹ค. # 1. SwiftUI ๋Š” ๋‹ค์‹œ ์•ˆ๊ทธ๋ฆฌ๋Š”๋ฐ, ๋‚˜๋Š” ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ ๋ทฐ๋Š” extract subview๋ฅผ ํ•˜๋ฉด ๋ณ„๋„์˜ identity๋ฅผ ๋ถ€์—ฌ๋ฐ›์•„, ๋ถ€๋ชจ ๋ทฐ์™€ ๊ฐ™์ด ๋ฆฌ๋ Œ๋”๋ง์ด ์•ˆ๋ฉ๋‹ˆ๋‹ค. ๋ถ€๋ชจ์˜ body๊ฐ€ ์žฌํ˜ธ์ถœ๋  ๋•Œ extracted ํ•œ ์„œ๋ธŒ๋ทฐ๋ฅผ ํ•ญ์ƒ ๊ฐ™์ด ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ณ  ์‹ถ์œผ๋ฉด id๋ฅผ ํ™œ์šฉํ•ฉ๋‹ˆ๋‹ค. [ ๊ธฐ๋ณธ ๋™์ž‘ ] ContentView์˜ body๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ NoMatterText๋Š” ๋‹ค์‹œ ์•ˆ๊ทธ๋ ค์ง struct ContentView: View { @State private var isOn = true pri..

๐Ÿ/SwiftUI + Combine 2022. 11. 16. 23:56
[SwiftUI] re-rendering, re-draw ์ถ”์ธก

[ ์ธํŠธ๋กœ ] SwiftUI๋Š” state-driven, data-driven ๋ฐฉ์‹์œผ๋กœ state ๊ฐ€ ๋ณ€ํ•˜๋ฉด view ๋ฅผ ๋‹ค์‹œ ๊ทธ๋ฆฝ๋‹ˆ๋‹ค (body๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ) ํ•˜์ง€๋งŒ body๋ฅผ ์žฌํ˜ธ์ถœํ•œ๋‹ค๊ณ  ๋ชจ๋“  ๊ฒƒ์„ ๋‹ค์‹œ ๊ทธ๋ฆฌ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ๋ณ€๊ฒฝ์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„๋งŒ ๋‹ค์‹œ ๋ Œ๋”๋ง ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ ‡๋‹ค๋ฉด.. re-rendering ๋˜๋Š” re-draw๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” SwiftUI์˜ diff ํŒ๋‹จ ๋กœ์ง์€ ์–ด๋–ป๊ฒŒ ๋ ๊นŒ์š”? (= body๊ฐ€ ํ˜ธ์ถœ๋  ๋•Œ ๋ฌด์—‡์„ ๋‹ค์‹œ ๊ทธ๋ฆฌ๊ณ , ๋ฌด์—‡์„ ๋‹ค์‹œ ์•ˆ๊ทธ๋ฆด ์ง€ ์–ด๋–ป๊ฒŒ ๊ฒฐ์ •ํ• ๊นŒ์š”?) WWDC21 - Demystify SwiftUI ๋ฅผ ๋ณด๋ฉด identity, life time, dependencies ์ด ์„ธ๊ฐ€์ง€ ์š”์ธ์ด ๋ฉ”์ธ์š”์†Œ์ธ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค. ์ €๋Š” ์ด ์ค‘์—์„œ identity ์œ„์ฃผ๋กœ ์ €์˜ re-rendering ์ถ”์ธก..

๐Ÿ/SwiftUI + Combine 2022. 11. 16. 23:56
[SwiftUI] ZStack vs overlay modifier

ZStack ์€ ์ž์‹ ์˜ children๋ฅผ z์ถ•์œผ๋กœ overlayํ•˜๋Š” View์ด๊ณ  overlay ๋Š” ํ˜„์žฌ ๋ทฐ์— secondary view๋ฅผ overlayํ•˜๋Š” modifier ์ž…๋‹ˆ๋‹ค. (overlay๋ฅผ ์ค‘์ฒฉ์œผ๋กœ ๋ฒˆ์—ญํ•  ์ˆ˜ ์žˆ์„ ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค) ์• ํ”Œ๋ฌธ์„œ์— ์žˆ๋Š” overlay ์˜ˆ์ œ์˜ ๊ฒฐ๊ณผ๋ฅผ zstack์œผ๋กœ๋„ ๋˜‘๊ฐ™์ด ๋‚˜ํƒ€๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์ด๋ ‡๊ฒŒ ๋ณด๋ฉด ๋˜‘๊ฐ™์•„๋ณด์ด์ง€๋งŒ ์‚ฌ์‹ค ๋‘ ๊ฐœ๋Š” ์ฐจ์ด์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค. ZStack์˜ ์ž์‹๋ทฐ๋“ค์€ ์„œ๋กœ์— ๋Œ€ํ•ด independent ํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ZStack์— frame์„ ๋”ฐ๋กœ ์ฃผ์ง€ ์•Š์€ ์ด์ƒ ๊ฐ€์žฅ ํฐ ์ž์‹๋ทฐ๋ฅผ ๊ธฐ์ค€์œผ๋กœ ZStack์˜ fit์ด ๊ฒฐ์ •๋ฉ๋‹ˆ๋‹ค. ๋ฐ˜๋ฉด overlay์˜ ๊ฒฝ์šฐ overlay๋˜๋Š” view๋Š” parent view์— ์ข…์†๋ฉ๋‹ˆ๋‹ค. ํ•ญ์ƒ overlaid view๋Š” parent ..

๐Ÿ/SwiftUI + Combine 2021. 3. 26. 20:47
[SwiftUI] Button์˜ Tappable ์˜์—ญ

Button์€ ๋”ฑ ํ…์ŠคํŠธ์˜์—ญ๋งŒ Tappable ํ•˜๋‹ค. (๋…ธ๋ž€์ƒ‰์€ ํด๋ฆญ์˜์—ญ์ด ์•„๋‹˜) ์ด๋ฏธ์ง€๋ฅผ ๋„ฃ์–ด๋„ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ๋”ฑ ์ด๋ฏธ์ง€ ์˜์—ญ๋งŒ Tappableํ•˜๋‹ค. (๋…ธ๋ž€์ƒ‰์€ ํด๋ฆญ์˜์—ญ์ด ์•„๋‹˜) UIKit๊ณผ ๋‹ฌ๋ฆฌ SwiftUI์—์„œ๋Š” ๋ฒ„ํŠผ์„ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด์„œ Label์ด๋ผ๊ณ  ๋ถˆ๋ฆฌ๋Š” ๋‹ค๋ฅธ ๋ทฐ๋ฅผ ๊ผญ ์ค˜์•ผํ•œ๋‹ค.๊ทธ๋ž˜์„œ Label ์˜์—ญ๋งŒ tappableํ•˜๊ฒŒ ๋””์ž์ธ๋˜์—ˆ๋‚˜๋ณด๋‹ค. (์ถ”์ธก) ๊ทธ๋Ÿฌ๋ฉด Label๋ง๊ณ  ๋‹ค๋ฅธ ์˜์—ญ๋„ Tappableํ•˜๊ฒŒ ํ•˜๋ ค๋ฉด ์–ด๋–ป๊ฒŒ ํ•ด์•ผํ• ๊นŒ?! [1] Button๋ง๊ณ  Label์— frame์„ ์ฃผ๊ธฐ Label์˜์—ญ๋งŒ Tappableํ•˜๋‹ˆ๊นŒ Label์˜์—ญ์„ ๋ฒ„ํŠผ์‚ฌ์ด์ฆˆ๋กœ ํ•ด์ฃผ๋ฉด ๋˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค. [2] ๋ฒ„ํŠผ ์•„๋‹Œ ๋ทฐ๋ฅผ ๋งŒ๋“  ํ›„, onTapGesture ์‚ฌ์šฉSwiftUI์˜ ๋ฒ„ํŠผ์ด Label ์˜์—ญ๋งŒ Tappableํ•˜๊ฒŒ ๋””์ž์ธ ๋˜์—ˆ๋‹ค..

๐Ÿ/SwiftUI + Combine 2020. 9. 6. 02:56
[SwiftUI] modifier์˜ ์ˆœ์„œ๋ฅผ ๊ณ ๋ คํ•˜์ž (ํŠนํžˆ frame)

์ฒซ๋ฒˆ์งธ ์‚ฌ์ง„์˜ modifier ์ˆœ์„œ๋Š” background -> frame ์ž…๋‹ˆ๋‹ค. ๋‘๋ฒˆ์งธ ์‚ฌ์ง„์˜ modifier ์ˆœ์„œ๋Š” frame -> background ์ž…๋‹ˆ๋‹ค. ๊ฒฐ๊ณผ๊ฐ€ ๋‹ค๋ฅธ ๊ฒƒ์„ ๋ณผ ์ˆ˜์žˆ์ฃ ?! ๊ทธ ์ด์œ ๋Š” ๋ฌด์—‡์ผ๊นŒ์š”-?! SwiftUI์—์„œ๋Š” View์— modifier๋ฅผ ์ ์šฉํ• ๋•Œ๋งˆ๋‹ค ์ƒˆ๋กœ์šด view๋ฅผ ๋งŒ๋“ค๊ฒŒ ๋˜๋Š” ๊ฒƒ์ž„์„ ๊ธฐ์–ตํ•ด์•ผํ•ฉ๋‹ˆ๋‹ค (๋‹จ์ง€ ์กด์žฌํ•˜๋Š” view์˜ ์†์„ฑ์„ ๋ฐ”๊พธ๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ ์ƒˆ๋กœ์šด view๋ฅผ ๋ฆฌํ„ดํ•˜๊ฒŒ ๋˜๋Š” ๊ฒƒ-!) ๊ทธ๋ž˜์„œ ์ฒซ๋ฒˆ์งธ ์‚ฌ์ง„์€ ์•„๋ž˜์™€ ๊ฐ™์€ ์ด์œ ๋กœ ์ €๋ ‡๊ฒŒ ๊ทธ๋ ค์กŒ๊ณ  ๋‘๋ฒˆ์งธ ์‚ฌ์ง„์€ ์•„๋ž˜์™€ ๊ฐ™์€ ์ด์œ ๋กœ ์ €๋ ‡๊ฒŒ ๊ทธ๋ ค์กŒ์Šต๋‹ˆ๋‹ค. ํ—ท๊ฐˆ๋ฆฌ์ง€ ์•Š๋„๋ก frame modifier๋ฅผ ์ฒซ๋ฒˆ์งธ๋กœ ์œ„์น˜์‹œ์ผœ์•ผ๊ฒ ์Šต๋‹ˆ๋‹ค...! ๊ทธ๋ฆฌ๊ณ  ๊ฐœ๋ฐœํ•˜๋ฉด์„œ frame๋ง๊ณ ๋„ ์ˆœ์„œ๋ฐ”๊พธ๋‹ˆ๊นŒ ์›ํ•˜๋Š”๋Œ€๋กœ ๋™์ž‘ํ–ˆ๋˜ ๊ฒƒ์ด ๋˜ ์žˆ์—ˆ๋Š”๋ฐ (์ž˜ ๊ธฐ..

๐Ÿ/SwiftUI + Combine 2020. 9. 6. 02:01
๊ณต์ง€์‚ฌํ•ญ
Total
803,241
Today
100
Yesterday
1,454
ยซ   2022/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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 27 28 29 30 31
๊ธ€ ๋ณด๊ด€ํ•จ