Skip to content

Commit

Permalink
feat: optimize the scroll service
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Jun 16, 2023
1 parent 8538149 commit e5dd210
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 27 deletions.
14 changes: 9 additions & 5 deletions example/lib/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ class _HomePageState extends State<HomePage> {
Widget build(BuildContext context) {
return Scaffold(
key: _scaffoldKey,
extendBodyBehindAppBar: true,
extendBodyBehindAppBar: PlatformExtension.isDesktopOrWeb,
drawer: _buildDrawer(context),
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text('AppFlowy Editor'),
),
body: SafeArea(child: _buildBody(context)),
floatingActionButton: _buildFloatingActionButton(context),
floatingActionButtonLocation: PlatformExtension.isMobile
? FloatingActionButtonLocation.startTop
: FloatingActionButtonLocation.endFloat,
floatingActionButton: PlatformExtension.isDesktopOrWeb
? _buildFloatingActionButton(context)
: null,
floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
);
}

Expand Down
6 changes: 5 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class MyApp extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const MaterialApp(
return MaterialApp(
localizationsDelegates: [
GlobalMaterialLocalizations.delegate,
GlobalCupertinoLocalizations.delegate,
Expand All @@ -24,6 +24,10 @@ class MyApp extends StatelessWidget {
supportedLocales: [Locale('en', 'US')],
debugShowCheckedModeBanner: false,
home: MyHomePage(title: 'AppFlowyEditor Example'),
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
useMaterial3: true,
),
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,20 +77,6 @@ class _MobileSelectionServiceWidgetState
editorState.selectionNotifier.addListener(_updateSelection);
}

@override
void didChangeMetrics() {
super.didChangeMetrics();

// Need to refresh the selection when the metrics changed.
if (currentSelection.value != null) {
Debounce.debounce(
'didChangeMetrics - update selection ',
const Duration(milliseconds: 100),
() => updateSelection(currentSelection.value!),
);
}
}

@override
void dispose() {
clearSelection();
Expand Down Expand Up @@ -542,7 +528,7 @@ class _MobileSelectionServiceWidgetState
return false;
}

const extend = 30.0;
const extend = 40.0;
switch (type) {
case MobileSelectionHandlerType.leftHandler:
case MobileSelectionHandlerType.cursorHandler:
Expand Down
13 changes: 7 additions & 6 deletions lib/src/service/selection/mobile_selection_gesture.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ class MobileSelectionGestureDetectorState
@override
Widget build(BuildContext context) {
return RawGestureDetector(
behavior: HitTestBehavior.translucent,
behavior: HitTestBehavior.opaque,
gestures: {
VerticalDragGestureRecognizer:
GestureRecognizerFactoryWithHandlers<VerticalDragGestureRecognizer>(
() => VerticalDragGestureRecognizer(
PanGestureRecognizer:
GestureRecognizerFactoryWithHandlers<PanGestureRecognizer>(
() => PanGestureRecognizer(
supportedDevices: {
// https://docs.flutter.dev/release/breaking-changes/trackpad-gestures#for-gesture-interactions-not-suitable-for-trackpad-usage
PointerDeviceKind.trackpad, PointerDeviceKind.touch,
// // https://docs.flutter.dev/release/breaking-changes/trackpad-gestures#for-gesture-interactions-not-suitable-for-trackpad-usage
// PointerDeviceKind.trackpad,
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
PointerDeviceKind.stylus,
PointerDeviceKind.invertedStylus,
Expand Down

0 comments on commit e5dd210

Please sign in to comment.