Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow configuring the auto scroll edge offset #888

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading