Skip to content

Commit

Permalink
fix: [Bug] iOS scroll to cursor issue AppFlowy-IO#644
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail-Ivanou committed Feb 14, 2024
1 parent 66762ef commit 2100221
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class BlockComponentConfiguration {
this.placeholderText = _placeholderText,
this.textStyle = _textStyle,
this.placeholderTextStyle = _placeholderTextStyle,
this.alreadyScrollable = false,
});

/// The padding of a block component.
Expand All @@ -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<T extends StatefulWidget> on State<T> {
BlockComponentConfiguration get configuration;

Node get node;

EdgeInsets get padding => configuration.padding(node);
Expand Down
48 changes: 28 additions & 20 deletions lib/src/editor/editor_component/entry/page_block_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class ScrollServiceWidget extends StatefulWidget {
required this.editorScrollController,
required this.child,
});

static double edgeOffset = 150;

final EditorScrollController editorScrollController;

Expand Down Expand Up @@ -108,7 +110,7 @@ class _ScrollServiceWidgetState extends State<ScrollServiceWidget>
), () {
startAutoScroll(
endTouchPoint,
edgeOffset: 150,
edgeOffset: ScrollServiceWidget.edgeOffset,
duration: Duration.zero,
);
});
Expand Down

0 comments on commit 2100221

Please sign in to comment.