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

Add 'Share' button to the selection toolbar on Android #139479

Conversation

bleroux
Copy link
Contributor

@bleroux bleroux commented Dec 4, 2023

Description

This PR adds the 'Share' button to the text selection toolbar on Android.

Related Issue

Fixes #138728

Tests

Refactor a lot of existing tests in order to:

  • make them more readable (avoid duplication by introducing helper functions, specify explictly check which buttons are expected).
  • make them more accurate (check that expected buttons are visible instead of just checking the number of buttons).

For instance, previous tests contained sections such as:

      // Collapsed toolbar shows 3 buttons.
      expect(
        find.byType(CupertinoButton),
        isContextMenuProvidedByPlatform ? findsNothing : isTargetPlatformIOS ? findsNWidgets(6) : findsNWidgets(3)
      );

Where the comment is obsolete, the two cases (6 widgets and 3 widgets) are not explicit (which buttons are expected?), and not accurate (will pass if the number of buttons is right but the buttons are the wrong ones).

@github-actions github-actions bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. f: cupertino flutter/packages/flutter/cupertino repository labels Dec 4, 2023
@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #139479 at sha 74b42ed

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Dec 4, 2023
@bleroux
Copy link
Contributor Author

bleroux commented Dec 4, 2023

FYI, the golden change for material.text_field_opacity_test.0 is expected because it is a golden showing the text selection toolbar on Android and this PR adds the Share option to this menu.

@bleroux bleroux force-pushed the add_android_share_option_to_selection_toolbar branch from 74b42ed to 3e9b284 Compare December 5, 2023 15:16
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #139479 at sha 3e9b284

@@ -671,6 +664,8 @@ void main() {
selectionColor: selectionColor,
cursorColor: cursorColor,
child: Column(
// TODO(bleroux): investigate why the test fail without setting the mainAxisAlignment.
Copy link
Contributor

Choose a reason for hiding this comment

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

That is interesting, was this test working with no changes before this PR? I don't see why this PR would cause that to change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I can confirm that this test is working on master without this change.
With this PR, I just found that another solution to make this test green is to add a call to pumpAndSettle() on line 692, so there is probably an animation going on.
Do you think it is better to keep this TODO or to replace it with the call to pumpAndSettle? There are dozens of pumpAndSettle in this test file, so I think it makes sense to use one here, the remaining question is why was it not necesseray before? (it might be related to the toolbar content being longer than before).

Copy link
Contributor

Choose a reason for hiding this comment

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

Adding a pumpAndSettle sounds reasonable. I tried the pr out locally and found that if I change the logic in bool get shareEnabled to the code below the test passes. I'm not at all sure why this works. I think we should we keep the switch statement and add a pumpAndSettle since we might support other platforms.

    if (defaultTargetPlatform != TargetPlatform.iOS || defaultTargetPlatform != TargetPlatform.android) {
      return false;
    }

    return !widget.obscureText
        && !textEditingValue.selection.isCollapsed
        && textEditingValue.selection.textInside(textEditingValue.text).trim() != '';

} else {
expect(find.text('Share'), findsOneWidget);
await tester.tap(find.text('Share'));
expect(lastShare, 'Test');
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: consider moving expect(lastShare, 'Test'); out of this if statement since it is common to both branches.

@@ -144,6 +143,41 @@ void main() {
return renderEditable;
}

// Check that the Cupertino text selection toolbar is the expected one on iOS and macOS.
// TODO(bleroux): try to merge this into text_selection_toolbar_utils.dart
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 planned for this PR, or in the future?, same for below.

Copy link
Contributor Author

@bleroux bleroux Dec 6, 2023

Choose a reason for hiding this comment

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

I plan to work on this later because it is not a blocker for this PR and it requires some careful thinking because:

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good to me!

@Renzo-Olivares
Copy link
Contributor

Thank you for the contribution @bleroux! These improvements to tests are awesome! I just had a few small comments, but this look great!

@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #139479 at sha 075f9dc

Copy link
Contributor

@Renzo-Olivares Renzo-Olivares left a comment

Choose a reason for hiding this comment

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

LGTM after the pumpAndSettle is added. Thanks for the contribution @bleroux

@bleroux bleroux force-pushed the add_android_share_option_to_selection_toolbar branch from 075f9dc to a29f89a Compare December 8, 2023 13:15
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #139479 at sha a29f89a

@bleroux bleroux added the autosubmit Merge PR when tree becomes green via auto submit App label Dec 8, 2023
@auto-submit auto-submit bot merged commit e070417 into flutter:master Dec 8, 2023
67 checks passed
@bleroux bleroux deleted the add_android_share_option_to_selection_toolbar branch December 8, 2023 15:35
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 8, 2023
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Dec 8, 2023
auto-submit bot pushed a commit that referenced this pull request Dec 27, 2023
…9738)

## Description

This PR adds custom system-wide text selection toolbar buttons on Android.
~~This is a WIP until #139479 is merged (potential conflicts).~~

## Related Issue

Fixes #139361

## Tests

Adds 5 tests.
CoderDake pushed a commit to CoderDake/flutter that referenced this pull request Dec 28, 2023
…tter#139738)

## Description

This PR adds custom system-wide text selection toolbar buttons on Android.
~~This is a WIP until flutter#139479 is merged (potential conflicts).~~

## Related Issue

Fixes flutter#139361

## Tests

Adds 5 tests.
victoreronmosele pushed a commit to victoreronmosele/flutter that referenced this pull request Jan 6, 2024
…tter#139738)

## Description

This PR adds custom system-wide text selection toolbar buttons on Android.
~~This is a WIP until flutter#139479 is merged (potential conflicts).~~

## Related Issue

Fixes flutter#139361

## Tests

Adds 5 tests.
Michal-MK pushed a commit to Michal-MK/flutter that referenced this pull request Jan 8, 2024
…tter#139738)

## Description

This PR adds custom system-wide text selection toolbar buttons on Android.
~~This is a WIP until flutter#139479 is merged (potential conflicts).~~

## Related Issue

Fixes flutter#139361

## Tests

Adds 5 tests.
Markzipan pushed a commit to Markzipan/flutter that referenced this pull request Jan 9, 2024
## Description

This PR adds the 'Share' button to the text selection toolbar on Android.

## Related Issue

Fixes flutter#138728

## Tests

Refactor a lot of existing tests in order to:
- make them more readable (avoid duplication by introducing helper functions, specify explictly check which buttons are expected).
- make them more accurate (check that expected buttons are visible instead of just checking the number of buttons).

For instance, previous tests contained sections such as:

```dart

      // Collapsed toolbar shows 3 buttons.
      expect(
        find.byType(CupertinoButton),
        isContextMenuProvidedByPlatform ? findsNothing : isTargetPlatformIOS ? findsNWidgets(6) : findsNWidgets(3)
      );

```

Where the comment is obsolete, the two cases (6 widgets and 3 widgets) are not explicit (which buttons are expected?), and not accurate (will pass if the number of buttons is right but the buttons are the wrong ones).
Markzipan pushed a commit to Markzipan/flutter that referenced this pull request Jan 9, 2024
…tter#139738)

## Description

This PR adds custom system-wide text selection toolbar buttons on Android.
~~This is a WIP until flutter#139479 is merged (potential conflicts).~~

## Related Issue

Fixes flutter#139361

## Tests

Adds 5 tests.
auto-submit bot pushed a commit that referenced this pull request Jan 23, 2024
## Description

This PR adds the share button to text selection toolbar buttons on Android ~~and iOS~~ for `SelectableRegion` (and therefore `SelectionArea`).

#139479 adds this button for `EditableText` (which is used by `TextField` and `SelectableText` but not by `SelectionArea`).

**Edit**: supporting this on iOS will need more work (see #141447 (comment) and #141775).

## Related Issue

Follow up for #138728

## Tests

Adds 1 test.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a: text input Entering text in a text field or keyboard related problems autosubmit Merge PR when tree becomes green via auto submit App f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Android] Add 'Share' button to selection controls
2 participants