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

[SuperTextField][mobile] Migrate popover toolbars to OverlayPortal (Resolves #1602) #1604

Merged

Conversation

angelosilvestre
Copy link
Collaborator

[SuperTextField][mobile] Migrate popover toolbar to OverlayPortal (Resolves #1602)

Currently, the mobile toolbars are displayed in the app Overlay. Because of that, it doesn't have access to InheritedWidgets placed below MaterialApp.

As a result, if an app adds a Theme widget above SuperTextField, the SuperTextField uses this Theme, but the popover toolbar uses the MaterialApp's theme.

This PR changes the popover toolbars to be displayed in an OverlayPortal instead of an Overlay. By doing so, the popovers "see" the same InheritedWidgets that the SuperTextField sees.

In the tests, I had to use the platform textfields directly, as SuperTextField doesn't expose the popoverToolbarBuilder in its public API.

I also noticed that the iOS textfield is always using the _defaultPopoverToolbarBuilder instead of the given popoverToolbarBuilder. This PR fixes that.

@angelosilvestre
Copy link
Collaborator Author

@matthew-carroll Tests are failing due to a compilation error:

lib/src/default_editor/document_hardware_keyboard/document_physical_keyboard.dart:125:23: Error: The argument type 'RawKeyEvent' can't be assigned to the parameter type 'KeyEvent'.
 - 'RawKeyEvent' is from 'package:flutter/src/services/raw_keyboard.dart' ('/opt/hostedtoolcache/flutter/master-any-x64/packages/flutter/lib/src/services/raw_keyboard.dart').
 - 'KeyEvent' is from 'package:flutter/src/services/hardware_keyboard.dart' ('/opt/hostedtoolcache/flutter/master-any-x64/packages/flutter/lib/src/services/hardware_keyboard.dart').
      if (key.accepts(keyEvent, RawKeyboard.instance)) {

It seems to be related to this PR: #1593

final _popoverController = OverlayPortalController();

/// Notifies the popover toolbar to rebuild itself.
final _popoverRebuildSignal = SignalNotifier();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this rebuild signal here because we're scheduling extra frames to position the toolbar? If so, can we use a Leader and Follower instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is used to position the toolbar. Currently, we are doing _controlsOverlayEntry?.markNeedsBuild(); to do this.

We can use Leader and Follower, but it will require big change. I'm not sure we should do that on this PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. We can do it in a follow up. Can you file a ticket for that?

child: TextScrollView(
key: _scrollKey,
textScrollController: _textScrollController,
return OverlayPortal(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we're bringing an overlay portal into this, let's breakdown this build method so it's clear which pieces are what.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.


void main() {
group('SuperTextField', () {
testWidgetsOnIos('applies app theme to the popover toolbar (on iOS)', (tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to specify "(on iOS)" when using testWidgetsOnIos()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

testWidgetsOnIos itself doesn't add the "(on iOS)" suffix.

Maybe it's time to change that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really? I thought I saw "(on iOS)" appended to all sorts of tests that we run? If for some reason that test runner is the only one that isn't adding its name, then yes, we should add that, but I was almost certain that we already have iOS tests that add the suffix.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matthew-carroll It's the testWidgetsOnMobile and testWidgetsOnAllPlatforms that appends the suffixes. Can we make that change in a separate PR?

@matthew-carroll
Copy link
Contributor

This PR mentions that SuperTextField doesn't support any configuration of the overlay controls. We should probably provide that control. The question is, how should we do that?

In SuperEditor, I'm in the middle of moving overlay controls from widget properties over to ancestor composition with "scope" widgets. The rationale for this is that we were accumulating a lot of configurations: control color, handle builder, magnifier builder, toolbar builder, objects to show/hide each of those.

Should we repeat the approach from SuperEditor for SuperTextField and introduce scope widgets? Or should we introduce widget properties? Either way, we should probably do that in a separate PR, but we can decide the best approach while we're here.

@angelosilvestre
Copy link
Collaborator Author

Should we repeat the approach from SuperEditor for SuperTextField and introduce scope widgets? Or should we introduce widget properties? Either way, we should probably do that in a separate PR, but we can decide the best approach while we're here.

@matthew-carroll If we want to be consistent, we probably want to use the same approach from SuperEditor. The downsides is that it's a bit more difficult for app developers than just using widget properties and less discoverable (intelisense won't help them). We'll need good docs and probably mention that in the README.

@matthew-carroll
Copy link
Contributor

@angelosilvestre can you file an issue about compositional overlay controls to match SuperEditor?

Copy link
Contributor

@matthew-carroll matthew-carroll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Pending the "(on iOS)" suffix for the test runner

@matthew-carroll
Copy link
Contributor

@angelosilvestre can you take the last step for this PR?

@angelosilvestre
Copy link
Collaborator Author

@matthew-carroll Opened Flutter-Bounty-Hunters/testing#1 to add the suffixes directly on the testWidgetsOnXXXXX and removed from the editor tests.

@matthew-carroll
Copy link
Contributor

@angelosilvestre I merged your PR in the testing repo

@angelosilvestre
Copy link
Collaborator Author

@matthew-carroll Already removed the suffixes from here.

I think #1593 needs to get merged to fix the tests.

@matthew-carroll
Copy link
Contributor

@angelosilvestre did you check all the tests to make sure there aren't any new failures aside from those existing problems?

@angelosilvestre
Copy link
Collaborator Author

@matthew-carroll All failing tests are failing due to the compilation error related to the RawKeyEvent -> KeyEvent migration.

@matthew-carroll matthew-carroll merged commit ab19396 into superlistapp:main Nov 26, 2023
6 of 11 checks passed
angelosilvestre added a commit to angelosilvestre/super_editor that referenced this pull request Nov 26, 2023
@angelosilvestre angelosilvestre deleted the 1602_popover_overlay branch November 26, 2023 23:20
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

Successfully merging this pull request may close these issues.

[SuperTextField] - Toolbar should respect app theme brightness
2 participants