mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-05-07 10:37:51 +08:00
refresh live msg if needed
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -100,7 +100,9 @@ class LiveRoomController extends GetxController {
|
|||||||
// dm
|
// dm
|
||||||
LiveDmInfoData? dmInfo;
|
LiveDmInfoData? dmInfo;
|
||||||
List<RichTextItem>? savedDanmaku;
|
List<RichTextItem>? savedDanmaku;
|
||||||
|
int builtLength = 0;
|
||||||
RxList<dynamic> messages = <dynamic>[].obs;
|
RxList<dynamic> messages = <dynamic>[].obs;
|
||||||
|
bool get shouldRefresh => builtLength != messages.length;
|
||||||
late final Rx<SuperChatItem?> fsSC = Rx<SuperChatItem?>(null);
|
late final Rx<SuperChatItem?> fsSC = Rx<SuperChatItem?>(null);
|
||||||
late final RxList<SuperChatItem> superChatMsg = <SuperChatItem>[].obs;
|
late final RxList<SuperChatItem> superChatMsg = <SuperChatItem>[].obs;
|
||||||
RxBool disableAutoScroll = false.obs;
|
RxBool disableAutoScroll = false.obs;
|
||||||
@@ -285,7 +287,17 @@ class LiveRoomController extends GetxController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void jumpToBottom() {
|
void handleJumpToBottom() {
|
||||||
|
disableAutoScroll.value = false;
|
||||||
|
if (shouldRefresh) {
|
||||||
|
messages.refresh();
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback(_jumpToBottom);
|
||||||
|
} else {
|
||||||
|
_jumpToBottom();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void _jumpToBottom([_]) {
|
||||||
if (scrollController.hasClients) {
|
if (scrollController.hasClients) {
|
||||||
scrollController.jumpTo(scrollController.position.maxScrollExtent);
|
scrollController.jumpTo(scrollController.position.maxScrollExtent);
|
||||||
}
|
}
|
||||||
@@ -349,12 +361,21 @@ class LiveRoomController extends GetxController {
|
|||||||
disableAutoScroll.value = true;
|
disableAutoScroll.value = true;
|
||||||
} else if (userScrollDirection == .reverse) {
|
} else if (userScrollDirection == .reverse) {
|
||||||
final pos = scrollController.position;
|
final pos = scrollController.position;
|
||||||
if (pos.maxScrollExtent - pos.pixels <= 100) {
|
if (pos.maxScrollExtent - pos.pixels <= 100 && disableAutoScroll.value) {
|
||||||
disableAutoScroll.value = false;
|
disableAutoScroll.value = false;
|
||||||
|
refreshMsgIfNeeded();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void refreshMsgIfNeeded() {
|
||||||
|
if (shouldRefresh) {
|
||||||
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||||
|
messages.refresh();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void onClose() {
|
void onClose() {
|
||||||
closeLiveMsg();
|
closeLiveMsg();
|
||||||
|
|||||||
@@ -187,7 +187,9 @@ class _LiveRoomPageState extends State<LiveRoomPage>
|
|||||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||||
if (plPlayerController.visible = state == .resumed) {
|
if (plPlayerController.visible = state == .resumed) {
|
||||||
if (!plPlayerController.showDanmaku) {
|
if (!plPlayerController.showDanmaku) {
|
||||||
_liveRoomController.startLiveTimer();
|
_liveRoomController
|
||||||
|
..refreshMsgIfNeeded()
|
||||||
|
..startLiveTimer();
|
||||||
plPlayerController.showDanmaku = true;
|
plPlayerController.showDanmaku = true;
|
||||||
}
|
}
|
||||||
} else if (state == .paused) {
|
} else if (state == .paused) {
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ class LiveRoomChatPanel extends StatelessWidget {
|
|||||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||||
controller: liveRoomController.scrollController,
|
controller: liveRoomController.scrollController,
|
||||||
separatorBuilder: (_, _) => const SizedBox(height: 8),
|
separatorBuilder: (_, _) => const SizedBox(height: 8),
|
||||||
itemCount: liveRoomController.messages.length,
|
itemCount: liveRoomController.builtLength =
|
||||||
|
liveRoomController.messages.length,
|
||||||
physics: const ClampingScrollPhysics(),
|
physics: const ClampingScrollPhysics(),
|
||||||
itemBuilder: (_, index) {
|
itemBuilder: (_, index) {
|
||||||
final item = liveRoomController.messages[index];
|
final item = liveRoomController.messages[index];
|
||||||
@@ -218,17 +219,10 @@ class LiveRoomChatPanel extends StatelessWidget {
|
|||||||
right: 12,
|
right: 12,
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
child: ElevatedButton.icon(
|
child: ElevatedButton.icon(
|
||||||
style: ElevatedButton.styleFrom(
|
style: const ButtonStyle(visualDensity: .comfortable),
|
||||||
visualDensity: VisualDensity.comfortable,
|
icon: const Icon(Icons.arrow_downward_rounded, size: 20),
|
||||||
),
|
|
||||||
icon: const Icon(
|
|
||||||
Icons.arrow_downward_rounded,
|
|
||||||
size: 20,
|
|
||||||
),
|
|
||||||
label: const Text('回到底部'),
|
label: const Text('回到底部'),
|
||||||
onPressed: () => liveRoomController
|
onPressed: liveRoomController.handleJumpToBottom,
|
||||||
..disableAutoScroll.value = false
|
|
||||||
..jumpToBottom(),
|
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
: const SizedBox.shrink(),
|
: const SizedBox.shrink(),
|
||||||
|
|||||||
Reference in New Issue
Block a user