Skip to content

Commit

Permalink
fix: dismiss notification indicator on tap icon (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
poppingmoon authored Mar 31, 2024
1 parent 8ecc279 commit d7281b8
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 89 deletions.
90 changes: 47 additions & 43 deletions lib/view/widget/follow_requests_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,53 +54,57 @@ class FollowRequestsListView extends HookConsumerWidget {
});
final centerKey = useMemoized(() => GlobalKey(), []);

return Stack(
alignment: Alignment.topCenter,
children: [
CustomScrollView(
controller: controller,
center: centerKey,
slivers: [
SliverList.separated(
itemBuilder: (context, index) => FollowRequestTile(
account: account,
user: nextRequests.value[index],
onDismissed: () => nextRequests.value = nextRequests.value
.whereIndexed((i, _) => i != index)
.toList(),
return RefreshIndicator(
onRefresh: () =>
ref.refresh(followRequestsNotifierProvider(account).future),
child: Stack(
alignment: Alignment.topCenter,
children: [
CustomScrollView(
controller: controller,
center: centerKey,
slivers: [
SliverList.separated(
itemBuilder: (context, index) => FollowRequestTile(
account: account,
user: nextRequests.value[index],
onDismissed: () => nextRequests.value = nextRequests.value
.whereIndexed((i, _) => i != index)
.toList(),
),
separatorBuilder: (_, __) => const Divider(height: 0),
itemCount: nextRequests.value.length,
),
separatorBuilder: (_, __) => const Divider(height: 0),
itemCount: nextRequests.value.length,
),
SliverList.separated(
key: centerKey,
itemBuilder: (context, index) => FollowRequestTile(
account: account,
user: requests.value!.items[index].follower,
SliverList.separated(
key: centerKey,
itemBuilder: (context, index) => FollowRequestTile(
account: account,
user: requests.value!.items[index].follower,
),
separatorBuilder: (_, __) => const Divider(height: 0),
itemCount: requests.valueOrNull?.items.length ?? 0,
),
separatorBuilder: (_, __) => const Divider(height: 0),
itemCount: requests.valueOrNull?.items.length ?? 0,
),
SliverToBoxAdapter(
child: PaginationBottomWidget(
paginationState: requests,
noItemsLabel: t.misskey.noFollowRequests,
loadMore: () => ref
.read(followRequestsNotifierProvider(account).notifier)
.loadMore(skipError: true),
SliverToBoxAdapter(
child: PaginationBottomWidget(
paginationState: requests,
noItemsLabel: t.misskey.noFollowRequests,
loadMore: () => ref
.read(followRequestsNotifierProvider(account).notifier)
.loadMore(skipError: true),
),
),
),
],
),
if (hasNewRequest.value)
Positioned(
top: 16.0,
child: ElevatedButton(
onPressed: () => controller.scrollToTop(),
child: Text(t.aria.newFollowRequestReceived),
),
],
),
],
if (hasNewRequest.value)
Positioned(
top: 16.0,
child: ElevatedButton(
onPressed: () => controller.scrollToTop(),
child: Text(t.aria.newFollowRequestReceived),
),
),
],
),
);
}
}
Expand Down
85 changes: 44 additions & 41 deletions lib/view/widget/notifications_list_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class NotificationsListView extends HookConsumerWidget {
controller.addListener(() {
if (controller.position.extentBefore == 0) {
hasNewNotification.value = false;
if (i != null && i.hasUnreadAnnouncement) {
if (i != null && i.hasUnreadNotification) {
ref.read(iNotifierProvider(account).notifier).readNotifications();
}
}
Expand All @@ -54,50 +54,53 @@ class NotificationsListView extends HookConsumerWidget {
});
final centerKey = useMemoized(() => GlobalKey(), []);

return Stack(
alignment: Alignment.topCenter,
children: [
CustomScrollView(
controller: controller,
center: centerKey,
slivers: [
SliverList.separated(
itemBuilder: (context, index) => NotificationWidget(
account: account,
notification: nextNotifications.value[index],
return RefreshIndicator(
onRefresh: () => ref.read(iNotifierProvider(account).future),
child: Stack(
alignment: Alignment.topCenter,
children: [
CustomScrollView(
controller: controller,
center: centerKey,
slivers: [
SliverList.separated(
itemBuilder: (context, index) => NotificationWidget(
account: account,
notification: nextNotifications.value[index],
),
separatorBuilder: (_, __) => const Divider(height: 0),
itemCount: nextNotifications.value.length,
),
separatorBuilder: (_, __) => const Divider(height: 0),
itemCount: nextNotifications.value.length,
),
SliverList.separated(
key: centerKey,
itemBuilder: (context, index) => NotificationWidget(
account: account,
notification: notifications.value!.items[index],
SliverList.separated(
key: centerKey,
itemBuilder: (context, index) => NotificationWidget(
account: account,
notification: notifications.value!.items[index],
),
separatorBuilder: (_, __) => const Divider(height: 0),
itemCount: notifications.valueOrNull?.items.length ?? 0,
),
separatorBuilder: (_, __) => const Divider(height: 0),
itemCount: notifications.valueOrNull?.items.length ?? 0,
),
SliverToBoxAdapter(
child: PaginationBottomWidget(
paginationState: notifications,
noItemsLabel: t.misskey.noNotes,
loadMore: () => ref
.read(notificationsNotifierProvider(account).notifier)
.loadMore(skipError: true),
SliverToBoxAdapter(
child: PaginationBottomWidget(
paginationState: notifications,
noItemsLabel: t.misskey.noNotes,
loadMore: () => ref
.read(notificationsNotifierProvider(account).notifier)
.loadMore(skipError: true),
),
),
),
],
),
if (hasNewNotification.value)
Positioned(
top: 16.0,
child: ElevatedButton(
onPressed: () => controller.scrollToTop(),
child: Text(t.aria.newNotificationReceived),
),
],
),
],
if (hasNewNotification.value)
Positioned(
top: 16.0,
child: ElevatedButton(
onPressed: () => controller.scrollToTop(),
child: Text(t.aria.newNotificationReceived),
),
),
],
),
);
}
}
41 changes: 38 additions & 3 deletions lib/view/widget/timeline_drawer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,29 @@ class TimelineDrawer extends ConsumerWidget {
initiallyExpanded: account == currentAccount,
children: [
ListTile(
leading: const Icon(Icons.notifications),
leading: Stack(
children: [
const Icon(Icons.notifications),
if (i?.hasUnreadNotification ?? false)
DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.primary,
),
child: const SizedBox(
height: 12.0,
width: 12.0,
),
),
],
),
title: Text(t.misskey.notifications),
onTap: () => context.push('/$account/notifications'),
onTap: () {
ref
.read(iNotifierProvider(account).notifier)
.readNotifications();
context.push('/$account/notifications');
},
),
ListTile(
leading: const Icon(Icons.attach_file),
Expand All @@ -99,7 +119,22 @@ class TimelineDrawer extends ConsumerWidget {
onTap: () => context.push('/$account/explore'),
),
ListTile(
leading: const Icon(Icons.campaign),
leading: Stack(
children: [
const Icon(Icons.campaign),
if (i?.hasUnreadAnnouncement ?? false)
DecoratedBox(
decoration: BoxDecoration(
shape: BoxShape.circle,
color: Theme.of(context).colorScheme.primary,
),
child: const SizedBox(
height: 12.0,
width: 12.0,
),
),
],
),
title: Text(t.misskey.announcements),
onTap: () => context.push('/$account/announcements'),
),
Expand Down
9 changes: 7 additions & 2 deletions lib/view/widget/timeline_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ class TimelineMenu extends ConsumerWidget {
Card(
clipBehavior: Clip.hardEdge,
child: InkWell(
onTap: () => context.push('/$account/notifications'),
onTap: () {
ref
.read(iNotifierProvider(account).notifier)
.readNotifications();
context.push('/$account/notifications');
},
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Expand Down Expand Up @@ -136,7 +141,7 @@ class TimelineMenu extends ConsumerWidget {
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Icon(Icons.list),
FittedBox(child: Text(t.misskey.announcements)),
FittedBox(child: Text(t.misskey.userList)),
],
),
),
Expand Down

0 comments on commit d7281b8

Please sign in to comment.