๊ธ€ ์ž‘์„ฑ์ž: ์ด์ง€์›๐ŸŒฉ๏ธ

ํ˜„์žฌ ํ•˜๊ณ  ์žˆ๋Š” ํ† ์ด ํ”„๋กœ์ ํŠธ์—์„œ ์‚ฌ์šฉ์ž์—๊ฒŒ ์ด๋ชจ์ง€๋ฅผ ์ž…๋ ฅ๋ฐ›๋Š”๋‹ค. ์ผ๋ฐ˜์ ์ธ ํ‚ค๋ณด๋“œ๋กœ ์ž…๋ ฅ๋ฐ›๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ ISEmojiView ๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ–ˆ๋Š”๋ฐ, ์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” EmojiViewDelegate๋ฅผ ๊ตฌํ˜„ํ•ด์•ผ ํ•œ๋‹ค. ๊ทธ์ค‘์—์„œ ํ•ต์‹ฌ์€ ์ด ๋ถ€๋ถ„์ด๋‹ค.

// callback when tap a emoji on keyboard
func emojiViewDidSelectEmoji(_ emoji: String, emojiView: EmojiView) {
    textView.insertText(emoji)
}

๋‚˜๋Š” ๋”ฑ ํ•˜๋‚˜์˜ ์ด๋ชจ์ง€๋งŒ ์ž…๋ ฅ๋ฐ›๊ณ  ์‹ถ์–ด์„œ, insertText()๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๋Œ€์‹ ์— emojiField.text = emoji๋กœ ๋ณ€๊ฒฝํ–ˆ๋‹ค. ๊ทธ๋Ÿฐ๋ฐ, ์—ฌ๊ธฐ์„œ ๋ฌธ์ œ์ ์ด ์ƒ๊ฒผ๋Š”๋ฐ emojiField์— ๋ฐ”์ธ๋“œ ํ•œ PublishRelay์—์„œ ํ…์ŠคํŠธ ๋ณ€๊ฒฝ์„ ๊ฐ์ง€ํ•˜์ง€ ๋ชปํ–ˆ๋‹ค.

๊ทธ๋ž˜์„œ ๋‚˜๋Š” ๋‹จ์ˆœํ•˜๊ฒŒ, ์ง์ ‘ ์ด๋ฒคํŠธ๋ฅผ ๋„˜๊ฒจ์ฃผ๋Š” ๋ฐฉ์‹์œผ๋กœ ํ•ด๊ฒฐํ–ˆ๋‹ค.

// callback when tap a emoji on keyboard
func emojiViewDidSelectEmoji(_ emoji: String, emojiView: EmojiView) {
    emojiField.text = emoji
    viewModel.emojiField.accept(emoji)
}

๊ทธ๋Ÿฐ๋ฐ...!

์Šคํ„ฐ๋””์—์„œ ๋‹ค๋ฅธ ๋ถ„์ด ๋ณธ์ธ ๋ฌธ์ œ ํ•ด๊ฒฐํ•œ ๊ฑธ ๊ณต์œ ํ•˜์…จ๋Š”๋ฐ ๊ทธ๊ฒŒ ๋‚˜์™€ ๊ฐ™์€ ๋ฌธ์ œ์˜€์—ˆ๋‹ค. ํ•ด๊ฒฐ์ฑ…์€ ์—ญ์‹œ๋‚˜, ์ˆ˜๋™์œผ๋กœ ์•Œ๋ ค์ฃผ๋Š” ๊ฒƒ์ธ๋ฐ ๋‹ค๋ฅธ ์ ์€ ๋‚˜์ฒ˜๋Ÿผ ํŠน์ • ์˜ต์ €๋ฒ„๋ธ”์— ์ด๋ฒคํŠธ๋ฅผ ์ „๋‹ฌํ•˜๋Š” ๊ฒŒ ์•„๋‹ˆ๋ผ, ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค๋Š” ๊ฑธ UITextField์— ์•Œ๋ฆฌ๋Š” ๊ฒƒ์ด๋‹ค.

// callback when tap a emoji on keyboard
func emojiViewDidSelectEmoji(_ emoji: String, emojiView: EmojiView) {
    emojiField.text = emoji
    emojiField.sendActions(for: .valueChanged)
}

์ด๋ ‡๊ฒŒ ํ•˜๋ฉด, ์—ฌ๋Ÿฌ ๊ฐœ์˜ ์˜ต์ €๋ฒ„๋ธ”์— ๋ฐ”์ธ๋”ฉ์ด ๋˜์–ด ์žˆ์–ด๋„ ๋‚ด๊ฐ€ ํ–ˆ๋˜ ๋ฐฉ์‹์ฒ˜๋Ÿผ ์ผ์ผ์ด ์•Œ๋ ค์ค„ ํ•„์š”๊ฐ€ ์—†๋‹ค.

์™€! ๊ฐœ๊ฟ€!

ํ•ด๊ฒฐํ•˜๊ณ  ๋‚˜๋‹ˆ๊นŒ ๋“œ๋Š” ์ƒ๊ฐ์€ ์™œ ์ง์ ‘ ๋Œ€์ž…ํ•˜๋Š” ๊ฑด ์ด๋ฒคํŠธ๋ฅผ ๊ฐ์ง€ํ•˜์ง€ ๋ชปํ•˜๋Š” ๊ฒƒ์ผ๊นŒ? ์˜€๋Š”๋ฐ ๊ทธ๊ฒƒ๋งˆ์ €๋„ ๋‹ต๋ณ€์— ์“ฐ์—ฌ์žˆ์—ˆ๋‹ค.

ํ•ด๊ฒฐ์ฑ… ๋ณด๋Š๋ผ ๋‚ด์šฉ์€ ๋ณด์ง€๋„ ์•Š์•˜์Œ.

 

On digging a little bit more, I realized that the rx.text depends on UIControlEvents and these are not triggered when you explicitly set the text.
์กฐ๊ธˆ ๋” ์ž์„ธํžˆ ์‚ดํŽด๋ณด๋ฉด, rx.text๊ฐ€ UIControlEvents์— ์˜์กดํ•˜๊ณ  ๋ช…์‹œ์ ์œผ๋กœ ํ…์ŠคํŠธ๋ฅผ ์„ค์ •ํ•  ๋•Œ ํŠธ๋ฆฌ๊ฑฐ ๋˜์ง€ ์•Š๋Š”๋‹ค๋Š” ๊ฒƒ์„ ๊นจ๋‹ฌ์•˜์Šต๋‹ˆ๋‹ค.

 

์–ด.. ์–ด๋ ค์›Œ... ๐Ÿคฏ

 

์ฐธ๊ณ  ์ž๋ฃŒ

๋ฐ˜์‘ํ˜•