Skip to content

Commit

Permalink
feat: detail add scrollUp/scrollDown
Browse files Browse the repository at this point in the history
Release Notes:
- feat: 详情页支持 ctrl+p/ctrl+n 滚动(桌面)
  • Loading branch information
d1y committed Jun 27, 2024
1 parent 0e88022 commit 4fd2214
Show file tree
Hide file tree
Showing 9 changed files with 320 additions and 42 deletions.
30 changes: 3 additions & 27 deletions lib/app/modules/home/views/index_home_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,10 @@ import 'package:movie/app/widget/k_error_stack.dart';
import 'package:movie/app/widget/movie_card_item.dart';
import 'package:movie/app/widget/window_appbar.dart';
import 'package:pull_to_refresh_flutter3/pull_to_refresh_flutter3.dart';
import 'package:simple/x.dart';
import 'package:waterfall_flow/waterfall_flow.dart';
import 'package:xi/xi.dart';

class ScrollDownIntent extends Intent {}

class ScrollUpIntent extends Intent {}

class CategoryNextIntent extends Intent {}

class CategoryPrevIntent extends Intent {}

const scrollSize = 240;

shortcutCallback<T extends Intent>(int curr, VoidCallback cb) {
Expand Down Expand Up @@ -199,28 +192,11 @@ class _IndexHomeViewState extends State<IndexHomeView>
child: Actions(
actions: {
ScrollUpIntent: shortcutCallback(controller.currentBarIndex, () {
var curr = scrollController.offset;
if (curr == 0) return;
var exec = curr - scrollSize;
if (exec < 0) exec = 0;
scrollController.animateTo(
exec,
duration: const Duration(milliseconds: 420),
curve: Curves.ease,
);
scrollUp(scrollController);
}),
ScrollDownIntent:
shortcutCallback(controller.currentBarIndex, () {
var curr = scrollController.offset;
var max = scrollController.position.maxScrollExtent;
if (curr == max) return;
var exec = curr + scrollSize;
if (exec > max) exec = max;
scrollController.animateTo(
exec,
duration: const Duration(milliseconds: 420),
curve: Curves.ease,
);
scrollDown(scrollController);
}),
CategoryPrevIntent:
shortcutCallback(controller.currentBarIndex, () {
Expand Down
69 changes: 54 additions & 15 deletions lib/app/modules/play/views/play_view.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:ui';

import 'package:command_palette/command_palette.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
Expand All @@ -9,6 +10,7 @@ import 'package:movie/app/modules/home/views/parse_vip_manage.dart';
import 'package:movie/app/widget/helper.dart';
import 'package:movie/app/widget/window_appbar.dart';
import 'package:movie/widget/simple_html/flutter_html.dart';
import 'package:simple/x.dart';
import 'package:xi/adapters/mac_cms.dart';
import 'package:xi/xi.dart';

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

FocusNode focusNode = FocusNode();

ScrollController scrollController = ScrollController();

bool get canBeShowParseVipButton {
return home.parseVipList.isNotEmpty;
}
Expand Down Expand Up @@ -163,10 +167,28 @@ class _PlayViewState extends State<PlayView> {
),
),
body: Shortcuts(
shortcuts: const {
SingleActivator(LogicalKeyboardKey.escape): DismissIntent(),
SingleActivator(LogicalKeyboardKey.backspace): DismissIntent(),
SingleActivator(LogicalKeyboardKey.enter): ActivateIntent(),
shortcuts: {
// esc
const SingleActivator(LogicalKeyboardKey.escape):
const DismissIntent(),
// backspace
const SingleActivator(LogicalKeyboardKey.backspace):
const DismissIntent(),
// enter
const SingleActivator(LogicalKeyboardKey.enter):
const ActivateIntent(),
// ctrl-p
const SingleActivator(LogicalKeyboardKey.keyP, control: true):
ScrollUpIntent(),
// ctrl-n
const SingleActivator(LogicalKeyboardKey.keyN, control: true):
ScrollDownIntent(),
// // cmd-shift-[
// const SingleActivator(LogicalKeyboardKey.braceLeft /* { */,
// meta: true, shift: true): TabSwitchLeftIntent(),
// // cmd-shift-]
// const SingleActivator(LogicalKeyboardKey.braceRight /* } */,
// meta: true, shift: true): TabSwitchRightIntent(),
},
child: Actions(
actions: {
Expand All @@ -186,6 +208,18 @@ class _PlayViewState extends State<PlayView> {
return null;
},
),
ScrollUpIntent: CallbackAction<ScrollUpIntent>(
onInvoke: (_) {
scrollUp(scrollController);
return null;
},
),
ScrollDownIntent: CallbackAction<ScrollDownIntent>(
onInvoke: (_) {
scrollDown(scrollController);
return null;
},
),
},
child: Focus(
autofocus: true,
Expand All @@ -196,6 +230,7 @@ class _PlayViewState extends State<PlayView> {
color: context.isDarkMode ? Colors.white : Colors.black,
),
child: SingleChildScrollView(
controller: scrollController,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down Expand Up @@ -349,17 +384,21 @@ class _PlayViewState extends State<PlayView> {
},
);
}
return CupertinoSlidingSegmentedControl(
backgroundColor: Colors.black26,
thumbColor: context.isDarkMode
? Colors.blue
: Colors.white,
onValueChanged: (value) {
if (value == null) return;
play.changeTabIndex(value);
},
groupValue: play.tabIndex,
children: tabviewData,
return Padding(
padding: const EdgeInsets.symmetric(
horizontal: 12),
child: CupertinoSlidingSegmentedControl(
backgroundColor: Colors.black26,
thumbColor: context.isDarkMode
? Colors.blue
: Colors.white,
onValueChanged: (value) {
if (value == null) return;
play.changeTabIndex(value);
},
groupValue: play.tabIndex,
children: tabviewData,
),
);
}),
),
Expand Down
9 changes: 9 additions & 0 deletions packages/simple/lib/intent.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:flutter/widgets.dart';

class ScrollDownIntent extends Intent {}

class ScrollUpIntent extends Intent {}

class CategoryNextIntent extends Intent {}

class CategoryPrevIntent extends Intent {}
21 changes: 21 additions & 0 deletions packages/simple/lib/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/widgets.dart';

const kScrollDuration = Duration(milliseconds: 420);
const kScrollSize = 240;

scrollUp(ScrollController cx) {
var curr = cx.offset;
if (curr == 0) return;
var exec = curr - kScrollSize;
if (exec < 0) exec = 0;
cx.animateTo(exec, duration: kScrollDuration, curve: Curves.ease);
}

scrollDown(ScrollController cx) {
var curr = cx.offset;
var max = cx.position.maxScrollExtent;
if (curr == max) return;
var exec = curr + kScrollSize;
if (exec > max) exec = max;
cx.animateTo(exec, duration: kScrollDuration, curve: Curves.ease);
}
4 changes: 4 additions & 0 deletions packages/simple/lib/x.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library simple;

export 'intent.dart';
export 'utils.dart';
Loading

0 comments on commit 4fd2214

Please sign in to comment.