-
Notifications
You must be signed in to change notification settings - Fork 253
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
matthew-carroll
merged 3 commits into
superlistapp:main
from
angelosilvestre:1602_popover_overlay
Nov 26, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import 'package:super_editor/src/infrastructure/flutter/flutter_scheduler.dart'; | |
import 'package:super_editor/src/infrastructure/focus.dart'; | ||
import 'package:super_editor/src/infrastructure/ime_input_owner.dart'; | ||
import 'package:super_editor/src/infrastructure/platforms/android/toolbar.dart'; | ||
import 'package:super_editor/src/infrastructure/signal_notifier.dart'; | ||
import 'package:super_editor/src/infrastructure/touch_controls.dart'; | ||
import 'package:super_editor/src/super_textfield/android/_editing_controls.dart'; | ||
import 'package:super_editor/src/super_textfield/android/_user_interaction.dart'; | ||
|
@@ -168,10 +169,12 @@ class SuperAndroidTextFieldState extends State<SuperAndroidTextField> | |
|
||
late TextScrollController _textScrollController; | ||
|
||
// OverlayEntry that displays the toolbar and magnifier, and | ||
// positions the invisible touch targets for base/extent | ||
// dragging. | ||
OverlayEntry? _controlsOverlayEntry; | ||
/// Opens/closes the popover that displays the toolbar and magnifier, and | ||
// positions the invisible touch targets for base/extent dragging. | ||
final _popoverController = OverlayPortalController(); | ||
|
||
/// Notifies the popover toolbar to rebuild itself. | ||
final _popoverRebuildSignal = SignalNotifier(); | ||
|
||
@override | ||
void initState() { | ||
|
@@ -293,6 +296,8 @@ class SuperAndroidTextFieldState extends State<SuperAndroidTextField> | |
..removeListener(_onTextScrollChange) | ||
..dispose(); | ||
|
||
_popoverRebuildSignal.dispose(); | ||
|
||
WidgetsBinding.instance.removeObserver(this); | ||
|
||
super.dispose(); | ||
|
@@ -359,46 +364,32 @@ class SuperAndroidTextFieldState extends State<SuperAndroidTextField> | |
} | ||
|
||
void _onTextScrollChange() { | ||
if (_controlsOverlayEntry != null) { | ||
if (_popoverController.isShowing) { | ||
_rebuildEditingOverlayControls(); | ||
} | ||
} | ||
|
||
/// Displays [AndroidEditingOverlayControls] in the app's [Overlay], if not already | ||
/// Displays [AndroidEditingOverlayControls] in the [OverlayPortal], if not already | ||
/// displayed. | ||
void _showEditingControlsOverlay() { | ||
if (_controlsOverlayEntry == null) { | ||
_controlsOverlayEntry = OverlayEntry(builder: (overlayContext) { | ||
return AndroidEditingOverlayControls( | ||
editingController: _editingOverlayController, | ||
textScrollController: _textScrollController, | ||
textFieldLayerLink: _textFieldLayerLink, | ||
textFieldKey: _textFieldKey, | ||
textContentLayerLink: _textContentLayerLink, | ||
textContentKey: _textContentKey, | ||
tapRegionGroupId: widget.tapRegionGroupId, | ||
handleColor: widget.handlesColor, | ||
popoverToolbarBuilder: widget.popoverToolbarBuilder, | ||
showDebugPaint: widget.showDebugPaint, | ||
); | ||
}); | ||
|
||
Overlay.of(context).insert(_controlsOverlayEntry!); | ||
if (!_popoverController.isShowing) { | ||
_popoverController.show(); | ||
} | ||
} | ||
|
||
/// Rebuilds the [AndroidEditingControls] in the app's [Overlay], if | ||
/// Rebuilds the [AndroidEditingOverlayControls] in the [OverlayPortal], if | ||
/// they're currently displayed. | ||
void _rebuildEditingOverlayControls() { | ||
_controlsOverlayEntry?.markNeedsBuild(); | ||
if (_popoverController.isShowing) { | ||
_popoverRebuildSignal.notifyListeners(); | ||
} | ||
} | ||
|
||
/// Removes [AndroidEditingControls] from the app's [Overlay], if they're | ||
/// Hides the [AndroidEditingOverlayControls] in the [OverlayPortal], if they're | ||
/// currently displayed. | ||
void _removeEditingOverlayControls() { | ||
if (_controlsOverlayEntry != null) { | ||
_controlsOverlayEntry!.remove(); | ||
_controlsOverlayEntry = null; | ||
if (_popoverController.isShowing) { | ||
_popoverController.hide(); | ||
} | ||
} | ||
|
||
|
@@ -497,6 +488,14 @@ class SuperAndroidTextFieldState extends State<SuperAndroidTextField> | |
|
||
@override | ||
Widget build(BuildContext context) { | ||
return OverlayPortal( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated. |
||
controller: _popoverController, | ||
overlayChildBuilder: _buildPopoverToolbar, | ||
child: _buildTextField(), | ||
); | ||
} | ||
|
||
Widget _buildTextField() { | ||
return TapRegion( | ||
groupId: widget.tapRegionGroupId, | ||
child: NonReparentingFocus( | ||
|
@@ -578,6 +577,26 @@ class SuperAndroidTextFieldState extends State<SuperAndroidTextField> | |
), | ||
); | ||
} | ||
|
||
Widget _buildPopoverToolbar(BuildContext context) { | ||
return ListenableBuilder( | ||
listenable: _popoverRebuildSignal, | ||
builder: (context, _) { | ||
return AndroidEditingOverlayControls( | ||
editingController: _editingOverlayController, | ||
textScrollController: _textScrollController, | ||
textFieldLayerLink: _textFieldLayerLink, | ||
textFieldKey: _textFieldKey, | ||
textContentLayerLink: _textContentLayerLink, | ||
textContentKey: _textContentKey, | ||
tapRegionGroupId: widget.tapRegionGroupId, | ||
handleColor: widget.handlesColor, | ||
popoverToolbarBuilder: widget.popoverToolbarBuilder, | ||
showDebugPaint: widget.showDebugPaint, | ||
); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
Widget _defaultAndroidToolbarBuilder( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
andFollower
instead?There was a problem hiding this comment.
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
andFollower
, but it will require big change. I'm not sure we should do that on this PR.There was a problem hiding this comment.
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?