From 21002216d6b7991096bd4ba6d3b0b335aa6acabd Mon Sep 17 00:00:00 2001 From: mike Date: Sat, 20 Jan 2024 15:25:32 +0300 Subject: [PATCH] fix: [Bug] iOS scroll to cursor issue #644 --- .../block_component_configuration.dart | 10 ++++ .../entry/page_block_component.dart | 48 +++++++++++-------- .../service/scroll_service_widget.dart | 4 +- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lib/src/editor/block_component/base_component/block_component_configuration.dart b/lib/src/editor/block_component/base_component/block_component_configuration.dart index 890b2808a..e08e98d95 100644 --- a/lib/src/editor/block_component/base_component/block_component_configuration.dart +++ b/lib/src/editor/block_component/base_component/block_component_configuration.dart @@ -9,6 +9,7 @@ class BlockComponentConfiguration { this.placeholderText = _placeholderText, this.textStyle = _textStyle, this.placeholderTextStyle = _placeholderTextStyle, + this.alreadyScrollable = false, }); /// The padding of a block component. @@ -35,23 +36,32 @@ class BlockComponentConfiguration { /// It inherits the style from [textStyle]. final TextStyle Function(Node node) placeholderTextStyle; + /// This flag shows if AppFlowyEditor is already wrapped with + /// SingleChildScrollView + /// + /// used when scrollController.shrinkWrap == true + final bool alreadyScrollable; + BlockComponentConfiguration copyWith({ EdgeInsets Function(Node node)? padding, TextStyle Function(Node node)? textStyle, String Function(Node node)? placeholderText, TextStyle Function(Node node)? placeholderTextStyle, + bool? alreadyScrollable, }) { return BlockComponentConfiguration( padding: padding ?? this.padding, textStyle: textStyle ?? this.textStyle, placeholderText: placeholderText ?? this.placeholderText, placeholderTextStyle: placeholderTextStyle ?? this.placeholderTextStyle, + alreadyScrollable: alreadyScrollable ?? this.alreadyScrollable, ); } } mixin BlockComponentConfigurable on State { BlockComponentConfiguration get configuration; + Node get node; EdgeInsets get padding => configuration.padding(node); diff --git a/lib/src/editor/editor_component/entry/page_block_component.dart b/lib/src/editor/editor_component/entry/page_block_component.dart index 36d599a7a..d3d24574a 100644 --- a/lib/src/editor/editor_component/entry/page_block_component.dart +++ b/lib/src/editor/editor_component/entry/page_block_component.dart @@ -27,8 +27,13 @@ class PageBlockComponentBuilder extends BlockComponentBuilder { node: blockComponentContext.node, header: blockComponentContext.header, footer: blockComponentContext.footer, + configuration: configuration, ); } + + PageBlockComponentBuilder({ + super.configuration = const BlockComponentConfiguration(), + }); } class PageBlockComponent extends BlockComponentStatelessWidget { @@ -54,28 +59,31 @@ class PageBlockComponent extends BlockComponentStatelessWidget { if (scrollController == null || scrollController.shrinkWrap || !editorState.editable) { - return SingleChildScrollView( - child: Builder( - builder: (context) { - final scroller = Scrollable.maybeOf(context); - if (scroller != null) { - editorState.updateAutoScroller(scroller); - } - return Column( - children: [ - if (header != null) header!, - ...items.map( - (e) => Padding( - padding: editorState.editorStyle.padding, - child: editorState.renderer.build(context, e), - ), + final child = Builder( + builder: (context) { + final scroller = Scrollable.maybeOf(context); + if (scroller != null) { + editorState.updateAutoScroller(scroller); + } + return Column( + children: [ + if (header != null) header!, + ...items.map( + (e) => Padding( + padding: editorState.editorStyle.padding, + child: editorState.renderer.build(context, e), ), - if (footer != null) footer!, - ], - ); - }, - ), + ), + if (footer != null) footer!, + ], + ); + }, ); + return configuration.alreadyScrollable + ? child + : SingleChildScrollView( + child: child, + ); } else { int extentCount = 0; if (header != null) extentCount++; diff --git a/lib/src/editor/editor_component/service/scroll_service_widget.dart b/lib/src/editor/editor_component/service/scroll_service_widget.dart index c7b90a15c..e5b70f2a1 100644 --- a/lib/src/editor/editor_component/service/scroll_service_widget.dart +++ b/lib/src/editor/editor_component/service/scroll_service_widget.dart @@ -11,6 +11,8 @@ class ScrollServiceWidget extends StatefulWidget { required this.editorScrollController, required this.child, }); + + static double edgeOffset = 150; final EditorScrollController editorScrollController; @@ -108,7 +110,7 @@ class _ScrollServiceWidgetState extends State ), () { startAutoScroll( endTouchPoint, - edgeOffset: 150, + edgeOffset: ScrollServiceWidget.edgeOffset, duration: Duration.zero, ); });