2022-02-27 20:43:29 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-07-07 20:40:54 +02:00
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-02-27 20:43:29 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-10-14 23:13:35 +02:00
|
|
|
import 'package:flutter/services.dart';
|
2022-02-27 20:43:29 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2023-11-09 18:19:53 +02:00
|
|
|
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
2023-02-18 04:46:25 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/scroll_notifier.provider.dart';
|
2022-10-14 22:37:15 +02:00
|
|
|
import 'package:immich_mobile/modules/home/providers/multiselect.provider.dart';
|
2024-01-15 17:25:56 +02:00
|
|
|
import 'package:immich_mobile/modules/search/ui/immich_search_bar.dart';
|
2022-02-27 20:43:29 +02:00
|
|
|
import 'package:immich_mobile/routing/router.dart';
|
2023-06-10 20:13:59 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/asset.provider.dart';
|
2023-09-10 14:51:18 +02:00
|
|
|
import 'package:immich_mobile/shared/providers/tab.provider.dart';
|
2022-02-27 20:43:29 +02:00
|
|
|
|
2023-06-10 20:13:59 +02:00
|
|
|
class TabControllerPage extends HookConsumerWidget {
|
2022-02-27 20:43:29 +02:00
|
|
|
const TabControllerPage({Key? key}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2023-06-10 20:13:59 +02:00
|
|
|
final refreshing = ref.watch(assetProvider);
|
|
|
|
|
|
|
|
Widget buildIcon(Widget icon) {
|
|
|
|
if (!refreshing) return icon;
|
|
|
|
return Stack(
|
|
|
|
alignment: Alignment.center,
|
|
|
|
clipBehavior: Clip.none,
|
|
|
|
children: [
|
|
|
|
icon,
|
|
|
|
Positioned(
|
|
|
|
right: -14,
|
|
|
|
child: SizedBox(
|
|
|
|
height: 12,
|
|
|
|
width: 12,
|
|
|
|
child: CircularProgressIndicator(
|
|
|
|
strokeWidth: 2,
|
|
|
|
valueColor: AlwaysStoppedAnimation<Color>(
|
2023-11-09 18:19:53 +02:00
|
|
|
context.primaryColor,
|
2023-06-10 20:13:59 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-02-08 21:42:45 +02:00
|
|
|
navigationRail(TabsRouter tabsRouter) {
|
|
|
|
return NavigationRail(
|
|
|
|
labelType: NavigationRailLabelType.all,
|
|
|
|
selectedIndex: tabsRouter.activeIndex,
|
|
|
|
onDestinationSelected: (index) {
|
2023-02-18 04:46:25 +02:00
|
|
|
// Selected Photos while it is active
|
|
|
|
if (tabsRouter.activeIndex == 0 && index == 0) {
|
|
|
|
// Scroll to top
|
|
|
|
scrollToTopNotifierProvider.scrollToTop();
|
|
|
|
}
|
2024-01-15 17:25:56 +02:00
|
|
|
if (tabsRouter.activeIndex == 1 && index == 1) {
|
|
|
|
// Focus search
|
|
|
|
searchFocusNotifier.requestFocus();
|
|
|
|
}
|
|
|
|
|
2023-02-08 21:42:45 +02:00
|
|
|
HapticFeedback.selectionClick();
|
|
|
|
tabsRouter.setActiveIndex(index);
|
2023-09-10 14:51:18 +02:00
|
|
|
ref.read(tabProvider.notifier).state = TabEnum.values[index];
|
2023-02-08 21:42:45 +02:00
|
|
|
},
|
|
|
|
selectedIconTheme: IconThemeData(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
|
|
|
selectedLabelTextStyle: TextStyle(
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
|
|
|
useIndicator: false,
|
|
|
|
destinations: [
|
|
|
|
NavigationRailDestination(
|
|
|
|
padding: EdgeInsets.only(
|
|
|
|
top: MediaQuery.of(context).padding.top + 4,
|
|
|
|
left: 4,
|
|
|
|
right: 4,
|
|
|
|
bottom: 4,
|
|
|
|
),
|
2023-05-08 21:01:39 +02:00
|
|
|
icon: const Icon(Icons.photo_library_outlined),
|
|
|
|
selectedIcon: const Icon(Icons.photo_library),
|
2023-02-08 21:42:45 +02:00
|
|
|
label: const Text('tab_controller_nav_photos').tr(),
|
|
|
|
),
|
|
|
|
NavigationRailDestination(
|
|
|
|
padding: const EdgeInsets.all(4),
|
2023-02-11 22:23:32 +02:00
|
|
|
icon: const Icon(Icons.search_rounded),
|
|
|
|
selectedIcon: const Icon(Icons.search),
|
2023-02-08 21:42:45 +02:00
|
|
|
label: const Text('tab_controller_nav_search').tr(),
|
|
|
|
),
|
|
|
|
NavigationRailDestination(
|
|
|
|
padding: const EdgeInsets.all(4),
|
2023-02-11 22:23:32 +02:00
|
|
|
icon: const Icon(Icons.share_rounded),
|
|
|
|
selectedIcon: const Icon(Icons.share),
|
2023-02-08 21:42:45 +02:00
|
|
|
label: const Text('tab_controller_nav_sharing').tr(),
|
|
|
|
),
|
|
|
|
NavigationRailDestination(
|
|
|
|
padding: const EdgeInsets.all(4),
|
2023-02-11 22:23:32 +02:00
|
|
|
icon: const Icon(Icons.photo_album_outlined),
|
|
|
|
selectedIcon: const Icon(Icons.photo_album),
|
2023-02-08 21:42:45 +02:00
|
|
|
label: const Text('tab_controller_nav_library').tr(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
bottomNavigationBar(TabsRouter tabsRouter) {
|
2023-02-11 22:23:32 +02:00
|
|
|
return NavigationBar(
|
|
|
|
selectedIndex: tabsRouter.activeIndex,
|
|
|
|
onDestinationSelected: (index) {
|
2023-02-18 04:46:25 +02:00
|
|
|
if (tabsRouter.activeIndex == 0 && index == 0) {
|
|
|
|
// Scroll to top
|
|
|
|
scrollToTopNotifierProvider.scrollToTop();
|
|
|
|
}
|
2024-01-15 17:25:56 +02:00
|
|
|
if (tabsRouter.activeIndex == 1 && index == 1) {
|
|
|
|
// Focus search
|
|
|
|
searchFocusNotifier.requestFocus();
|
|
|
|
}
|
2023-02-11 22:23:32 +02:00
|
|
|
HapticFeedback.selectionClick();
|
|
|
|
tabsRouter.setActiveIndex(index);
|
2023-09-10 14:51:18 +02:00
|
|
|
ref.read(tabProvider.notifier).state = TabEnum.values[index];
|
2023-02-11 22:23:32 +02:00
|
|
|
},
|
|
|
|
destinations: [
|
|
|
|
NavigationDestination(
|
|
|
|
label: 'tab_controller_nav_photos'.tr(),
|
|
|
|
icon: const Icon(
|
2023-05-08 21:01:39 +02:00
|
|
|
Icons.photo_library_outlined,
|
2023-02-11 22:23:32 +02:00
|
|
|
),
|
2023-06-10 20:13:59 +02:00
|
|
|
selectedIcon: buildIcon(
|
|
|
|
Icon(
|
|
|
|
Icons.photo_library,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-06-10 20:13:59 +02:00
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
NavigationDestination(
|
|
|
|
label: 'tab_controller_nav_search'.tr(),
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.search_rounded,
|
|
|
|
),
|
|
|
|
selectedIcon: Icon(
|
|
|
|
Icons.search,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-02-11 22:23:32 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
NavigationDestination(
|
|
|
|
label: 'tab_controller_nav_sharing'.tr(),
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.group_outlined,
|
|
|
|
),
|
|
|
|
selectedIcon: Icon(
|
|
|
|
Icons.group,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-02-11 22:23:32 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
NavigationDestination(
|
|
|
|
label: 'tab_controller_nav_library'.tr(),
|
|
|
|
icon: const Icon(
|
|
|
|
Icons.photo_album_outlined,
|
|
|
|
),
|
2023-06-10 20:13:59 +02:00
|
|
|
selectedIcon: buildIcon(
|
|
|
|
Icon(
|
|
|
|
Icons.photo_album_rounded,
|
2023-11-09 18:19:53 +02:00
|
|
|
color: context.primaryColor,
|
2023-06-10 20:13:59 +02:00
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
),
|
2023-08-19 00:52:40 +02:00
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-10-14 22:37:15 +02:00
|
|
|
final multiselectEnabled = ref.watch(multiselectProvider);
|
2022-02-27 20:43:29 +02:00
|
|
|
return AutoTabsRouter(
|
|
|
|
routes: [
|
|
|
|
const HomeRoute(),
|
|
|
|
SearchRoute(),
|
2022-04-24 04:08:45 +02:00
|
|
|
const SharingRoute(),
|
2023-08-19 00:52:40 +02:00
|
|
|
const LibraryRoute(),
|
2022-02-27 20:43:29 +02:00
|
|
|
],
|
|
|
|
builder: (context, child, animation) {
|
|
|
|
final tabsRouter = AutoTabsRouter.of(context);
|
2022-05-30 00:32:30 +02:00
|
|
|
return WillPopScope(
|
|
|
|
onWillPop: () async {
|
2022-10-21 20:05:44 +02:00
|
|
|
bool atHomeTab = tabsRouter.activeIndex == 0;
|
|
|
|
if (!atHomeTab) {
|
2022-10-17 20:04:17 +02:00
|
|
|
tabsRouter.setActiveIndex(0);
|
2023-02-11 22:23:32 +02:00
|
|
|
}
|
2023-02-10 08:04:41 +02:00
|
|
|
|
2022-10-21 20:05:44 +02:00
|
|
|
return atHomeTab;
|
2022-05-30 00:32:30 +02:00
|
|
|
},
|
2023-02-08 21:42:45 +02:00
|
|
|
child: LayoutBuilder(
|
|
|
|
builder: (context, constraints) {
|
|
|
|
const medium = 600;
|
|
|
|
final Widget? bottom;
|
|
|
|
final Widget body;
|
|
|
|
if (constraints.maxWidth < medium) {
|
|
|
|
// Normal phone width
|
2023-02-18 04:46:25 +02:00
|
|
|
bottom = bottomNavigationBar(tabsRouter);
|
2023-02-08 21:42:45 +02:00
|
|
|
body = FadeTransition(
|
|
|
|
opacity: animation,
|
|
|
|
child: child,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
// Medium tablet width
|
|
|
|
bottom = null;
|
|
|
|
body = Row(
|
|
|
|
children: [
|
|
|
|
navigationRail(tabsRouter),
|
|
|
|
Expanded(
|
|
|
|
child: FadeTransition(
|
|
|
|
opacity: animation,
|
|
|
|
child: child,
|
2022-07-13 14:23:48 +02:00
|
|
|
),
|
2023-02-08 21:42:45 +02:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
2023-02-11 22:23:32 +02:00
|
|
|
}
|
|
|
|
return Scaffold(
|
2023-03-25 05:44:53 +02:00
|
|
|
body: HeroControllerScope(
|
|
|
|
controller: HeroController(),
|
|
|
|
child: body,
|
|
|
|
),
|
2023-02-11 22:23:32 +02:00
|
|
|
bottomNavigationBar: multiselectEnabled ? null : bottom,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
2022-02-27 20:43:29 +02:00
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|