Skip to content

Commit ba51f34

Browse files
committed
feat(settings): configure app bar collapse behavior
1 parent 1d4f8cd commit ba51f34

File tree

8 files changed

+35
-3
lines changed

8 files changed

+35
-3
lines changed

lib/features/settings/repositories/settings_repository.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ final class SettingsRepository with LoggerMixin {
136136
useDetectedProxyWhenStartup: s.extract(_SK.useDetectedProxyWhenStartup),
137137
enableAutoClearImageCache: s.extract(_SK.enableAutoClearImageCache),
138138
autoClearImageCacheDuration: s.extract(_SK.autoClearImageCacheDuration),
139+
collapseAppBarWhenScroll: s.extract(_SK.collapseAppBarWhenScroll),
139140
);
140141
}
141142

lib/features/settings/view/settings_page.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ class _SettingsPageState extends State<SettingsPage> {
396396
autoSyncNoticeDuration = Duration(seconds: autoSyncNoticeSeconds);
397397
}
398398
final enableBBCodeParser = state.settingsMap.enableEditorBBCodeParser;
399+
final collapseAppBarWhenScroll = state.settingsMap.collapseAppBarWhenScroll;
399400

400401
return [
401402
SectionTitleText(tr.title),
@@ -475,6 +476,14 @@ class _SettingsPageState extends State<SettingsPage> {
475476
subtitle: Text(context.t.fastReplyTemplate.details),
476477
onTap: () async => context.pushNamed(ScreenPaths.fastReplyTemplate, pathParameters: {'pick': 'false'}),
477478
),
479+
SectionSwitchListTile(
480+
secondary: const Icon(Symbols.page_header),
481+
title: Text(tr.collapseAppBarWhenScroll.title),
482+
subtitle: Text(tr.collapseAppBarWhenScroll.detail),
483+
value: collapseAppBarWhenScroll,
484+
onChanged: (v) async =>
485+
context.read<SettingsBloc>().add(SettingsValueChanged(SettingsKeys.collapseAppBarWhenScroll, v)),
486+
),
478487
];
479488
}
480489

lib/i18n/en.i18n.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@
198198
"title": "What is BBCode parser",
199199
"detail": "BBCode parser converts plain text BBCode into WYSIWYG content when:\n\n1. Editing published thread\n2. Editing reply templates\n3. Insert reply templates\n4. Expand bottom editor in thread and chat page\n\nDisabling BBCode parser will leave plain text to edit, turn if off when you get bugs."
200200
}
201+
},
202+
"collapseAppBarWhenScroll": {
203+
"title": "Hide app bar when scroll",
204+
"detail": "Hide when scroll down in subreddit and thread pages"
201205
}
202206
},
203207
"checkinSection": {

lib/i18n/zh-CN.i18n.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@
198198
"title": "BBCode parser是什么",
199199
"detail": "以下场景中BBCode parser会将纯文本的BBCode转换为所见即所得的内容以供编辑:\n\n1. 编辑已发布的帖子\n2. 编辑回复模板\n3. 插入回复模板\n4. 展开帖子和聊天页面底部的编辑框\n\n关闭BBCode parse后在编辑时将使用纯文本,遇到问题时可将其关闭"
200200
}
201+
},
202+
"collapseAppBarWhenScroll": {
203+
"title": "滑动时收起AppBar",
204+
"detail": "分区和帖子页面中收起"
201205
}
202206
},
203207
"checkinSection": {

lib/i18n/zh-TW.i18n.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@
198198
"title": "BBCode parser是什麼",
199199
"detail": "以下場景中BBCode parser會將純文字的BBCode轉換為所見即所得的內容以供編輯:\n\n1. 編輯已發布的帖子\n2. 編輯回复模板\n3. 插入回复模板\n4. 展開帖子和聊天頁面底部的編輯框\n\n關閉BBCode parse後在編輯時將使用純文本,遇到問題時可將其關閉"
200200
}
201+
},
202+
"collapseAppBarWhenScroll": {
203+
"title": "滑動時收起AppBar",
204+
"detail": "分割區與貼文頁面中收起"
201205
}
202206
},
203207
"checkinSection": {

lib/shared/models/settings.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,11 @@ enum SettingsKeys<T> implements Comparable<SettingsKeys<T>> {
192192
/// Images that have a long duration till last used time will be considered as outdated.
193193
///
194194
/// Default is 7 days = 60 * 60 * 24 * 7.
195-
autoClearImageCacheDuration<int>(name: 'autoClearImageCacheDuration', type: int, defaultValue: 60 * 60 * 24 * 7);
195+
autoClearImageCacheDuration<int>(name: 'autoClearImageCacheDuration', type: int, defaultValue: 60 * 60 * 24 * 7),
196+
197+
/// Collapse app bar when scroll in pages we want to do it, for example forum page and thread page where app bar
198+
/// holds more spaces and user shall have more space to focus on contents in UI.
199+
collapseAppBarWhenScroll<bool>(name: 'collapseAppBarWhenScroll', type: bool, defaultValue: true);
196200

197201
const SettingsKeys({required this.name, required this.type, required this.defaultValue});
198202

lib/shared/models/settings_map.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class SettingsMap with SettingsMapMappable {
5050
required this.useDetectedProxyWhenStartup,
5151
required this.enableAutoClearImageCache,
5252
required this.autoClearImageCacheDuration,
53+
required this.collapseAppBarWhenScroll,
5354
});
5455

5556
final String netClientAccept;
@@ -94,6 +95,7 @@ class SettingsMap with SettingsMapMappable {
9495
final bool useDetectedProxyWhenStartup;
9596
final bool enableAutoClearImageCache;
9697
final int autoClearImageCacheDuration;
98+
final bool collapseAppBarWhenScroll;
9799

98100
SettingsMap copyWithKey<T>(SettingsKeys<T> key, T? value) {
99101
assert(
@@ -145,6 +147,7 @@ class SettingsMap with SettingsMapMappable {
145147
SettingsKeys.useDetectedProxyWhenStartup => copyWith(useDetectedProxyWhenStartup: value as bool?),
146148
SettingsKeys.enableAutoClearImageCache => copyWith(enableAutoClearImageCache: value as bool?),
147149
SettingsKeys.autoClearImageCacheDuration => copyWith(autoClearImageCacheDuration: value as int?),
150+
SettingsKeys.collapseAppBarWhenScroll => copyWith(collapseAppBarWhenScroll: value as bool?),
148151
};
149152
}
150153
}

lib/widgets/list_app_bar.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,13 @@ class ListAppBar extends StatelessWidget implements PreferredSizeWidget {
115115
// (though impossible if only one page).
116116
final reverseOrder = threadBloc?.state.reverseOrder ?? false;
117117

118+
final collapsableAppBar = context.select<SettingsBloc, bool>((v) => v.state.settingsMap.collapseAppBarWhenScroll);
119+
118120
return SliverAppBar(
119121
title: title == null ? null : Text(title!),
120-
floating: true,
121-
snap: true,
122+
pinned: !collapsableAppBar,
123+
floating: collapsableAppBar,
124+
snap: collapsableAppBar,
122125
bottom: PreferredSize(
123126
preferredSize: Size.fromHeight((bottom?.preferredSize.height ?? 0) + (isMobile ? 52 : 42)),
124127
child: Column(

0 commit comments

Comments
 (0)