fix(player): 修复返回首页黑屏并恢复预热

This commit is contained in:
Zhou Weidong committed 2026-10-26 16:45:00 +08:00
1 parent 6667330ce0
commit 54eb5a60a8
9 files changed
+56 -101

No files matched your search

+3 -47
View File
@@ -57,12 +57,8 @@ const double _playerLoadingStrokeWidth = 2;
const double _feedRefreshTopGap = 56;
class PlayerPageHandoff {
PlayerPageHandoff({
required this.prepareSource,
required this.sourceUserWantsPlay,
});
PlayerPageHandoff({required this.sourceUserWantsPlay});
final Future<void> Function() prepareSource;
final bool sourceUserWantsPlay;
}
@@ -145,8 +141,6 @@ class _PlayerPageState extends State<PlayerPage>
DateTime? _swipeStartedAt;
bool _swipePrewarmCaptured = false;
bool _presentationActive = false;
bool _presentationSuspended = false;
bool _presentationReturning = false;
bool _leavingHandoff = false;
bool _preparingFullPlayer = false;
final Set<String> _precachedPosterUrls = {};
@@ -538,8 +532,6 @@ class _PlayerPageState extends State<PlayerPage>
}
Widget _buildPlayer(BuildContext context) {
if (_presentationSuspended) return const SizedBox.expand();
if (_presentationReturning) return _buildPresentationReturnLayer();
final interactions = context.watch<InteractionController>();
final l10n = AppLocalizations.of(context)!;
final indices = logic.visibleIndices;
@@ -736,17 +728,6 @@ class _PlayerPageState extends State<PlayerPage>
};
}
Widget _buildPresentationReturnLayer() {
final indices = logic.visibleIndices;
return AnimatedBuilder(
animation: logic.session,
builder: (context, _) => PlayerRenderStack(
pageController: _pageController,
slots: _renderSlots(indices),
),
);
}
PlayerRenderSlotData _renderSlot(
PlayerRenderSlotRole role,
int? index,
@@ -1191,10 +1172,7 @@ class _PlayerPageState extends State<PlayerPage>
_preparingFullPlayer = false;
}
if (!mounted || !context.mounted) return;
final handoff = PlayerPageHandoff(
prepareSource: _prepareSourceAfterFullPlayer,
sourceUserWantsPlay: sourceUserWantsPlay,
);
final handoff = PlayerPageHandoff(sourceUserWantsPlay: sourceUserWantsPlay);
_logFullPlayerRoute('present');
setState(() => _presentationActive = true);
final route = Navigator.of(context).push<void>(
@@ -1208,41 +1186,19 @@ class _PlayerPageState extends State<PlayerPage>
),
),
);
await WidgetsBinding.instance.endOfFrame;
if (mounted) {
setState(() => _presentationSuspended = true);
await WidgetsBinding.instance.endOfFrame;
}
await route;
if (!mounted) return;
logic.attach(widget, isMounted: () => mounted);
setState(() {
_presentationActive = false;
_presentationSuspended = false;
_presentationReturning = false;
});
setState(() => _presentationActive = false);
await logic.resumeAfterFullPlayer();
if (!mounted) return;
_logFullPlayerRoute('restored');
}
Future<void> _prepareSourceAfterFullPlayer() async {
if (!mounted) return;
logic.attach(widget, isMounted: () => mounted);
await logic.prepareFeedResume();
if (!mounted) return;
setState(() {
_presentationSuspended = false;
_presentationReturning = true;
});
await WidgetsBinding.instance.endOfFrame;
}
Future<void> _leaveHandoff(BuildContext context) async {
if (_leavingHandoff) return;
setState(() => _leavingHandoff = true);
await logic.session.pauseForRouteHandoff();
await widget.handoff?.prepareSource();
if (context.mounted) Navigator.of(context).pop();
}