From 4f546db4bdac9661603d86cd81b2b9dc525ce270 Mon Sep 17 00:00:00 2001 From: dragonflylee Date: Wed, 15 May 2024 13:47:10 +0800 Subject: [PATCH] Fix cell focus when chat reload --- wiliwili/source/fragment/inbox_chat.cpp | 1 + wiliwili/source/fragment/inbox_view.cpp | 5 ++++- wiliwili/source/view/recycling_grid.cpp | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/wiliwili/source/fragment/inbox_chat.cpp b/wiliwili/source/fragment/inbox_chat.cpp index fcb6fdee..05543609 100644 --- a/wiliwili/source/fragment/inbox_chat.cpp +++ b/wiliwili/source/fragment/inbox_chat.cpp @@ -160,6 +160,7 @@ void InboxChat::onMsgList(const bilibili::InboxMessageResultWrapper& result, boo datasource = new DataSourceMsgList(result, this->talkerId); recyclingGrid->setDefaultCellFocus(datasource->getItemCount() - 1); recyclingGrid->setDataSource(datasource); + brls::sync([this]() { recyclingGrid->selectRowAt(recyclingGrid->getDefaultCellFocus(), true); }); } }); } diff --git a/wiliwili/source/fragment/inbox_view.cpp b/wiliwili/source/fragment/inbox_view.cpp index b10c8f9f..79798957 100644 --- a/wiliwili/source/fragment/inbox_view.cpp +++ b/wiliwili/source/fragment/inbox_view.cpp @@ -67,7 +67,10 @@ class DataSourceChatList : public RecyclingGridDataSource { void onItemSelected(RecyclingGrid* recycler, size_t index) override { auto& r = this->list[index]; - auto* view = new InboxChat(r, [recycler]() { recycler->refresh(); }); + auto* view = new InboxChat(r, [recycler, index]() { + recycler->setDefaultCellFocus(index); + recycler->refresh(); + }); recycler->present(view); } diff --git a/wiliwili/source/view/recycling_grid.cpp b/wiliwili/source/view/recycling_grid.cpp index 68c682d5..95c2702a 100644 --- a/wiliwili/source/view/recycling_grid.cpp +++ b/wiliwili/source/view/recycling_grid.cpp @@ -311,7 +311,7 @@ void RecyclingGrid::reloadData() { } // 在前面的操作中,列表增加了一项,通过 selectRowAt 再精确地显示出具体选中项 - selectRowAt(cellFocusIndex, this->isFlowMode); + selectRowAt(cellFocusIndex, false); } void RecyclingGrid::notifyDataChanged() {