|
56 | 56 | // This is left a FlutterBinaryMessenger privately for now to give people a chance to notice the |
57 | 57 | // change. Unfortunately unless you have Werror turned on, incompatible pointers as arguments are |
58 | 58 | // just a warning. |
59 | | -@interface FlutterViewController () <FlutterBinaryMessenger, UIScrollViewDelegate> |
| 59 | +@interface FlutterViewController () <FlutterBinaryMessenger, |
| 60 | + UIScrollViewDelegate, |
| 61 | + UIPencilInteractionDelegate> |
60 | 62 | @property(nonatomic, readwrite, getter=isDisplayingFlutterUI) BOOL displayingFlutterUI; |
61 | 63 | @property(nonatomic, assign) BOOL isHomeIndicatorHidden; |
62 | 64 | @property(nonatomic, assign) BOOL isPresentingViewControllerAnimating; |
@@ -97,7 +99,7 @@ @interface FlutterViewController () <FlutterBinaryMessenger, UIScrollViewDelegat |
97 | 99 | // Trackpad rotating |
98 | 100 | @property(nonatomic, retain) |
99 | 101 | UIRotationGestureRecognizer* rotationGestureRecognizer API_AVAILABLE(ios(13.4)); |
100 | | - |
| 102 | +@property(nonatomic, retain) UIPencilInteraction* pencilInteraction API_AVAILABLE(ios(13.4)); |
101 | 103 | /** |
102 | 104 | * Creates and registers plugins used by this view controller. |
103 | 105 | */ |
@@ -722,6 +724,10 @@ - (void)viewDidLoad { |
722 | 724 | [self createTouchRateCorrectionVSyncClientIfNeeded]; |
723 | 725 |
|
724 | 726 | if (@available(iOS 13.4, *)) { |
| 727 | + _pencilInteraction = [[UIPencilInteraction alloc] init]; |
| 728 | + _pencilInteraction.delegate = self; |
| 729 | + [_flutterView addInteraction:_pencilInteraction]; |
| 730 | + |
725 | 731 | _hoverGestureRecognizer = |
726 | 732 | [[UIHoverGestureRecognizer alloc] initWithTarget:self action:@selector(hoverEvent:)]; |
727 | 733 | _hoverGestureRecognizer.delegate = self; |
@@ -895,6 +901,8 @@ - (void)dealloc { |
895 | 901 | [_pinchGestureRecognizer release]; |
896 | 902 | _rotationGestureRecognizer.delegate = nil; |
897 | 903 | [_rotationGestureRecognizer release]; |
| 904 | + _pencilInteraction.delegate = nil; |
| 905 | + [_pencilInteraction release]; |
898 | 906 | [super dealloc]; |
899 | 907 | } |
900 | 908 |
|
@@ -969,7 +977,7 @@ - (void)goToApplicationLifecycle:(nonnull NSString*)state { |
969 | 977 | case UITouchTypeDirect: |
970 | 978 | case UITouchTypeIndirect: |
971 | 979 | return flutter::PointerData::DeviceKind::kTouch; |
972 | | - case UITouchTypeStylus: |
| 980 | + case UITouchTypePencil: |
973 | 981 | return flutter::PointerData::DeviceKind::kStylus; |
974 | 982 | case UITouchTypeIndirectPointer: |
975 | 983 | return flutter::PointerData::DeviceKind::kMouse; |
@@ -1224,6 +1232,50 @@ - (void)invalidateTouchRateCorrectionVSyncClient { |
1224 | 1232 | _touchRateCorrectionVSyncClient = nil; |
1225 | 1233 | } |
1226 | 1234 |
|
| 1235 | +#pragma mark - Stylus Events |
| 1236 | + |
| 1237 | +- (void)pencilInteractionDidTap:(UIPencilInteraction*)interaction API_AVAILABLE(ios(13.4)) { |
| 1238 | + flutter::PointerData pointer_data = [self createAuxillaryStylusActionData]; |
| 1239 | + |
| 1240 | + auto packet = std::make_unique<flutter::PointerDataPacket>(1); |
| 1241 | + packet->SetPointerData(/*index=*/0, pointer_data); |
| 1242 | + [_engine.get() dispatchPointerDataPacket:std::move(packet)]; |
| 1243 | +} |
| 1244 | + |
| 1245 | +- (flutter::PointerData)createAuxillaryStylusActionData API_AVAILABLE(ios(13.4)) { |
| 1246 | + flutter::PointerData pointer_data; |
| 1247 | + pointer_data.Clear(); |
| 1248 | + |
| 1249 | + switch (UIPencilInteraction.preferredTapAction) { |
| 1250 | + case UIPencilPreferredActionIgnore: |
| 1251 | + pointer_data.preferred_auxiliary_stylus_action = |
| 1252 | + flutter::PointerData::PreferredStylusAuxiliaryAction::kIgnore; |
| 1253 | + break; |
| 1254 | + case UIPencilPreferredActionShowColorPalette: |
| 1255 | + pointer_data.preferred_auxiliary_stylus_action = |
| 1256 | + flutter::PointerData::PreferredStylusAuxiliaryAction::kShowColorPalette; |
| 1257 | + break; |
| 1258 | + case UIPencilPreferredActionSwitchEraser: |
| 1259 | + pointer_data.preferred_auxiliary_stylus_action = |
| 1260 | + flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchEraser; |
| 1261 | + break; |
| 1262 | + case UIPencilPreferredActionSwitchPrevious: |
| 1263 | + pointer_data.preferred_auxiliary_stylus_action = |
| 1264 | + flutter::PointerData::PreferredStylusAuxiliaryAction::kSwitchPrevious; |
| 1265 | + break; |
| 1266 | + default: |
| 1267 | + pointer_data.preferred_auxiliary_stylus_action = |
| 1268 | + flutter::PointerData::PreferredStylusAuxiliaryAction::kUnknown; |
| 1269 | + break; |
| 1270 | + } |
| 1271 | + |
| 1272 | + pointer_data.time_stamp = [[NSProcessInfo processInfo] systemUptime] * kMicrosecondsPerSecond; |
| 1273 | + pointer_data.kind = flutter::PointerData::DeviceKind::kStylus; |
| 1274 | + pointer_data.signal_kind = flutter::PointerData::SignalKind::kStylusAuxiliaryAction; |
| 1275 | + |
| 1276 | + return pointer_data; |
| 1277 | +} |
| 1278 | + |
1227 | 1279 | #pragma mark - Handle view resizing |
1228 | 1280 |
|
1229 | 1281 | - (void)updateViewportMetrics { |
|
0 commit comments