Skip to content

Commit

Permalink
feat: allow configuring the auto scroll edge offset (#888)
Browse files Browse the repository at this point in the history
  • Loading branch information
snipd-min authored Sep 16, 2024
1 parent fc5d33e commit ea494df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/src/editor/editor_component/service/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ KeepEditorFocusNotifier keepEditorFocusNotifier = KeepEditorFocusNotifier();

/// The default value of the auto scroll edge offset on mobile
/// The editor will scroll when the cursor is close to the edge of the screen
double appFlowyEditorAutoScrollEdgeOffset = 220.0;
const double appFlowyEditorAutoScrollEdgeOffset = 220.0;

class AppFlowyEditor extends StatefulWidget {
AppFlowyEditor({
Expand Down Expand Up @@ -45,6 +45,7 @@ class AppFlowyEditor extends StatefulWidget {
this.disableKeyboardService = false,
this.disableScrollService = false,
this.disableAutoScroll = false,
this.autoScrollEdgeOffset = appFlowyEditorAutoScrollEdgeOffset,
}) : blockComponentBuilders =
blockComponentBuilders ?? standardBlockComponentBuilderMap,
characterShortcutEvents =
Expand Down Expand Up @@ -216,6 +217,10 @@ class AppFlowyEditor extends StatefulWidget {
///
final bool disableAutoScroll;

/// The edge offset of the auto scroll.
///
final double autoScrollEdgeOffset;

@override
State<AppFlowyEditor> createState() => _AppFlowyEditorState();
}
Expand Down Expand Up @@ -362,6 +367,7 @@ class _AppFlowyEditorState extends State<AppFlowyEditor> {
editorState.enableAutoComplete = widget.enableAutoComplete;
editorState.autoCompleteTextProvider = widget.autoCompleteTextProvider;
editorState.disableAutoScroll = widget.disableAutoScroll;
editorState.autoScrollEdgeOffset = widget.autoScrollEdgeOffset;
}

BlockComponentRendererService get _renderer => BlockComponentRenderer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class _ScrollServiceWidgetState extends State<ScrollServiceWidget>
return Future.delayed(duration, () {
startAutoScroll(
endTouchPoint,
edgeOffset: appFlowyEditorAutoScrollEdgeOffset,
edgeOffset: editorState.autoScrollEdgeOffset,
duration: Duration.zero,
);
});
Expand Down
3 changes: 3 additions & 0 deletions lib/src/editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ class EditorState {
/// Whether the editor should disable auto scroll.
bool disableAutoScroll = false;

/// The edge offset of the auto scroll.
double autoScrollEdgeOffset = appFlowyEditorAutoScrollEdgeOffset;

/// The style of the editor.
late EditorStyle editorStyle;

Expand Down

0 comments on commit ea494df

Please sign in to comment.