Skip to content

Commit 4fd2214

Browse files
committed
feat: detail add scrollUp/scrollDown
Release Notes: - feat: 详情页支持 ctrl+p/ctrl+n 滚动(桌面)
1 parent 0e88022 commit 4fd2214

File tree

9 files changed

+320
-42
lines changed

9 files changed

+320
-42
lines changed

lib/app/modules/home/views/index_home_view.dart

+3-27
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,10 @@ import 'package:movie/app/widget/k_error_stack.dart';
1111
import 'package:movie/app/widget/movie_card_item.dart';
1212
import 'package:movie/app/widget/window_appbar.dart';
1313
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
14+
import 'package:simple/x.dart';
1415
import 'package:waterfall_flow/waterfall_flow.dart';
1516
import 'package:xi/xi.dart';
1617

17-
class ScrollDownIntent extends Intent {}
18-
19-
class ScrollUpIntent extends Intent {}
20-
21-
class CategoryNextIntent extends Intent {}
22-
23-
class CategoryPrevIntent extends Intent {}
24-
2518
const scrollSize = 240;
2619

2720
shortcutCallback<T extends Intent>(int curr, VoidCallback cb) {
@@ -199,28 +192,11 @@ class _IndexHomeViewState extends State<IndexHomeView>
199192
child: Actions(
200193
actions: {
201194
ScrollUpIntent: shortcutCallback(controller.currentBarIndex, () {
202-
var curr = scrollController.offset;
203-
if (curr == 0) return;
204-
var exec = curr - scrollSize;
205-
if (exec < 0) exec = 0;
206-
scrollController.animateTo(
207-
exec,
208-
duration: const Duration(milliseconds: 420),
209-
curve: Curves.ease,
210-
);
195+
scrollUp(scrollController);
211196
}),
212197
ScrollDownIntent:
213198
shortcutCallback(controller.currentBarIndex, () {
214-
var curr = scrollController.offset;
215-
var max = scrollController.position.maxScrollExtent;
216-
if (curr == max) return;
217-
var exec = curr + scrollSize;
218-
if (exec > max) exec = max;
219-
scrollController.animateTo(
220-
exec,
221-
duration: const Duration(milliseconds: 420),
222-
curve: Curves.ease,
223-
);
199+
scrollDown(scrollController);
224200
}),
225201
CategoryPrevIntent:
226202
shortcutCallback(controller.currentBarIndex, () {

lib/app/modules/play/views/play_view.dart

+54-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'dart:ui';
22

3+
import 'package:command_palette/command_palette.dart';
34
import 'package:flutter/cupertino.dart';
45
import 'package:flutter/material.dart';
56
import 'package:flutter/services.dart';
@@ -9,6 +10,7 @@ import 'package:movie/app/modules/home/views/parse_vip_manage.dart';
910
import 'package:movie/app/widget/helper.dart';
1011
import 'package:movie/app/widget/window_appbar.dart';
1112
import 'package:movie/widget/simple_html/flutter_html.dart';
13+
import 'package:simple/x.dart';
1214
import 'package:xi/adapters/mac_cms.dart';
1315
import 'package:xi/xi.dart';
1416

@@ -46,6 +48,8 @@ class _PlayViewState extends State<PlayView> {
4648

4749
FocusNode focusNode = FocusNode();
4850

51+
ScrollController scrollController = ScrollController();
52+
4953
bool get canBeShowParseVipButton {
5054
return home.parseVipList.isNotEmpty;
5155
}
@@ -163,10 +167,28 @@ class _PlayViewState extends State<PlayView> {
163167
),
164168
),
165169
body: Shortcuts(
166-
shortcuts: const {
167-
SingleActivator(LogicalKeyboardKey.escape): DismissIntent(),
168-
SingleActivator(LogicalKeyboardKey.backspace): DismissIntent(),
169-
SingleActivator(LogicalKeyboardKey.enter): ActivateIntent(),
170+
shortcuts: {
171+
// esc
172+
const SingleActivator(LogicalKeyboardKey.escape):
173+
const DismissIntent(),
174+
// backspace
175+
const SingleActivator(LogicalKeyboardKey.backspace):
176+
const DismissIntent(),
177+
// enter
178+
const SingleActivator(LogicalKeyboardKey.enter):
179+
const ActivateIntent(),
180+
// ctrl-p
181+
const SingleActivator(LogicalKeyboardKey.keyP, control: true):
182+
ScrollUpIntent(),
183+
// ctrl-n
184+
const SingleActivator(LogicalKeyboardKey.keyN, control: true):
185+
ScrollDownIntent(),
186+
// // cmd-shift-[
187+
// const SingleActivator(LogicalKeyboardKey.braceLeft /* { */,
188+
// meta: true, shift: true): TabSwitchLeftIntent(),
189+
// // cmd-shift-]
190+
// const SingleActivator(LogicalKeyboardKey.braceRight /* } */,
191+
// meta: true, shift: true): TabSwitchRightIntent(),
170192
},
171193
child: Actions(
172194
actions: {
@@ -186,6 +208,18 @@ class _PlayViewState extends State<PlayView> {
186208
return null;
187209
},
188210
),
211+
ScrollUpIntent: CallbackAction<ScrollUpIntent>(
212+
onInvoke: (_) {
213+
scrollUp(scrollController);
214+
return null;
215+
},
216+
),
217+
ScrollDownIntent: CallbackAction<ScrollDownIntent>(
218+
onInvoke: (_) {
219+
scrollDown(scrollController);
220+
return null;
221+
},
222+
),
189223
},
190224
child: Focus(
191225
autofocus: true,
@@ -196,6 +230,7 @@ class _PlayViewState extends State<PlayView> {
196230
color: context.isDarkMode ? Colors.white : Colors.black,
197231
),
198232
child: SingleChildScrollView(
233+
controller: scrollController,
199234
child: Column(
200235
mainAxisAlignment: MainAxisAlignment.start,
201236
crossAxisAlignment: CrossAxisAlignment.start,
@@ -349,17 +384,21 @@ class _PlayViewState extends State<PlayView> {
349384
},
350385
);
351386
}
352-
return CupertinoSlidingSegmentedControl(
353-
backgroundColor: Colors.black26,
354-
thumbColor: context.isDarkMode
355-
? Colors.blue
356-
: Colors.white,
357-
onValueChanged: (value) {
358-
if (value == null) return;
359-
play.changeTabIndex(value);
360-
},
361-
groupValue: play.tabIndex,
362-
children: tabviewData,
387+
return Padding(
388+
padding: const EdgeInsets.symmetric(
389+
horizontal: 12),
390+
child: CupertinoSlidingSegmentedControl(
391+
backgroundColor: Colors.black26,
392+
thumbColor: context.isDarkMode
393+
? Colors.blue
394+
: Colors.white,
395+
onValueChanged: (value) {
396+
if (value == null) return;
397+
play.changeTabIndex(value);
398+
},
399+
groupValue: play.tabIndex,
400+
children: tabviewData,
401+
),
363402
);
364403
}),
365404
),

packages/simple/lib/intent.dart

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'package:flutter/widgets.dart';
2+
3+
class ScrollDownIntent extends Intent {}
4+
5+
class ScrollUpIntent extends Intent {}
6+
7+
class CategoryNextIntent extends Intent {}
8+
9+
class CategoryPrevIntent extends Intent {}

packages/simple/lib/utils.dart

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import 'package:flutter/widgets.dart';
2+
3+
const kScrollDuration = Duration(milliseconds: 420);
4+
const kScrollSize = 240;
5+
6+
scrollUp(ScrollController cx) {
7+
var curr = cx.offset;
8+
if (curr == 0) return;
9+
var exec = curr - kScrollSize;
10+
if (exec < 0) exec = 0;
11+
cx.animateTo(exec, duration: kScrollDuration, curve: Curves.ease);
12+
}
13+
14+
scrollDown(ScrollController cx) {
15+
var curr = cx.offset;
16+
var max = cx.position.maxScrollExtent;
17+
if (curr == max) return;
18+
var exec = curr + kScrollSize;
19+
if (exec > max) exec = max;
20+
cx.animateTo(exec, duration: kScrollDuration, curve: Curves.ease);
21+
}

packages/simple/lib/x.dart

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
library simple;
2+
3+
export 'intent.dart';
4+
export 'utils.dart';

0 commit comments

Comments
 (0)