Skip to content

๐Ÿ—œEnhanced SwiftUI's TextEditor API powered by UITextView

Notifications You must be signed in to change notification settings

Jager-yoo/TextMaster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

15 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

TextMaster

๐Ÿ—œEnhanced SwiftUI's TextEditor API powered by UITextView


โœจ ์„ค๋ช…

SwiftUI ์—์„œ ์—ฌ๋Ÿฌ ์ค„์˜ ํ…์ŠคํŠธ ์ž…๋ ฅ์„ ๋ฐ›๊ธฐ ์œ„ํ•ด์„  ๋ฌด์—‡์„ ์‚ฌ์šฉํ•ด์•ผ ํ• ๊นŒ์š”?

iOS 14.0+ ๋ถ€ํ„ฐ ์ œ๊ณต๋˜๋Š” TextEditor๊ฐ€ ์žˆ์ง€๋งŒ, ๊ธฐ๋Šฅ์ด ์ œํ•œ์ ์ž…๋‹ˆ๋‹ค.

์Šคํฌ๋กค ๊ธฐ๋Šฅ์„ ์ผœ๊ณ  ๋„๊ฑฐ๋‚˜, firstResponder ์„ค์ •, ๋‹ค์ด๋‚˜๋ฏน height ์กฐ์ ˆ, ๋ฐฑ๊ทธ๋ผ์šด๋“œ ์ปฌ๋Ÿฌ ๋ณ€๊ฒฝ ๋“ฑ์ด ๋ถˆ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰, TextEditor ๋กœ๋Š” ์‹ค๋ฌด์—์„œ ํ•„์š”ํ•œ ๋ณต์žกํ•œ ์š”๊ตฌ์‚ฌํ•ญ์„ ์ถฉ์กฑ์‹œํ‚ค๊ธฐ ์–ด๋ ต์Šต๋‹ˆ๋‹ค.

TextMaster ๋Š” UIKit ์—์„œ iOS 2.0+ ๋ถ€ํ„ฐ ์ œ๊ณต๋˜๋Š” ๊ทผ๋ณธ API ์ธ UITextView์˜ ๊ธฐ๋Šฅ์„ SwiftUI ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก wrapping ํ•œ ๊ตฌ์กฐ์ฒด์ž…๋‹ˆ๋‹ค.

TextMaster ๋Š” iOS 15.0+ ๋ถ€ํ„ฐ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.


์ผ๋ถ€๋Ÿฌ SPM ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๋งŒ๋“ค์ง€ ์•Š์•˜์Šต๋‹ˆ๋‹ค.

๋ณธ ๋ ˆํฌ์˜ TextMaster.swift ํŒŒ์ผ ๋‚ด๋ถ€๋ฅผ ๋ณต์‚ฌํ•ด์„œ ๊ฐ€์ ธ๊ฐ€๋ฉด, ๋ฐ”๋กœ ์‚ฌ์šฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

์ปค์Šคํ…€์ด ํ•„์š”ํ•œ ๋ถ€๋ถ„์€ ์Šค์Šค๋กœ ์ˆ˜์ •ํ•ด์„œ ์‚ฌ์šฉํ•˜์…”๋„ ๋ฉ๋‹ˆ๋‹ค. ๐Ÿ˜„


โœจ ํŠน์ง•

์‹ค๋ฌด์—์„œ ๊ธฐํš์ž/๋””์ž์ด๋„ˆ์™€ ํ™”๋ฉด์— ์˜ฌ๋ฆฌ๋Š” TextView ์˜ ์ŠคํŽ™์„ ์ด์•ผ๊ธฐํ•˜๋‹ค ๋ณด๋ฉด, ๋‹จ์ˆœํžˆ ๊ณ ์ • height ๋กœ ๊ฒฐ์ •๋  ๋•Œ๋„ ์žˆ์ง€๋งŒ

๊ฐ„ํ˜น, ์ด๋Ÿฐ ์ŠคํŽ™์„ ์ „๋‹ฌ ๋ฐ›๋Š” ๊ฒฝ์šฐ๋„ ์žˆ์Šต๋‹ˆ๋‹ค.

"์ฒ˜์Œ์—” 1์ค„๋งŒ ํ‘œ์‹œ๋˜๋‹ค๊ฐ€, ์ตœ๋Œ€ 5์ค„๊นŒ์ง€ ๋Š˜์–ด๋‚˜๊ณ , ๊ทธ ๋ณด๋‹ค ๋งŽ์•„์ง€๋ฉด ์Šคํฌ๋กค์ด ๊ฐ€๋Šฅํ•˜๋„๋ก ๋งŒ๋“ค์–ด์ฃผ์„ธ์š”."

"์•„ ๊ทผ๋ฐ ํฐํŠธ๋Š” 24 ์ •๋„๋กœ ์ข€ ํฌ๊ฒŒ ํ•ด์ฃผ์‹œ๊ณ ์š”."

"์ฒ˜์Œ์— ์ด ํŽ˜์ด์ง€๋กœ ์ง„์ž…ํ•  ๋•Œ, ๋ฐ”๋กœ TextView ์— ํฌ์ปค์Šค๊ฐ€ ๋“ค์–ด์˜ค๋ฉด์„œ ํ‚ค๋ณด๋“œ๊ฐ€ ์˜ฌ๋ผ์˜ค๊ฒŒ ํ•ด์ฃผ์„ธ์š”."

์ถฉ๋ถ„ํžˆ ํ•ฉ๋ฆฌ์ ์ธ ์ŠคํŽ™์ด์ง€๋งŒ, ์ด ์ŠคํŽ™์„ SwiftUI ์—์„œ ๊ตฌํ˜„ํ•˜๋Š” ๊ฑด ๋งค์šฐ~ ๊นŒ๋‹ค๋กญ์Šต๋‹ˆ๋‹ค.

ํ•˜์ง€๋งŒ TextMaster ๋กœ๋Š” ์‰ฝ๊ฒŒ ๊ตฌํ˜„ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.

TextMaster(
  text: $text, // @State ํ…์ŠคํŠธ์™€ ๋ฐ”์ธ๋”ฉ
  isFocused: $isTextMasterFocused, // @FocusState ์™€ ๋ฐ”์ธ๋”ฉ
  minLine: 1, // ์ตœ์†Œ 1์ค„ (๋””ํดํŠธ)
  maxLine: 5, // ์ตœ๋Œ€ 5์ค„ (๋ผ์ธ์ด ๋” ๋Š˜์–ด๋‚˜๋ฉด ์Šคํฌ๋กค ๊ธฐ๋Šฅ์ด ์ž‘๋™)
  fontSize: 24, // ํฐํŠธ ์‚ฌ์ด์ฆˆ (Double ํƒ€์ž…)
  becomeFirstResponder: true) // true ๊ฐ€ ๋“ค์–ด๊ฐ€๋ฉด, ์ด ํŽ˜์ด์ง€๊ฐ€ ๋‚˜ํƒ€๋‚  ๋•Œ ์ž๋™์œผ๋กœ ํฌ์ปค์Šค๊ฐ€ ์žกํžˆ๋ฉฐ ํ‚ค๋ณด๋“œ ์˜ฌ๋ผ์˜ด

TextMaster


์ŠคํŽ™์ด ์ด๋ ‡๊ฒŒ ๋“ค์–ด์˜จ๋‹ค๊ณ  ๊ฐ€์ •ํ•ด๋ณด์ฃ .

"์ตœ์†Œ 2์ค„์—์„œ ์‹œ์ž‘, ์ตœ๋Œ€ 4์ค„ ๊นŒ์ง€๋งŒ ์ปค์ง€๋‹ค๊ฐ€ ์Šคํฌ๋กค ์ž‘๋™, ํฐํŠธ ์‚ฌ์ด์ฆˆ๋Š” 16 ์œผ๋กœ ๋ถ€ํƒ๋“œ๋ ค์š”."

"์•„, ๋ฐฑ๊ทธ๋ผ์šด๋“œ๋Š” quaternary ๋กœ ๋ถ€ํƒ๋“œ๋ ค์š”."

TextMaster(
  text: $text,
  isFocused: $isTextMasterFocused,
  minLine: 2,
  maxLine: 5,
  fontSize: 16)
  .background(.quaternary)

TextMaster2


์ด๋Ÿฐ ์ŠคํŽ™์€ ์–ด๋–จ๊นŒ์š”?

"3์ค„ ๊นŒ์ง€๋งŒ ์ž…๋ ฅ ๊ฐ€๋Šฅํ•˜๋„๋ก ๊ณ ์ •์‹œ์ผœ ์ฃผ์„ธ์š”. ๊ทธ ์ด์ƒ์—์„  ์Šคํฌ๋กค์ด ์ž‘๋™ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค."

TextMaster(
  text: $text,
  isFocused: $isTextMasterFocused,
  minLine: 3,
  maxLine: 3,
  fontSize: 16)

TextMaster3


์œ„์™€ ๊ฐ™์ด, TextMaster๋Š” SwiftUI ์˜ TextEditor API ์˜ ํ•œ๊ณ„๋ฅผ ๋ฒ—์–ด๋‚˜๊ณ 

์‹ค๋ฌด์—์„œ ์š”๊ตฌ ๋ฐ›๋Š” TextView ์ŠคํŽ™์„ ์‰ฝ๊ฒŒ ๋งž์ถ”๊ธฐ ์œ„ํ•ด ๋งŒ๋“ค์–ด์กŒ์Šต๋‹ˆ๋‹ค.

ํ˜น์‹œ๋‚˜ ๋” ์ถ”๊ฐ€๋ฅผ ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์ด๋‚˜ ํŒŒ๋ผ๋ฏธํ„ฐ๊ฐ€ ์žˆ๋‹ค๋ฉด, Issues์— ์ œ์•ˆํ•ด์ฃผ์„ธ์š”. ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค! ๐Ÿ˜„

About

๐Ÿ—œEnhanced SwiftUI's TextEditor API powered by UITextView

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages