Skip to content

Commit

Permalink
feat: enable debug paint size for mobile drag handle
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasXu0 committed Dec 30, 2024
1 parent c68e5f6 commit 3ece3c6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions example/lib/pages/mobile_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class _MobileEditorState extends State<MobileEditor> {

editorStyle = _buildMobileEditorStyle();
blockComponentBuilders = _buildBlockComponentBuilders();

editorState.debugInfo.debugPaintSizeEnabled = true;
}

@override
Expand Down
16 changes: 16 additions & 0 deletions lib/src/editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ typedef EditorTransactionValue = (
ApplyOptions options,
);

class EditorStateDebugInfo {
EditorStateDebugInfo({
this.debugPaintSizeEnabled = false,
});

/// Enable the debug paint size for selection handle.
///
/// It only available on mobile.
bool debugPaintSizeEnabled;
}

/// the type of this value is bool.
///
/// set true to this key to prevent attaching the text service when selection is changed.
Expand Down Expand Up @@ -166,6 +177,11 @@ class EditorState {
service.rendererService = value;
}

/// Customize the debug info for the editor state.
///
/// Refer to [EditorStateDebugInfo] for more details.
EditorStateDebugInfo debugInfo = EditorStateDebugInfo();

/// store the auto scroller instance in here temporarily.
AutoScroller? autoScroller;
ScrollableState? scrollableState;
Expand Down
11 changes: 11 additions & 0 deletions lib/src/render/selection/mobile_collapsed_handle.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor/src/editor/util/platform_extension.dart';
import 'package:appflowy_editor/src/render/selection/mobile_basic_handle.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class MobileCollapsedHandle extends StatelessWidget {
const MobileCollapsedHandle({
Expand All @@ -22,11 +24,13 @@ class MobileCollapsedHandle extends StatelessWidget {

@override
Widget build(BuildContext context) {
final debugInfo = context.read<EditorState>().debugInfo;
if (PlatformExtension.isIOS) {
return _IOSCollapsedHandle(
layerLink: layerLink,
rect: rect,
handleWidth: handleWidth,
debugPaintSizeEnabled: debugInfo.debugPaintSizeEnabled,
);
} else if (PlatformExtension.isAndroid) {
return _AndroidCollapsedHandle(
Expand All @@ -36,6 +40,7 @@ class MobileCollapsedHandle extends StatelessWidget {
handleWidth: handleWidth,
handleBallWidth: handleBallWidth,
enableHapticFeedbackOnAndroid: enableHapticFeedbackOnAndroid,
debugPaintSizeEnabled: debugInfo.debugPaintSizeEnabled,
);
}
throw UnsupportedError('Unsupported platform');
Expand All @@ -47,11 +52,13 @@ class _IOSCollapsedHandle extends StatelessWidget {
required this.layerLink,
required this.rect,
this.handleWidth = 2.0,
this.debugPaintSizeEnabled = false,
});

final Rect rect;
final LayerLink layerLink;
final double handleWidth;
final bool debugPaintSizeEnabled;

@override
Widget build(BuildContext context) {
Expand All @@ -78,6 +85,7 @@ class _IOSCollapsedHandle extends StatelessWidget {
handleType: HandleType.collapsed,
handleColor: Colors.transparent,
handleWidth: adjustedRect.width,
debugPaintSizeEnabled: debugPaintSizeEnabled,
),
),
],
Expand All @@ -95,6 +103,7 @@ class _AndroidCollapsedHandle extends StatelessWidget {
this.handleBallWidth = 6.0,
this.handleWidth = 2.0,
this.enableHapticFeedbackOnAndroid = true,
this.debugPaintSizeEnabled = false,
});

final Rect rect;
Expand All @@ -103,6 +112,7 @@ class _AndroidCollapsedHandle extends StatelessWidget {
final double handleWidth;
final double handleBallWidth;
final bool enableHapticFeedbackOnAndroid;
final bool debugPaintSizeEnabled;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -132,6 +142,7 @@ class _AndroidCollapsedHandle extends StatelessWidget {
handleColor: handleColor,
handleWidth: adjustedRect.width,
handleBallWidth: handleBallWidth,
debugPaintSizeEnabled: debugPaintSizeEnabled,
),
),
],
Expand Down

0 comments on commit 3ece3c6

Please sign in to comment.