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
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
115 changes: 72 additions & 43 deletions lib/community/pages/community_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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


class CommunityPage extends StatefulWidget {
final int? communityId;
Expand All @@ -28,6 +29,22 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl
@override
bool get wantKeepAlive => true;

final GlobalKey<NestedScrollViewState> globalKey = GlobalKey();

@override
void initState() {
super.initState();
WidgetsBinding.instance!.addPostFrameCallback((timeStamp) {
globalKey.currentState!.innerController.addListener(() {
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

}
});
});
}

SortType? sortType;
IconData? sortTypeIcon;
String? sortTypeLabel;
Expand Down Expand Up @@ -66,48 +83,61 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl
},
builder: (context, state) {
return Scaffold(
key: widget.scaffoldKey,
appBar: AppBar(
title: Text(getCommunityName(state)),
centerTitle: false,
toolbarHeight: 70.0,
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if ((state.communityId != null || state.communityName != null) && isUserLoggedIn)
IconButton(
icon: Icon(
(state.subscribedType == SubscribedType.notSubscribed || state.subscribedType == null) ? Icons.library_add_check_outlined : Icons.library_add_check_rounded,
semanticLabel: (state.subscribedType == SubscribedType.notSubscribed || state.subscribedType == null) ? 'Subscribe' : 'Unsubscribe',
),
onPressed: () {
HapticFeedback.mediumImpact();
context.read<CommunityBloc>().add(
ChangeCommunitySubsciptionStatusEvent(
communityId: state.communityId!,
follow: (state.subscribedType == null) ? true : (state.subscribedType == SubscribedType.notSubscribed ? true : false),
),
);
},
),
IconButton(
icon: const Icon(Icons.refresh_rounded, semanticLabel: 'Refresh'),
onPressed: () {
HapticFeedback.mediumImpact();
return context.read<CommunityBloc>().add(GetCommunityPostsEvent(reset: true, sortType: sortType, communityId: state.communityId));
}),
IconButton(
icon: Icon(sortTypeIcon, semanticLabel: 'Sort By'),
tooltip: sortTypeLabel,
onPressed: () {
HapticFeedback.mediumImpact();
showSortBottomSheet(context, state);
}),
const SizedBox(width: 8.0),
],
)
],
// key: widget.scaffoldKey,
body: NestedScrollView(
key: globalKey,
floatHeaderSlivers: true,
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
SliverAppBar(
title: Text(getCommunityName(state)),
pinned: false,
floating: true,
snap: false,
forceElevated: innerBoxIsScrolled,
centerTitle: false,
toolbarHeight: 70.0,
actions: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
if ((state.communityId != null || state.communityName != null) && isUserLoggedIn)
IconButton(
icon: Icon(
(state.subscribedType == SubscribedType.notSubscribed || state.subscribedType == null) ? Icons.library_add_check_outlined : Icons.library_add_check_rounded,
semanticLabel: (state.subscribedType == SubscribedType.notSubscribed || state.subscribedType == null) ? 'Subscribe' : 'Unsubscribe',
),
onPressed: () {
HapticFeedback.mediumImpact();
context.read<CommunityBloc>().add(
ChangeCommunitySubsciptionStatusEvent(
communityId: state.communityId!,
follow: (state.subscribedType == null) ? true : (state.subscribedType == SubscribedType.notSubscribed ? true : false),
),
);
},
),
IconButton(
icon: const Icon(Icons.refresh_rounded, semanticLabel: 'Refresh'),
onPressed: () {
HapticFeedback.mediumImpact();
return context.read<CommunityBloc>().add(GetCommunityPostsEvent(reset: true, sortType: sortType, communityId: state.communityId));
}),
IconButton(
icon: Icon(sortTypeIcon, semanticLabel: 'Sort By'),
tooltip: sortTypeLabel,
onPressed: () {
HapticFeedback.mediumImpact();
showSortBottomSheet(context, state);
}),
const SizedBox(width: 8.0),
],
)
],
),
];
},
body: SafeArea(child: _getBody(context, state)),
),
drawer: (widget.communityId != null || widget.communityName != null) ? null : const CommunityDrawer(),
floatingActionButton: ((state.communityId != null || widget.communityName != null) && isUserLoggedIn)
Expand All @@ -132,7 +162,6 @@ class _CommunityPageState extends State<CommunityPage> with AutomaticKeepAliveCl
),
)
: null,
body: SafeArea(child: _getBody(context, state)),
);
},
),
Expand Down
2 changes: 1 addition & 1 deletion lib/community/widgets/post_card_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class _PostCardListState extends State<PostCardList> {
},
child: ListView.builder(
cacheExtent: 500,
controller: _scrollController,
// controller: _scrollController,
itemCount: widget.postViews?.length != null ? ((widget.communityId != null || widget.communityName != null) ? widget.postViews!.length + 1 : widget.postViews!.length + 1) : 1,
itemBuilder: (context, index) {
if (index == 0 && (widget.communityId != null || widget.communityName != null)) {
Expand Down