Files
test/Assets/Scripts/typing-preview-summary.md
T

2.3 KiB

Typing Preview - Summary

Muc tieu da thuc hien

  • Tach logic typingPreview ra class rieng de de tai su dung.
  • Lien ket lai logic giua ChatInputHandler va TypingPreviewController.
  • Dieu chinh co che hien/an theo yeu cau mobile keyboard.

Cac file da cap nhat

  • Assets/Scripts/TypingPreviewController.cs
  • Assets/Scripts/ChatInputHandler.cs

Noi dung da lam

1) Tach typing preview thanh class rieng

  • Tao class TypingPreviewController de quan ly:
    • Hien/an preview (typingPreviewRoot)
    • Cap nhat text preview realtime (typingPreviewText)
    • Dinh vi preview theo offset keyboard (typingPreviewRect, previewVerticalOffset)

2) Lien ket voi ChatInputHandler

  • ChatInputHandler giu SerializeField:
    • TypingPreviewController typingPreview
  • Moi khi input thay doi text, ChatInputHandler lay message body (bo prefix kenh/whisper) roi day sang controller de cap nhat preview.
  • Khi clear input, preview duoc cap nhat lai ngay de an dung trang thai.

3) Co che mobile keyboard (cap nhat moi nhat)

  • Da chuyen logic check keyboard vao thang TypingPreviewController:
    • IsMobileKeyboardVisible()
    • GetVisibleKeyboardHeight()
  • ChatInputHandler da bo cac ham keyboard-check khong con dung.
  • ChatInputHandler chi can goi typingPreview.UpdatePreview(isFocused, body).
  • ChatInputHandler.Update() van refresh moi frame de bat kip luc keyboard mo/dong.
  • Rule hien moi nhat:
    • Keyboard mobile vua mo la preview show ngay (neu input dang focus), khong can cho co ky tu.

Hanh vi hien tai

  • Preview chi hien khi:
    • Dang o mobile
    • Keyboard dang mo
    • Input dang focus
  • Khong con yeu cau body phai khong rong (show ngay khi keyboard mo).
  • Khi tat keyboard, preview an ngay.
  • Khi mo lai keyboard, noi dung da go truoc do van con trong input va preview hien lai dung noi dung.

Emoji tren preview

  • Hien tai preview duoc set text truc tiep tu body, nen neu body co TMP sprite tag thi co the hien emoji.
  • Luu y cau hinh component:
    • typingPreviewText dang de kieu TMP_InputField trong TypingPreviewController.
    • Neu muon on dinh cho muc dich "preview display", nen doi sang TMP_Text hoac TextMeshProUGUI.

Ghi chu

  • Da kiem tra lint sau cac lan sua, khong phat hien loi lint moi tren cac file da chinh.