This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
Add support for double tap action from Apple Pencil 2 #39267
Merged
auto-submit
merged 27 commits into
flutter:main
from
LouiseHsu:louisehsu/pencil-double-tap
Feb 13, 2023
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a945890
working commit
LouiseHsu 04b8708
Merge branch 'master' into louisehsu/pencil-double-tap
LouiseHsu 6b7061a
some clean up
LouiseHsu 3818c77
white space fixes
LouiseHsu 1b6c8f5
whitespace
LouiseHsu 9c31bd1
remove unused import
LouiseHsu c2450d4
Addressing PR comment, fix tests, update touch packet on Andriod
LouiseHsu 0317a34
formatting n whitespace again
LouiseHsu 61296be
add new field to web ui pointer.dart
LouiseHsu 2b5a6b9
update test
LouiseHsu c18f4e9
whitespace
LouiseHsu 9f780ce
fix test
LouiseHsu 25f6607
Merge branch 'master' into louisehsu/pencil-double-tap
LouiseHsu 2ec9688
PR comments
LouiseHsu a50f554
fix test
LouiseHsu a27ba22
whitespace
LouiseHsu 1cdf0ec
fix test by factoring out logic into helper function
LouiseHsu b348378
whitespace
LouiseHsu 4e14bbf
fix malformed string
LouiseHsu c8a8cd7
pr comments
LouiseHsu 69d1035
fix type issue
LouiseHsu b162cbc
sigh whitespace
LouiseHsu 79b790f
Merge branch 'main' into louisehsu/pencil-double-tap
LouiseHsu 912a4cc
revert test changes :)
LouiseHsu 1393fae
pr comments + separate out tests
LouiseHsu 9527282
extra space
LouiseHsu b09a991
change test name
LouiseHsu 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -56,7 +56,9 @@ | |
| // This is left a FlutterBinaryMessenger privately for now to give people a chance to notice the | ||
| // change. Unfortunately unless you have Werror turned on, incompatible pointers as arguments are | ||
| // just a warning. | ||
| @interface FlutterViewController () <FlutterBinaryMessenger, UIScrollViewDelegate> | ||
| @interface FlutterViewController () <FlutterBinaryMessenger, | ||
| UIScrollViewDelegate, | ||
| UIPencilInteractionDelegate> | ||
| @property(nonatomic, readwrite, getter=isDisplayingFlutterUI) BOOL displayingFlutterUI; | ||
| @property(nonatomic, assign) BOOL isHomeIndicatorHidden; | ||
| @property(nonatomic, assign) BOOL isPresentingViewControllerAnimating; | ||
|
|
@@ -97,7 +99,7 @@ @interface FlutterViewController () <FlutterBinaryMessenger, UIScrollViewDelegat | |
| // Trackpad rotating | ||
| @property(nonatomic, retain) | ||
| UIRotationGestureRecognizer* rotationGestureRecognizer API_AVAILABLE(ios(13.4)); | ||
|
|
||
| @property(nonatomic, retain) UIPencilInteraction* pencilInteraction API_AVAILABLE(ios(13.4)); | ||
LouiseHsu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /** | ||
| * Creates and registers plugins used by this view controller. | ||
| */ | ||
|
|
@@ -718,6 +720,10 @@ - (void)viewDidLoad { | |
| [self createTouchRateCorrectionVSyncClientIfNeeded]; | ||
|
|
||
| if (@available(iOS 13.4, *)) { | ||
| _pencilInteraction = [[UIPencilInteraction alloc] init]; | ||
| _pencilInteraction.delegate = self; | ||
| [_flutterView addInteraction:_pencilInteraction]; | ||
|
|
||
| _hoverGestureRecognizer = | ||
| [[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hoverEvent:)]; | ||
| _hoverGestureRecognizer.delegate = self; | ||
|
|
@@ -891,6 +897,8 @@ - (void)dealloc { | |
| [_pinchGestureRecognizer release]; | ||
| _rotationGestureRecognizer.delegate = nil; | ||
| [_rotationGestureRecognizer release]; | ||
| _pencilInteraction.delegate = nil; | ||
| [_pencilInteraction release]; | ||
| [super dealloc]; | ||
| } | ||
|
|
||
|
|
@@ -965,7 +973,7 @@ - (void)goToApplicationLifecycle:(nonnull NSString*)state { | |
| case UITouchTypeDirect: | ||
| case UITouchTypeIndirect: | ||
| return flutter::PointerData::DeviceKind::kTouch; | ||
| case UITouchTypeStylus: | ||
| case UITouchTypePencil: | ||
|
Contributor
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. is this change intended?
Contributor
Author
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. Yeah, UITouchTypeStylus is deprecated and is suggested https://developer.apple.com/documentation/uikit/uitouchtype/uitouchtypestylus |
||
| return flutter::PointerData::DeviceKind::kStylus; | ||
| case UITouchTypeIndirectPointer: | ||
| return flutter::PointerData::DeviceKind::kMouse; | ||
|
|
@@ -1220,6 +1228,50 @@ - (void)invalidateTouchRateCorrectionVSyncClient { | |
| _touchRateCorrectionVSyncClient = nil; | ||
| } | ||
|
|
||
| #pragma mark - Stylus Events | ||
|
|
||
| - (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE(ios(13.4)) { | ||
| flutter::PointerData pointer_data = [self createAuxillaryStylusActionData]; | ||
|
|
||
| auto packet = std::make_unique<flutter::PointerDataPacket>(1); | ||
| packet->SetPointerData(/*index=*/0, pointer_data); | ||
|
Contributor
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. you can probably put this packet creation into the helper so that it's also unit tested. |
||
| [_engine.get() dispatchPointerDataPacket:std::move(packet)]; | ||
| } | ||
|
|
||
| - (flutter::PointerData)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { | ||
| flutter::PointerData pointer_data; | ||
| pointer_data.Clear(); | ||
|
|
||
| switch (UIPencilInteraction.preferredTapAction) { | ||
| case UIPencilPreferredActionIgnore: | ||
| pointer_data.preferred_auxiliary_stylus_action = | ||
| flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore; | ||
| break; | ||
| case UIPencilPreferredActionShowColorPalette: | ||
| pointer_data.preferred_auxiliary_stylus_action = | ||
| flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette; | ||
| break; | ||
| case UIPencilPreferredActionSwitchEraser: | ||
| pointer_data.preferred_auxiliary_stylus_action = | ||
| flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchEraser; | ||
| break; | ||
| case UIPencilPreferredActionSwitchPrevious: | ||
| pointer_data.preferred_auxiliary_stylus_action = | ||
| flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchPrevious; | ||
| break; | ||
| default: | ||
| pointer_data.preferred_auxiliary_stylus_action = | ||
| flutter::PointerData::PreferredStylusAuxiliaryAction::kUnknown; | ||
| break; | ||
LouiseHsu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| pointer_data.time_stamp = [[NSProcessInfo processInfo] systemUptime] * kMicrosecondsPerSecond; | ||
| pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; | ||
| pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; | ||
|
|
||
| return pointer_data; | ||
| } | ||
|
|
||
| #pragma mark - Handle view resizing | ||
|
|
||
| - (void)updateViewportMetrics { | ||
|
|
||
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.
just double check - did framework team already agree with using this naming?
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.
its already in the design doc, and they didnt object - if they change their mind, I think it wouldnt be a big deal to change the naming.