#pragma once // Spec: INV-posts 5.3 (CommentEditorView). Mention suggestions above a text editor (BG_0), a counter (min 3, max // 125000 UTF-16 units), the uploader and the cancel and submit icons. One object per open composer; the owner // calls view() every frame. #include #include #include #include #include #include "model/UploadResponse.hpp" #include "model/UserSearch.hpp" #include "screens/components/AttachmentUploader.hpp" #include "screens/components/MentionSuggestions.hpp" #include "ui/TextInput.hpp" #include "ui/Views.hpp" namespace dp { struct CommentEditorProps { ui::Binding text; std::string placeholder; // empty = PostsText::kReplyPlaceholder std::optional initialLineCount; std::optional initialHeight; bool focusOnAppear = false; // Attachments are offered only when onAttachmentsChange is set (replies, not edits). std::vector attachments; std::function&)> onAttachmentsChange; std::vector mentionParticipants; std::function onCancel; std::function onSubmit; std::string anchorKey; // AnchorMark key of the composer (scroll anchor), empty = unmarked }; class CommentEditor { public: // `key` makes the text editor state (height) unique among the visible composers. explicit CommentEditor(std::string key); ~CommentEditor(); CommentEditor(const CommentEditor&) = delete; CommentEditor& operator=(const CommentEditor&) = delete; ui::ViewPtr view(const CommentEditorProps& props); // Height of the mention suggestion list (0 while hidden); the screen re-scrolls the composer when it changes. float mentionListHeight() const { return mentions_.listHeight(); } // 3 <= UTF-16 units <= 125000 (CommentEditorView.swift:104-108). static bool canSubmit(const std::string& text); // Scroll anchor id of the composer (CommentEditorView.scrollAnchorName). static const char* scrollAnchorName() { return "commentComposerAnchor"; } private: void syncUploaders(const CommentEditorProps& props); void scheduleFocus(); std::string key_; std::shared_ptr handle_ = std::make_shared(); MentionSuggestions mentions_; std::unique_ptr small_; std::unique_ptr full_; std::vector> retired_; bool focusScheduled_ = false; std::shared_ptr alive_ = std::make_shared(true); }; } // namespace dp