Skip to content

Commit

Permalink
fix scroll to newsest post on subscription page"
Browse files Browse the repository at this point in the history
"
  • Loading branch information
dasmikko committed Mar 17, 2023
1 parent 2d5f954 commit 09faf93
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 17 deletions.
3 changes: 2 additions & 1 deletion fastlane/metadata/android/en-US/changelogs/83.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ Version 2.3.3 *(TBD)*
----------------------------

New

* A simple way to block a user. The content of a user wont be displayed.

Changes


Fixes
* Couldn't leave thread if post editor wasn't empty
* When tapping the new post button on the subscription screen wouldn't scroll the to newest post
1 change: 1 addition & 0 deletions lib/screens/subscriptions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class _SubscriptionsScreenState extends State<SubscriptionsScreen> {
return SubscriptionListItem(
threadDetails: alert.thread,
unreadPosts: alert.unreadPosts,
firstUnreadId: alert.firstUnreadId,
);
},
),
Expand Down
20 changes: 12 additions & 8 deletions lib/screens/thread.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,18 @@ class _ThreadScreenState extends State<ThreadScreen>
subscription = threadController.data.listen((Thread? thread) async {
await Future.delayed(Duration(milliseconds: 100));

// Find the index of the post to scroll to
int postIndex =
thread!.posts!.indexWhere((o) => o.id == this.widget.linkedPostId) +
1;

// If we can't find the postIndex, just scroll to the top.
threadController.itemScrollController
.jumpTo(index: postIndex == -1 ? 0 : postIndex);
if (this.widget.linkedPostId != null) {
// Find the index of the post to scroll to
int postIndex =
thread!.posts!.indexWhere((o) => o.id == this.widget.linkedPostId) +
1;

print(postIndex);

// If we can't find the postIndex, just scroll to the top.
threadController.itemScrollController
.jumpTo(index: postIndex == -1 ? 0 : postIndex);
}

// Stop listening for more change, as we will never have to scroll to specific post anymore
subscription.cancel();
Expand Down
12 changes: 5 additions & 7 deletions lib/widgets/shared/threadListItem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import 'package:knocky/widgets/InkWellOnWidget.dart';
import 'dart:ui' as ui;
import 'package:timeago/timeago.dart' as timeago;
import 'package:knocky/screens/thread.dart';
import 'package:get/get.dart';

class ThreadListItem extends StatelessWidget {
final dynamic threadDetails;
Expand Down Expand Up @@ -111,13 +112,10 @@ class ThreadListItem extends StatelessWidget {
@protected
void onTapUnreadPostsButton(
BuildContext context, int unreadCount, int? totalCount) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => ThreadScreen(
id: threadDetails.id,
page: PostsPerPage.unreadPostsPage(unreadCount, totalCount!),
linkedPostId: threadDetails.firstUnreadId)));
Get.to(() => ThreadScreen(
id: threadDetails.id,
page: PostsPerPage.unreadPostsPage(unreadCount, totalCount!),
linkedPostId: threadDetails.firstUnreadId));
}

@protected
Expand Down
13 changes: 12 additions & 1 deletion lib/widgets/subscriptions/subscriptionListItem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ import 'package:knocky/widgets/shared/threadListItem.dart';

class SubscriptionListItem extends ThreadListItem {
final SubforumThread? threadDetails;
final firstUnreadId;
final int? unreadPosts;
final SubscriptionController subscriptionController =
Get.put(SubscriptionController());

SubscriptionListItem({required this.threadDetails, this.unreadPosts})
SubscriptionListItem(
{required this.threadDetails, this.unreadPosts, this.firstUnreadId})
: super(threadDetails: threadDetails);

@override
Expand All @@ -42,6 +44,15 @@ class SubscriptionListItem extends ThreadListItem {
Get.to(() => ThreadScreen(id: threadDetails!.id, page: page));
}

@override
void onTapUnreadPostsButton(
BuildContext context, int unreadCount, int? totalCount) {
Get.to(() => ThreadScreen(
id: threadDetails!.id,
page: PostsPerPage.unreadPostsPage(unreadCount, totalCount!),
linkedPostId: firstUnreadId));
}

Widget longPressBottomSheetContent() {
return Container(
color: Get.theme.bottomAppBarTheme.color,
Expand Down

0 comments on commit 09faf93

Please sign in to comment.