Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

navigate home pages for deeplink #2057

Merged
merged 4 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/screen/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import 'package:autonomy_flutter/screen/exhibition_details/exhibition_detail_blo
import 'package:autonomy_flutter/screen/exhibition_details/exhibition_detail_page.dart';
import 'package:autonomy_flutter/screen/feralfile_artwork_preview/feralfile_artwork_preview_bloc.dart';
import 'package:autonomy_flutter/screen/feralfile_artwork_preview/feralfile_artwork_preview_page.dart';
import 'package:autonomy_flutter/screen/feralfile_home/feralfile_home.dart';
import 'package:autonomy_flutter/screen/feralfile_series/feralfile_series_bloc.dart';
import 'package:autonomy_flutter/screen/feralfile_series/feralfile_series_page.dart';
import 'package:autonomy_flutter/screen/gallery/gallery_bloc.dart';
Expand Down Expand Up @@ -145,6 +146,7 @@ import 'package:page_transition/page_transition.dart';

GlobalKey<HomeNavigationPageState> homePageKey = GlobalKey();
GlobalKey<HomeNavigationPageState> homePageNoTransactionKey = GlobalKey();
GlobalKey<FeralfileHomePageState> feralFileHomeKey = GlobalKey();

class AppRouter {
static const createPlayListPage = 'create_playlist_page';
Expand Down Expand Up @@ -241,6 +243,11 @@ class AppRouter {
static const artistWorksPage = 'artist_works_page';
static const artistExhibitionsPage = 'artist_exhibitions_page';
static const artistPostsPage = 'artist_posts_page';
static const featuredPage = 'featured_page';
static const artworksPage = 'artworks_page';
static const artistsPage = 'artists_page';
static const curatorsPage = 'curators_page';
static const rAndDPage = 'r_and_d_page';

static Route<dynamic> onGenerateRoute(RouteSettings settings) {
final ethereumBloc = EthereumBloc(injector(), injector());
Expand Down
40 changes: 25 additions & 15 deletions lib/screen/feralfile_home/feralfile_home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class FeralfileHomePageState extends State<FeralfileHomePage>
final _exhibitionViewKey = GlobalKey<ExploreExhibitionState>();
final _artistViewKey = GlobalKey<ExploreArtistViewState>();
final _curatorViewKey = GlobalKey<ExploreCuratorViewState>();
final GlobalKey<_ItemExpandedWidgetState> _itemExpandedKey = GlobalKey();

@override
void initState() {
Expand Down Expand Up @@ -188,6 +189,7 @@ class FeralfileHomePageState extends State<FeralfileHomePage>
builder: (context, state) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 8),
child: ItemExpandedWidget(
key: _itemExpandedKey,
items: _getItemList(state),
selectedIndex: _selectedIndex,
iconOnExpanded: RotatedBox(
Expand Down Expand Up @@ -217,6 +219,17 @@ class FeralfileHomePageState extends State<FeralfileHomePage>
);
}

void jumpToTab(FeralfileHomeTab tab) {
_selectTab(tab);
_itemExpandedKey.currentState?.selectItem(tab.index);
}

void _selectTab(FeralfileHomeTab tab) {
setState(() {
_selectedIndex = tab.index;
});
}

List<Item> _getItemList(FeralfileHomeBlocState state) {
final numberFormater = NumberFormat('#,###', 'en_US');
return [
Expand All @@ -227,9 +240,7 @@ class FeralfileHomePageState extends State<FeralfileHomePage>
? numberFormater.format(state.featuredArtworks!.length)
: '-',
onSelected: () {
setState(() {
_selectedIndex = FeralfileHomeTab.featured.index;
});
_selectTab(FeralfileHomeTab.featured);
},
),
Item(
Expand All @@ -239,9 +250,7 @@ class FeralfileHomePageState extends State<FeralfileHomePage>
? numberFormater.format(state.exploreStatisticsData!.totalArtwork)
: '-',
onSelected: () {
setState(() {
_selectedIndex = FeralfileHomeTab.artworks.index;
});
_selectTab(FeralfileHomeTab.artworks);
},
),
Item(
Expand All @@ -252,9 +261,7 @@ class FeralfileHomePageState extends State<FeralfileHomePage>
.format(state.exploreStatisticsData!.totalExhibition)
: '-',
onSelected: () {
setState(() {
_selectedIndex = FeralfileHomeTab.exhibitions.index;
});
_selectTab(FeralfileHomeTab.exhibitions);
},
),
Item(
Expand All @@ -264,9 +271,7 @@ class FeralfileHomePageState extends State<FeralfileHomePage>
? numberFormater.format(state.exploreStatisticsData!.totalArtist)
: '-',
onSelected: () {
setState(() {
_selectedIndex = FeralfileHomeTab.artists.index;
});
_selectTab(FeralfileHomeTab.artists);
}),
Item(
id: FeralfileHomeTab.curators.index.toString(),
Expand All @@ -275,9 +280,7 @@ class FeralfileHomePageState extends State<FeralfileHomePage>
? numberFormater.format(state.exploreStatisticsData!.totalCurator)
: '-',
onSelected: () {
setState(() {
_selectedIndex = FeralfileHomeTab.curators.index;
});
_selectTab(FeralfileHomeTab.curators);
},
),
];
Expand Down Expand Up @@ -429,6 +432,13 @@ class _ItemExpandedWidgetState extends State<ItemExpandedWidget> {
_selectedIndex = widget.selectedIndex;
}

void selectItem(int index) {
setState(() {
_selectedIndex = index;
_isExpanded = false;
});
}

@override
Widget build(BuildContext context) => TapRegion(
onTapOutside: (event) {
Expand Down
2 changes: 1 addition & 1 deletion lib/screen/feralfile_home/list_exhibition_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class ExploreExhibitionState extends State<ExploreExhibition> {
} else if (_exhibitions!.isEmpty) {
return _emptyView(context);
} else {
return Expanded(child: _exhibitionView(context, _exhibitions!));
return _exhibitionView(context, _exhibitions!);
}
}

Expand Down
15 changes: 7 additions & 8 deletions lib/screen/home/home_navigation_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ class HomeNavigationPageState extends State<HomeNavigationPage>
PageController? _pageController;
late List<Widget> _pages;
final GlobalKey<DailyWorkPageState> _dailyWorkKey = GlobalKey();
final GlobalKey<FeralfileHomePageState> _feralfileHomePageKey = GlobalKey();
final _configurationService = injector<ConfigurationService>();
late Timer? _timer;
final _clientTokenService = injector<ClientTokenService>();
Expand Down Expand Up @@ -129,15 +128,15 @@ class HomeNavigationPageState extends State<HomeNavigationPage>
}

Future<void> openExhibition(String exhibitionId) async {
await _onItemTapped(HomeNavigatorTab.explore.index);
await onItemTapped(HomeNavigatorTab.explore.index);
}

Future<void> _onItemTapped(int index) async {
Future<void> onItemTapped(int index) async {
if (index < _pages.length) {
// handle scroll to top when tap on the same tab
if (_selectedIndex == index) {
if (index == HomeNavigatorTab.explore.index) {
_feralfileHomePageKey.currentState?.scrollToTop();
feralFileHomeKey.currentState?.scrollToTop();
} else if (index == HomeNavigatorTab.daily.index) {
_dailyWorkKey.currentState?.scrollToTop();
}
Expand Down Expand Up @@ -218,7 +217,7 @@ class HomeNavigationPageState extends State<HomeNavigationPage>
onTap: () {
Navigator.of(context).popAndPushNamed(AppRouter.scanQRPage,
arguments:
ScanQRPagePayload(scannerItem: ScannerItem.GLOBAL));
const ScanQRPagePayload(scannerItem: ScannerItem.GLOBAL));
},
),
OptionItem(
Expand Down Expand Up @@ -328,7 +327,7 @@ class HomeNavigationPageState extends State<HomeNavigationPage>
),
],
child: FeralfileHomePage(
key: _feralfileHomePageKey,
key: feralFileHomeKey,
)),
];
if (!_configurationService.isReadRemoveSupport()) {
Expand Down Expand Up @@ -611,7 +610,7 @@ class HomeNavigationPageState extends State<HomeNavigationPage>
selectedItemColor: selectedColor,
unselectedItemColor: unselectedColor,
backgroundColor: AppColor.auGreyBackground,
onSelectTab: _onItemTapped,
onSelectTab: onItemTapped,
currentIndex: _selectedIndex,
);
}
Expand Down Expand Up @@ -659,7 +658,7 @@ class HomeNavigationPageState extends State<HomeNavigationPage>
@override
FutureOr<void> afterFirstLayout(BuildContext context) async {
if (widget.payload.startedTab != _initialTab) {
await _onItemTapped(widget.payload.startedTab.index);
await onItemTapped(widget.payload.startedTab.index);
}
await _cloudBackup();
final initialAction = _notificationService.initialAction;
Expand Down
54 changes: 45 additions & 9 deletions lib/service/navigation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ import 'package:autonomy_flutter/model/pair.dart';
import 'package:autonomy_flutter/screen/app_router.dart';
import 'package:autonomy_flutter/screen/artist_details/artist_details_page.dart';
import 'package:autonomy_flutter/screen/detail/artwork_detail_page.dart';
import 'package:autonomy_flutter/screen/feralfile_home/feralfile_home.dart';
import 'package:autonomy_flutter/screen/interactive_postcard/design_stamp.dart';
import 'package:autonomy_flutter/screen/irl_screen/webview_irl_screen.dart';
import 'package:autonomy_flutter/screen/send_receive_postcard/receive_postcard_page.dart';
import 'package:autonomy_flutter/screen/settings/subscription/upgrade_state.dart';
import 'package:autonomy_flutter/shared.dart';
import 'package:autonomy_flutter/util/asset_token_ext.dart';
import 'package:autonomy_flutter/util/error_handler.dart';
import 'package:autonomy_flutter/util/feral_file_custom_tab.dart';
Expand Down Expand Up @@ -532,22 +534,56 @@ class NavigationService {
return;
}
late String route;
HomeNavigatorTab? homeNavigationTab;
FeralfileHomeTab? exploreTab;

/// todo: handle more cases
switch (pair.first) {
case AppRouter.collectionPage:
case AppRouter.dailyWorkPage:
route = AppRouter.homePageNoTransition;
homeNavigationTab = HomeNavigatorTab.daily;
case AppRouter.featuredPage:
route = AppRouter.homePageNoTransition;
homeNavigationTab = HomeNavigatorTab.explore;
exploreTab = FeralfileHomeTab.featured;
case AppRouter.artworksPage:
route = AppRouter.homePageNoTransition;
homeNavigationTab = HomeNavigatorTab.explore;
exploreTab = FeralfileHomeTab.artworks;
case AppRouter.exhibitionsPage:
route = AppRouter.homePageNoTransition;
homeNavigationTab = HomeNavigatorTab.explore;
exploreTab = FeralfileHomeTab.exhibitions;
case AppRouter.artistsPage:
route = AppRouter.homePageNoTransition;
homeNavigationTab = HomeNavigatorTab.explore;
exploreTab = FeralfileHomeTab.artists;
case AppRouter.curatorsPage:
route = AppRouter.homePageNoTransition;
homeNavigationTab = HomeNavigatorTab.explore;
exploreTab = FeralfileHomeTab.curators;
case AppRouter.rAndDPage:
route = AppRouter.homePageNoTransition;
homeNavigationTab = HomeNavigatorTab.explore;
exploreTab = FeralfileHomeTab.rAndD;
default:
route = pair.first;
unawaited(navigateTo(route, arguments: pair.second));
return;
}

unawaited(navigateTo(route, arguments: pair.second));
Future.delayed(const Duration(milliseconds: 300), () {
switch (pair.first) {
case AppRouter.collectionPage:
popToCollection();
default:
break;
popUntilHome();

await Future.delayed(const Duration(milliseconds: 300), () async {
if (homeNavigationTab != null) {
unawaited(
(homePageKey.currentState ?? homePageNoTransactionKey.currentState)
?.onItemTapped(homeNavigationTab.index));

await Future.delayed(const Duration(milliseconds: 300), () {
if (exploreTab != null) {
feralFileHomeKey.currentState?.jumpToTab(exploreTab);
}
});
}
});
}
Expand Down
Loading