feat: Dynamic appbar elevation and FAB in chat list

This commit is contained in:
Christian Pauly 2021-05-30 12:41:10 +02:00
parent 34b8751328
commit 3d7e1554bf
2 changed files with 28 additions and 10 deletions

View File

@ -32,6 +32,7 @@ class ChatList extends StatefulWidget {
} }
class ChatListController extends State<ChatList> { class ChatListController extends State<ChatList> {
final ScrollController scrollController = ScrollController();
StreamSubscription _intentDataStreamSubscription; StreamSubscription _intentDataStreamSubscription;
StreamSubscription _intentFileStreamSubscription; StreamSubscription _intentFileStreamSubscription;
@ -42,6 +43,15 @@ class ChatListController extends State<ChatList> {
String get activeChat => VRouter.of(context).pathParameters['roomid']; String get activeChat => VRouter.of(context).pathParameters['roomid'];
bool scrolledTop = true;
void updateScrolledTop() {
final newScrolledTop = scrollController.offset == 0;
if (scrolledTop != newScrolledTop) {
setState(() => scrolledTop = newScrolledTop);
}
}
void _processIncomingSharedFiles(List<SharedMediaFile> files) { void _processIncomingSharedFiles(List<SharedMediaFile> files) {
if (files?.isEmpty ?? true) return; if (files?.isEmpty ?? true) return;
VRouter.of(context).push('/rooms'); VRouter.of(context).push('/rooms');
@ -109,6 +119,7 @@ class ChatListController extends State<ChatList> {
@override @override
void initState() { void initState() {
_initReceiveSharingIntent(); _initReceiveSharingIntent();
scrollController.addListener(updateScrolledTop);
super.initState(); super.initState();
} }
@ -117,6 +128,7 @@ class ChatListController extends State<ChatList> {
_intentDataStreamSubscription?.cancel(); _intentDataStreamSubscription?.cancel();
_intentFileStreamSubscription?.cancel(); _intentFileStreamSubscription?.cancel();
_intentUriStreamSubscription?.cancel(); _intentUriStreamSubscription?.cancel();
scrollController.removeListener(updateScrolledTop);
super.dispose(); super.dispose();
} }

View File

@ -1,5 +1,4 @@
import 'package:famedlysdk/famedlysdk.dart'; import 'package:famedlysdk/famedlysdk.dart';
import 'package:fluffychat/config/themes.dart';
import 'package:fluffychat/pages/chat_list.dart'; import 'package:fluffychat/pages/chat_list.dart';
import 'package:fluffychat/widgets/connection_status_header.dart'; import 'package:fluffychat/widgets/connection_status_header.dart';
import 'package:fluffychat/widgets/list_items/chat_list_item.dart'; import 'package:fluffychat/widgets/list_items/chat_list_item.dart';
@ -35,10 +34,7 @@ class ChatListView extends StatelessWidget {
}, },
child: Scaffold( child: Scaffold(
appBar: AppBar( appBar: AppBar(
elevation: MediaQuery.of(context).size.width > elevation: controller.scrolledTop ? 0 : null,
FluffyThemes.columnWidth * 2
? 1
: null,
leading: selectMode == SelectMode.normal leading: selectMode == SelectMode.normal
? null ? null
: IconButton( : IconButton(
@ -207,6 +203,7 @@ class ChatListView extends StatelessWidget {
final totalCount = rooms.length; final totalCount = rooms.length;
return ListView.builder( return ListView.builder(
itemCount: totalCount, itemCount: totalCount,
controller: controller.scrollController,
itemBuilder: (BuildContext context, int i) => itemBuilder: (BuildContext context, int i) =>
ChatListItem( ChatListItem(
rooms[i], rooms[i],
@ -233,7 +230,16 @@ class ChatListView extends StatelessWidget {
), ),
]), ]),
floatingActionButton: selectMode == SelectMode.normal floatingActionButton: selectMode == SelectMode.normal
? FloatingActionButton( ? controller.scrolledTop
? FloatingActionButton.extended(
heroTag: 'main_fab',
onPressed: () =>
VRouter.of(context).push('/newprivatechat'),
icon: Icon(CupertinoIcons.chat_bubble),
label: Text(L10n.of(context).newChat),
)
: FloatingActionButton(
heroTag: 'main_fab',
onPressed: () => onPressed: () =>
VRouter.of(context).push('/newprivatechat'), VRouter.of(context).push('/newprivatechat'),
child: Icon(CupertinoIcons.chat_bubble), child: Icon(CupertinoIcons.chat_bubble),