2021-11-14 18:47:18 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
2022-04-02 16:18:36 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
2021-11-15 07:24:05 +01:00
|
|
|
import 'package:salomon_bottom_bar/salomon_bottom_bar.dart';
|
2021-11-14 18:47:18 +01:00
|
|
|
|
2022-04-02 16:18:36 +02:00
|
|
|
import 'package:fluffychat/config/app_config.dart';
|
2021-11-14 18:47:18 +01:00
|
|
|
import 'package:fluffychat/pages/chat_list/chat_list.dart';
|
2022-04-02 16:18:36 +02:00
|
|
|
import 'package:fluffychat/pages/chat_list/spaces_drawer.dart';
|
2022-04-03 19:00:35 +02:00
|
|
|
import 'package:fluffychat/pages/chat_list/spaces_entry.dart';
|
2021-11-14 18:47:18 +01:00
|
|
|
import 'package:fluffychat/widgets/avatar.dart';
|
2021-11-15 10:05:15 +01:00
|
|
|
import 'package:fluffychat/widgets/matrix.dart';
|
2021-11-14 18:47:18 +01:00
|
|
|
|
2022-04-02 16:18:36 +02:00
|
|
|
const kSpacesBottomBarHeight = 56.0;
|
|
|
|
|
2021-11-14 18:47:18 +01:00
|
|
|
class SpacesBottomBar extends StatelessWidget {
|
|
|
|
final ChatListController controller;
|
2022-04-02 16:18:36 +02:00
|
|
|
|
2022-01-29 12:35:03 +01:00
|
|
|
const SpacesBottomBar(this.controller, {Key? key}) : super(key: key);
|
2021-11-14 18:47:18 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2021-11-15 07:24:05 +01:00
|
|
|
return Material(
|
2022-04-02 16:18:36 +02:00
|
|
|
color: Theme.of(context).navigationBarTheme.backgroundColor,
|
2021-11-15 07:24:05 +01:00
|
|
|
elevation: 6,
|
2022-04-02 16:18:36 +02:00
|
|
|
borderRadius: const BorderRadius.vertical(
|
|
|
|
top: Radius.circular(AppConfig.borderRadius)),
|
|
|
|
clipBehavior: Clip.hardEdge,
|
2021-11-23 11:37:25 +01:00
|
|
|
child: SafeArea(
|
|
|
|
child: StreamBuilder<Object>(
|
2022-04-02 16:18:36 +02:00
|
|
|
stream: Matrix.of(context).client.onSync.stream.where((sync) =>
|
|
|
|
(sync.rooms?.join?.values.any((r) =>
|
|
|
|
r.state?.any((s) => s.type.startsWith('m.space')) ??
|
|
|
|
false) ??
|
|
|
|
false) ||
|
|
|
|
(sync.rooms?.leave?.isNotEmpty ?? false)),
|
|
|
|
builder: (context, snapshot) {
|
|
|
|
return SingleChildScrollView(
|
|
|
|
controller: controller.snappingSheetScrollContentController,
|
|
|
|
child: AnimatedBuilder(
|
|
|
|
child: _SpacesBottomNavigation(controller: controller),
|
|
|
|
builder: (context, child) {
|
|
|
|
if (controller.snappingSheetContainerSize == null) {
|
|
|
|
return child!;
|
|
|
|
}
|
|
|
|
final rawPosition =
|
|
|
|
controller.snappingSheetController.currentPosition;
|
|
|
|
final position = rawPosition /
|
|
|
|
controller.snappingSheetContainerSize!.maxHeight;
|
|
|
|
|
|
|
|
if (rawPosition <= kSpacesBottomBarHeight) {
|
|
|
|
return child!;
|
|
|
|
} else if (position >= 0.5) {
|
|
|
|
return SpacesDrawer(controller: controller);
|
|
|
|
} else {
|
|
|
|
final normalized = (rawPosition - kSpacesBottomBarHeight) /
|
|
|
|
(controller.snappingSheetContainerSize!.maxHeight -
|
|
|
|
kSpacesBottomBarHeight) *
|
|
|
|
2;
|
|
|
|
var boxHeight = (1 - normalized) * kSpacesBottomBarHeight;
|
|
|
|
if (boxHeight < 0) boxHeight = 0;
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
children: [
|
|
|
|
SizedBox(
|
|
|
|
height: boxHeight,
|
|
|
|
child: ClipRect(
|
|
|
|
clipBehavior: Clip.hardEdge,
|
|
|
|
child: Opacity(
|
|
|
|
opacity: 1 - normalized, child: child!)),
|
|
|
|
),
|
|
|
|
Opacity(
|
|
|
|
opacity: normalized,
|
|
|
|
child: SpacesDrawer(controller: controller),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
animation: controller.snappingSheetController,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SpacesBottomNavigation extends StatelessWidget {
|
|
|
|
final ChatListController controller;
|
|
|
|
|
|
|
|
const _SpacesBottomNavigation({Key? key, required this.controller})
|
|
|
|
: super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final currentIndex = controller.activeSpaceId == null
|
|
|
|
? 1
|
|
|
|
: controller.spaces
|
|
|
|
.indexWhere((space) => controller.activeSpaceId == space.id) +
|
|
|
|
2;
|
|
|
|
|
|
|
|
return Container(
|
|
|
|
height: 56,
|
|
|
|
alignment: Alignment.center,
|
|
|
|
child: SingleChildScrollView(
|
|
|
|
scrollDirection: Axis.horizontal,
|
|
|
|
child: SalomonBottomBar(
|
|
|
|
itemPadding: const EdgeInsets.all(8),
|
|
|
|
currentIndex: currentIndex,
|
|
|
|
onTap: (i) => i == 0
|
|
|
|
? controller.expandSpaces()
|
|
|
|
: i == 1
|
|
|
|
? controller.setActiveSpacesEntry(
|
|
|
|
context,
|
|
|
|
null,
|
|
|
|
)
|
|
|
|
: controller.setActiveSpacesEntry(
|
2021-11-23 11:37:25 +01:00
|
|
|
context,
|
2022-04-03 19:00:35 +02:00
|
|
|
controller.spacesEntries[i],
|
2021-11-15 10:09:23 +01:00
|
|
|
),
|
2022-04-02 16:18:36 +02:00
|
|
|
selectedItemColor: Theme.of(context).colorScheme.primary,
|
|
|
|
items: [
|
|
|
|
SalomonBottomBarItem(
|
|
|
|
icon: const Icon(Icons.keyboard_arrow_up),
|
|
|
|
title: Text(L10n.of(context)!.showSpaces),
|
|
|
|
),
|
|
|
|
...controller.spacesEntries
|
|
|
|
.map((space) => _buildSpacesEntryUI(context, space))
|
|
|
|
.toList(),
|
|
|
|
],
|
|
|
|
),
|
2021-11-23 11:37:25 +01:00
|
|
|
),
|
2021-11-14 18:47:18 +01:00
|
|
|
);
|
|
|
|
}
|
2022-04-03 19:00:35 +02:00
|
|
|
|
|
|
|
SalomonBottomBarItem _buildSpacesEntryUI(
|
|
|
|
BuildContext context, SpacesEntry entry) {
|
|
|
|
final space = entry.getSpace(context);
|
|
|
|
if (space != null) {
|
|
|
|
return SalomonBottomBarItem(
|
|
|
|
icon: InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(28),
|
|
|
|
onTap: () => controller.setActiveSpacesEntry(
|
|
|
|
context,
|
|
|
|
entry,
|
|
|
|
),
|
|
|
|
onLongPress: () => controller.editSpace(context, space.id),
|
|
|
|
child: Avatar(
|
|
|
|
mxContent: space.avatar,
|
|
|
|
name: space.displayname,
|
|
|
|
size: 24,
|
|
|
|
fontSize: 12,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
title: Text(entry.getName(context)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return SalomonBottomBarItem(
|
|
|
|
icon: entry.getIcon(false),
|
|
|
|
activeIcon: entry.getIcon(true),
|
|
|
|
title: Text(entry.getName(context)),
|
|
|
|
);
|
|
|
|
}
|
2021-11-14 18:47:18 +01:00
|
|
|
}
|