Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRAFT: Hide menus on scroll #257

Closed

Conversation

Fmstrat
Copy link
Contributor

@Fmstrat Fmstrat commented Jul 6, 2023

@hjiangsu This is a very first-draft of menu hiding on scroll. There are some commented items that I'm not sure of the full impact:

These were required to make the hiding work, but I'm unfamiliar with Dart and just doing this in spare time ;)

I also can't test horizontal swipes in the Android Emulator for some reason. Lastly, I didn't focus on the bottom bar yet as I'd like to know if it all works for you with horizontal swipes, etc.

Addresses: #74

@hjiangsu
Copy link
Member

hjiangsu commented Jul 6, 2023

I just took a quick look at the code, haven't ran it myself yet, but it seems like it's okay for now. Just a couple of points:

  • I'm a bit wary of removing the scrollController from the ListView because that is what controls when more posts are fetched based on the scroll distance
  • I would have to do some profiling on this change, to see if its still cleaning up the ListView as expected. I'm not too familiar myself with how the nested scroll view works, but from what I've experienced with SingleChildScrollView and ListView.builder, there can be cases where the ListView fails to clean up after itself and causes memory issues (which then causes lag and performance issues)

@Fmstrat
Copy link
Contributor Author

Fmstrat commented Jul 6, 2023

The commit I just added prints out endScroll when it gets to the end. As I only had a few minutes I didn't take the time to figure out how to get the GetCommunityPostsEvent to call from there, though.

NOTE: Hot reload won't work for the print out since it's in the state. You'll need a full reload (R)

@Fmstrat
Copy link
Contributor Author

Fmstrat commented Jul 6, 2023

I also think we could consider switching away from the ListView altogether and using a MasonryGridView (which is a Sliver style widget for good performance and includes the same builder feature as ListView for caching since it seems to be a GridView. This way we can use a crossAxisCount of 1 on phones, and 2 on tablets. I'm testing it out now and it seems to work quite well. (I'll make another PR when it's ready to show off)

@Fmstrat
Copy link
Contributor Author

Fmstrat commented Jul 6, 2023

As example, converting from ListView to MasonryGridView and setting the columns to 2 immediately worked with dynamic hights:
Screenshot_1688680782

@Fmstrat
Copy link
Contributor Author

Fmstrat commented Jul 6, 2023

Honestly this is pretty amazing, it's performing fantastically and was only a few lines of code change. I will make a new PR now, and revise this one once you take a look at that (as this should still apply).

@hjiangsu
Copy link
Member

hjiangsu commented Jul 7, 2023

Sorry, I've been really busy with work and other stuff today so I couldn't reply earlier but wow, that looks really good for a test!

I'll reply with some more details when I can but first glance, I think switching to MasonryGridView seems to be the way to go, especially since it supports columns natively

I can do some profiling when I have the chance to double check for memory issues or performance regressions but good work!

@Fmstrat
Copy link
Contributor Author

Fmstrat commented Jul 7, 2023

No need to apologize, you should see how slow I am on my own repos 😉

@hjiangsu
Copy link
Member

@Fmstrat Do you still consider this to be a draft, or should I take another look at the code?

Copy link
Member

@hjiangsu hjiangsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just added a quick review of the code!

@@ -12,6 +12,7 @@ import 'package:thunder/community/widgets/post_card_list.dart';
import 'package:thunder/core/auth/bloc/auth_bloc.dart';
import 'package:thunder/shared/error_message.dart';
import 'package:thunder/shared/sort_picker.dart';
import 'dart:developer';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a function which requires this package? This seems oddly specific

if (globalKey.currentState!.innerController.position.pixels >= globalKey.currentState!.innerController.position.maxScrollExtent * 0.7) {
print('endScroll');
// How do we call this from here?
// context.read<CommunityBloc>().add(GetCommunityPostsEvent(communityId: widget.communityId));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, we won't be able to call this function in the initState function since it has no access to the context.

One "hacky" way to pass in the context is to allow CommunityPage to accept a BuildContext as one of its parameters and then use that context here. However, I'm not sure if that's the best way to go about it

@Fmstrat
Copy link
Contributor Author

Fmstrat commented Jul 12, 2023

I will take a look when I can, but yes, this is definitely still draft. It will need to be merged into the new 2-column code, and of course the review items above are still outstanding issues. I also think we need to find a way to hide the bottom bar as well as the top bar.

@hjiangsu
Copy link
Member

Sounds good! Let me know if you want me to help with some of this

@Fmstrat
Copy link
Contributor Author

Fmstrat commented Jul 12, 2023

Sounds good! Let me know if you want me to help with some of this

If you feel like it, go for it! I'm pretty busy right now and will be traveling next week.

@tom-james-watson
Copy link
Contributor

Personally I dislike menus auto-hiding on scroll, though I feel like I'm in the minority. It would be good if this behaviour could be optional.

@everdred
Copy link

everdred commented Aug 5, 2023

It would be good if this behaviour could be optional.

@tom-james-watson Hey, there's two of us! The developer had previously suggested this could be implemented as a toggle.

@micahmo micahmo marked this pull request as draft August 19, 2023 02:52
@hjiangsu
Copy link
Member

hjiangsu commented Oct 3, 2023

I'll close this PR as it's changes are no longer relevant because of the refactor of the feed page. With the refactor, it should be much easier now to implement a toggle which automatically hides the top bar on scroll!

@hjiangsu hjiangsu closed this Oct 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants