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

[Bug] iOS scroll to cursor issue #644

Open
mikivanou opened this issue Jan 4, 2024 · 3 comments
Open

[Bug] iOS scroll to cursor issue #644

mikivanou opened this issue Jan 4, 2024 · 3 comments

Comments

@mikivanou
Copy link

mikivanou commented Jan 4, 2024

Bug Description

I need to implement AppflowyEditor with dynamic height.
It worked correctly in 1.4.4 version, but version 2.1.0 breaks flow

How to Reproduce

class HomeSamplePage extends StatefulWidget {
  static const String route = '/sample';

  const HomeSamplePage({Key? key}) : super(key: key);

  @override
  State<HomeSamplePage> createState() => _HomeSamplePageState();
}

 class _HomeSamplePageState extends State<HomeSamplePage> {
  final _descriptionScroll = ScrollController();
  final _descriptionFocusNode = FocusNode();
  late EditorState editorState;

  @override
  void initState() {
    editorState = EditorState(
      document: Document.blank(withInitialText: true),
    );
    _descriptionFocusNode.addListener(() {
      setState(() {
        //do refresh UI to show RichText buttons
      });
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Sample')),
      body: SafeArea(
        child: Container(
          padding: const EdgeInsets.symmetric(horizontal: 16),
          child: Column(
            children: [
              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      TextFormField(
                        decoration: const InputDecoration(hintText: 'Title'),
                      ),
                      const Divider(),
                      IntrinsicHeight(
                        child: AppFlowyEditor(
                          editorStyle:
                              AppflowyEditorStyles.getDescriptionStyles(
                                  context),
                          editorState: editorState,
                          editorScrollController: EditorScrollController(
                            editorState: editorState,
                            scrollController: _descriptionScroll,
                            shrinkWrap: true,
                          ),
                          focusNode: _descriptionFocusNode,
                          blockComponentBuilders:
                              AppflowyEditorStyles.getBuilders(
                                  context, editorState),
                        ),
                      ),
                      const Divider(),
                      const Text('Some text under description'),
                    ],
                  ),
                ),
              ),
              const Divider(),
              Row(
                children: [
                  OutlinedButton(
                    child: const Text('switch'),
                    onPressed: () async {
                      //some action, imitate real ui
                    },
                  ),
                ],
              ),
              const Divider(),
              if (_descriptionFocusNode.hasFocus) ...[
                const SizedBox(
                  height: 2,
                ),
                //custom toolbar
                RichTextToolbar(editorState: editorState),
                const SizedBox(
                  height: 2,
                ),
              ],
            ],
          ),
        ),
      ),
    );
  }
}

Expected Behavior

cursor is always visible

Operating System

iOS

AppFlowy Editor Version(s)

2.1.0

Screenshots

2.1.0
https://github.com/AppFlowy-IO/appflowy-editor/assets/142427747/5e8c4f36-4cf9-45b3-8a2a-5191e7ef995b

1.4.4

Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-01-04.at.23.17.32.mp4

Additional Context

I observe next logs with 2.1.0 version
flutter: App: ^[[38;5;196m┌───────────────────────────────────────────────────────────────────────────────<…>
flutter: App: ^[[38;5;196m│ 'package:appflowy_editor/src/flutter/scrollable_helpers.dart': Failed assertion: line 236 pos 7: 'globalRect.size.width >= _dragTargetRelatedToScrollOrigin.size.width &&<…>
flutter: App: ^[[38;5;196m│ globalRect.size.height >=<…>
flutter: App: ^[[38;5;196m│ _dragTargetRelatedToScrollOrigin.size.height': Drag target size is larger than scrollable size, which may cause bouncing<…>
flutter: App: ^[[38;5;196m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
flutter: App: ^[[38;5;196m│ #0 _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)<…>
flutter: App: ^[[38;5;196m│ #1 _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)<…>
flutter: App: ^[[38;5;196m│ #2 EdgeDraggingAutoScroller._scroll (package:appflowy_editor/src/flutter/scrollable_helpers.dart:236:7)<…>
flutter: App: ^[[38;5;196m│ #3 EdgeDraggingAutoScroller.startAutoScrollIfNecessary (package:appflowy_editor/src/flutter/scrollable_helpers.dart:215:5)<…>
flutter: App: ^[[38;5;196m│ #4 AutoScroller.startAutoScroll (package:appflowy_editor/src/editor/editor_component/service/scroll/auto_scroller.dart:48:5)<…>
flutter: App: ^[[38;5;196m│ #5 _MobileScrollServiceState.startAutoScroll (package:appflowy_editor/src/editor/editor_component/service/scroll/mobile_scroll_service.dart:103:19)<…>
flutter: App: ^[[38;5;196m│ #6 _ScrollServiceWidgetState.startAutoScroll (package:appflowy_editor/src/editor/editor_component/service/scroll_service_widget.dart:167:13)<…>
flutter: App: ^[[38;5;196m│ #7 _ScrollServiceWidgetState._onSelectionChanged.. (package:appflowy_editor/src/editor/editor_component/service/scroll_service_widget.dart:104:11)<…>
flutter: App: ^[[38;5;196m│ #8 new Future.delayed. (dart:async/future.dart:427:39)<…>
flutter: App: ^[[38;5;196m│ #9 _rootRun (dart:async/zone.dart:1391:47)<…>
flutter: App: ^[[38;5;196m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
flutter: App: ^[[38;5;196m│ ⛔ CRASH: <…>
flutter: App: ^[[38;5;196m└───────────────────────────────────────────────────────────────────────────────<…>

@LucasXu0
Copy link
Collaborator

LucasXu0 commented Jan 5, 2024

Hi, @mikivanou. Did you mean the editor won't scroll automatically if the cursor is off-screen?

@mikivanou
Copy link
Author

Hi, @mikivanou. Did you mean the editor won't scroll automatically if the cursor is off-screen?

Yep, I expect editor scroll automatically when cursor is off-screen

Mikhail-Ivanou added a commit to Mikhail-Ivanou/appflowy-editor that referenced this issue Jan 20, 2024
Mikhail-Ivanou added a commit to Mikhail-Ivanou/appflowy-editor that referenced this issue Feb 14, 2024
@adnan-nazir
Copy link

Hi @mikivanou , can you please share your source code for custom RichTextToolbar you implemented?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants