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 popover toolbar builder that uses Flutter's new support for an iOS 16+ system toolbar (Resolves #2032) #2058

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

matthew-carroll
Copy link
Contributor

@matthew-carroll matthew-carroll commented May 29, 2024

Add popover toolbar builder that uses Flutter's new support for an iOS 16+ system toolbar (Resolves #2032)

Also renamed some files for that were still using the unnecessary underscore "_" prefix.

The following code snippet should let you try the new SuperIOSTextField toolbar:

class _iOSSuperTextField extends StatefulWidget {
  const _iOSSuperTextField();

  @override
  State<_iOSSuperTextField> createState() => _iOSSuperTextFieldState();
}

class _iOSSuperTextFieldState extends State<_iOSSuperTextField> {
  final _textFieldKey = GlobalKey();
  final _focusNode = FocusNode();
  final _textController = ImeAttributedTextEditingController(
    controller: AttributedTextEditingController(
      text: AttributedText("This is some text to copy and paste."),
    ),
  );

  @override
  void dispose() {
    _textController.dispose();
    _focusNode.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return TapRegion(
      groupId: "textfields",
      onTapOutside: (_) => _focusNode.unfocus(),
      child: TextFieldBorder(
        focusNode: _focusNode,
        borderBuilder: _borderBuilder,
        child: SuperIOSTextField(
          key: _textFieldKey,
          focusNode: _focusNode,
          tapRegionGroupId: "textfields",
          textController: _textController,
          textStyleBuilder: _textStyleBuilder,
          hintBuilder: _createHintBuilder("Enter single line text..."),
          padding: const EdgeInsets.all(4),
          minLines: 1,
          maxLines: 1,
          caretStyle: CaretStyle().copyWith(color: Colors.red),
          selectionColor: Colors.red,
          handlesColor: Colors.red,
          popoverToolbarBuilder: iOSSystemPopoverToolbarWithBackupFlutterVersion,
        ),
      ),
    );
  }
}

@matthew-carroll
Copy link
Contributor Author

@BazinC - I added iOS system menu support to SuperIOSTextfield - would you like to try that out on the text field before I add it to SuperEditor?

Copy link
Collaborator

@angelosilvestre angelosilvestre left a comment

Choose a reason for hiding this comment

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

LGTM with a single comment.


/// An [IOSPopoverToolbarBuilder] that displays the iOS system popover toolbar, if the version of
/// iOS is recent enough, otherwise builds [defaultIosPopoverToolbarBuilder].
Widget iOSSystemPopoverToolbarWithBackupFlutterVersion(BuildContext context, IOSEditingOverlayController controller) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is WithBackupFlutterVersion an appropriate name? I think iOSSystemPopoverToolbarWithFallback would be simpler.

@BazinC
Copy link
Contributor

BazinC commented Jul 5, 2024

@BazinC - I added iOS system menu support to SuperIOSTextfield - would you like to try that out on the text field before I add it to SuperEditor?

@matthew-carroll We don't use SuperIOSText. Is this PR related to the following comment? #2032 (comment)
Is it still pending on Flutter side?

@matthew-carroll
Copy link
Contributor Author

@BazinC this PR adds the use of the native menu. It adds it to SuperTextField, first, because that's simpler. Can you please try out a SuperTextField on iOS and check if the native menu meets your expectations?

If we need to make changes to the behavior, or if the menu won't work, then it's less expensive to discover that here and now.

@BazinC
Copy link
Contributor

BazinC commented Jul 9, 2024

@matthew-carroll can you tell me which Flutter version you used for this branch?
SystemContextMenu is only available on master and I fail to run the demo on master

logs
corentinbazin@macbook-pro example % flutter run lib/flutter_demos/main_flutter_textfield.dart -d 00008110-001229512698401E
Launching lib/flutter_demos/main_flutter_textfield.dart on iPhone in debug mode...
Upgrading AppFrameworkInfo.plist
Upgrading Podfile
Upgrading Info.plist
ios/Runner/AppDelegate.swift uses the deprecated @UIApplicationMain attribute, updating.
Automatically signing iOS for device deployment using specified development team in Xcode project: 5RJWFAUGXQ
Running pod install...                                             807ms
Running Xcode build...                                                  
Xcode build done.                                           13.9s
Failed to build iOS app
Could not build the precompiled application for the device.
Error (Xcode): ../../../../../.pub-cache/hosted/pub.dev/win32-5.0.9/lib/src/guid.dart:32:9: Error: Type 'UnmodifiableUint8ListView' not found.



Error launching application on iPhone.
corentinbazin@macbook-pro example % flutter doctor                                                                        
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel master, 3.24.0-1.0.pre.54, on macOS 14.5 23F79 darwin-arm64, locale en-FR)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.1)
[✓] VS Code (version 1.91.0)
[✓] Connected device (5 available)
    ! Error: Browsing on the local area network for iPhone de Alois. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
      The device must be opted into Developer Mode to connect wirelessly. (code -27)
    ! Error: Browsing on the local area network for Corentin’s Apple Watch. Ensure the device is unlocked and discoverable via Bluetooth. (code -27)
[✓] Network resources

• No issues found!

Tried again after cleaning pub_cache, with no luck

@matthew-carroll
Copy link
Contributor Author

@BazinC I brought in the latest changes from main in case that was causing an issue.

As for the Flutter branch - I just tried on Beta and the context menu works, so you don't need to be on master.

For the demo - run the "Example - All Demos" and then choose the iOS super text field from the navigation drawer. When you open the editing toolbar in that demo, it will be the native iOS edit menu.

@BazinC
Copy link
Contributor

BazinC commented Jul 9, 2024

@BazinC I brought in the latest changes from main in case that was causing an issue.

As for the Flutter branch - I just tried on Beta and the context menu works, so you don't need to be on master.

For the demo - run the "Example - All Demos" and then choose the iOS super text field from the navigation drawer. When you open the editing toolbar in that demo, it will be the native iOS edit menu.

Thanks! I'm trying with beta now and it works!
I don't see any bug at first glance. No more "Allow/Don't Allow Paste" dialog.
One question: How customizable it could be? Now I see Cut/Copy/Paste/Delete/Select All/Autofill.
Not a big deal for now.

(Toolbar position and its arrow position look off but it's not related to this ticket)

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.

[iOS] Support native edit menu + Secure Paste
3 participants