feat(recommend): 支持横向切换三个内容页
This commit is contained in:
1 parent
5fce65ac57
commit
17faa749b2
3 files changed
+121
-17
No files matched your search
@@ -38,8 +38,15 @@ class RecommendPage extends StatefulWidget {
|
||||
|
||||
class _RecommendPageState extends State<RecommendPage> {
|
||||
RecommendInnerTab _tab = RecommendInnerTab.feed;
|
||||
final PageController _pageController = PageController();
|
||||
int _scrubCancelRequest = 0;
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_pageController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final categories = context.read<CategoryController>();
|
||||
@@ -51,23 +58,35 @@ class _RecommendPageState extends State<RecommendPage> {
|
||||
Positioned.fill(
|
||||
child: ListenableBuilder(
|
||||
listenable: Listenable.merge([widget.feedController, categories]),
|
||||
builder: (context, _) => IndexedStack(
|
||||
index: _tab.index,
|
||||
builder: (context, _) => PageView(
|
||||
key: const Key('recommend-tab-page-view'),
|
||||
controller: _pageController,
|
||||
scrollDirection: Axis.horizontal,
|
||||
onPageChanged: _onPageChanged,
|
||||
children: [
|
||||
_recommendFeed(context),
|
||||
_withTopNavSpace(
|
||||
RecommendSectionsView(
|
||||
feedController: widget.feedController,
|
||||
categories: categories,
|
||||
onOpenDrama: _openDrama,
|
||||
onMore: _handleMore,
|
||||
_KeepAliveTab(
|
||||
key: const PageStorageKey('recommend-tab-feed'),
|
||||
child: _recommendFeed(context),
|
||||
),
|
||||
_KeepAliveTab(
|
||||
key: const PageStorageKey('recommend-tab-playlists'),
|
||||
child: _withTopNavSpace(
|
||||
RecommendSectionsView(
|
||||
feedController: widget.feedController,
|
||||
categories: categories,
|
||||
onOpenDrama: _openDrama,
|
||||
onMore: _handleMore,
|
||||
),
|
||||
),
|
||||
),
|
||||
_withTopNavSpace(
|
||||
AllDramasFilterGrid(
|
||||
feedController: widget.feedController,
|
||||
onOpenDrama: _openDrama,
|
||||
onOpenFilter: widget.onOpenFilter,
|
||||
_KeepAliveTab(
|
||||
key: const PageStorageKey('recommend-tab-all'),
|
||||
child: _withTopNavSpace(
|
||||
AllDramasFilterGrid(
|
||||
feedController: widget.feedController,
|
||||
onOpenDrama: _openDrama,
|
||||
onOpenFilter: widget.onOpenFilter,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -162,6 +181,24 @@ class _RecommendPageState extends State<RecommendPage> {
|
||||
_tab = tab;
|
||||
_scrubCancelRequest++;
|
||||
});
|
||||
if (_pageController.hasClients) {
|
||||
unawaited(
|
||||
_pageController.animateToPage(
|
||||
tab.index,
|
||||
duration: const Duration(milliseconds: 220),
|
||||
curve: Curves.easeOut,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void _onPageChanged(int index) {
|
||||
final next = RecommendInnerTab.values[index];
|
||||
if (next == _tab) return;
|
||||
setState(() {
|
||||
_tab = next;
|
||||
_scrubCancelRequest++;
|
||||
});
|
||||
}
|
||||
|
||||
void _handleSearch() {
|
||||
@@ -180,10 +217,31 @@ class _RecommendPageState extends State<RecommendPage> {
|
||||
}
|
||||
|
||||
void _handleMore(RecommendSectionKind section) {
|
||||
setState(() => _tab = RecommendInnerTab.allDramas);
|
||||
_selectTab(RecommendInnerTab.allDramas);
|
||||
}
|
||||
|
||||
Future<void> _openDrama(Drama drama, {String? episodeId}) async {
|
||||
await playDramaFromCatalog(context, drama, episodeId: episodeId);
|
||||
}
|
||||
}
|
||||
|
||||
class _KeepAliveTab extends StatefulWidget {
|
||||
const _KeepAliveTab({super.key, required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
State<_KeepAliveTab> createState() => _KeepAliveTabState();
|
||||
}
|
||||
|
||||
class _KeepAliveTabState extends State<_KeepAliveTab>
|
||||
with AutomaticKeepAliveClientMixin<_KeepAliveTab> {
|
||||
@override
|
||||
bool get wantKeepAlive => true;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
super.build(context);
|
||||
return widget.child;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user