-
Notifications
You must be signed in to change notification settings - Fork 108
Adding a custom gesture recognizer for workspace-level interaction. #172
Conversation
dd2d1a8
to
35eb6c0
Compare
Review status: 0 of 4 files reviewed at latest revision, all discussions resolved. Comments from Reviewable |
Review status: 0 of 4 files reviewed at latest revision, 10 unresolved discussions. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 2 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L2)):
wrong header. Should be the apache license header. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 53 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L53)):
Typically something simple like this should just be done in a while loop to reduce overhead. eg: Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 77 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L77)):
Toolbox and Trash seem like they're mutually exclusive. Why not if inToolbox, else if inTrash, else? Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 124 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L124)):
please use the same loop pattern as you use in began and ended --> for touch in touches. It makes it easier to follow the code. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 126 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L126)):
huh...I was not expecting to find that iOS reuses the object and just keeps updating it. Blockly/Code/UI/View Controllers/WorkbenchViewController.swift, line 709 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/WorkbenchViewController.swift#L709)):
s/folder/flyout/ It looks like we'll need to do a find/replace on things. We're using flyout pretty consistently across Android and Web and should keep referring to it as flyout on iOS. Blockly/Code/UI/View Controllers/WorkbenchViewController.swift, line 719 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/WorkbenchViewController.swift#L719)):
s/folder/flyout/ Blockly/Code/UI/View Controllers/WorkbenchViewController.swift, line 720 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/WorkbenchViewController.swift#L720)):
nit ws Blockly/Code/UI/View Controllers/WorkbenchViewController.swift, line 753 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/WorkbenchViewController.swift#L753)):
nit ws Blockly/Code/UI/View Controllers/WorkbenchViewController.swift, line 809 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/WorkbenchViewController.swift#L809)):
nit line length Comments from Reviewable |
fae6349
to
7c19576
Compare
Review status: 0 of 4 files reviewed at latest revision, 10 unresolved discussions. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 2 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L2)):
|
7c19576
to
be132eb
Compare
I have some concerns with this implementation:
I believe this implementation needs to be a completely custom gesture recognizer and handle the logic of transitioning into the right state. Ideally, this class should basically only deal with tracking BlockViews and all business logic should remain in WorkbenchViewController. Here's an idea for getting around "transferring a gesture recognizer" problem:
We can talk more in person tomorrow for ideas. Review status: 0 of 4 files reviewed at latest revision, 28 unresolved discussions. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 11 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L11)):
Nit: Remove extra line and alphabetize imports Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 14 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L14)):
Add class comment. Shouldn't this be a completely custom gesture recognizer? Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 17 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L17)):
Add comments for each ivar. You can use shorthand "///" (three slashes) if each comment is 2 or less lines. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 26 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L26)):
Add public keyword and XCode doc. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 28 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L28)):
Can this class be refactored without a dependency to WorkbenchViewController? Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 35 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L35)):
Move private method to bottom of class (under a Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 36 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L36)):
Add backquote (`) around BlockView, so it shows up differently in XCode doc. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 39 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L39)):
Add backquotes around objects. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 41 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L41)):
Add space after Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 49 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L49)):
I think this should stop on the view this gesture recognizer is attached to, not the workbench. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 77 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L77)):
|
153cdba
to
0d532ed
Compare
Review status: 0 of 4 files reviewed at latest revision, 28 unresolved discussions. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 11 [r1] ([raw file](https://github.com/google/blockly-ios/blob/35eb6c0a7223d61097ad82d358e9eb6855e8d578/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L11)):
|
0d532ed
to
187aec6
Compare
Looking a lot better! Some bugs found still:
Comments below...address those first and then I'll do another pass after cleanup. Review status: 0 of 4 files reviewed at latest revision, 35 unresolved discussions. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 21 [r3] ([raw file](https://github.com/google/blockly-ios/blob/0d532ed64208134096a18e94acbd532b2e178d15/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L21)):
Nit: Add backquotes. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 30 [r3] ([raw file](https://github.com/google/blockly-ios/blob/0d532ed64208134096a18e94acbd532b2e178d15/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L30)):
To keep this consistent with the rest of the XCode doc: "The touch position in the UIView coordinate system" Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 37 [r3] ([raw file](https://github.com/google/blockly-ios/blob/0d532ed64208134096a18e94acbd532b2e178d15/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L37)):
Remove ; It's confusing overloading state for our purposes here. It's better to create a custom enum and pass that around. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 47 [r3] ([raw file](https://github.com/google/blockly-ios/blob/0d532ed64208134096a18e94acbd532b2e178d15/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L47)):
"public weak var targetDelegate: BlocklyPanGestureDelegate?" Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 49 [r3] ([raw file](https://github.com/google/blockly-ios/blob/0d532ed64208134096a18e94acbd532b2e178d15/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L49)):
Add ", in the UIView coordinate system" Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 50 [r3] ([raw file](https://github.com/google/blockly-ios/blob/0d532ed64208134096a18e94acbd532b2e178d15/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L50)):
"public var minimumPanDistance" Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 58 [r3] ([raw file](https://github.com/google/blockly-ios/blob/0d532ed64208134096a18e94acbd532b2e178d15/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L58)):
For one or two liners, you can just use "///". Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 36 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L36)):
The style I've been using for delegate method signatures has been to echo the class name first. I'd change it to this: ie. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 53 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L53)):
Define this inline and remove the initialization in the init(): private var _touches = UITouch Can _touches and _blocks be combined into a dictionary? UITouch is hashable and equatable. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 56 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L56)):
Define this inline and remove the initialization in the init(): private var _blocks = BlockView Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 80 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L80)):
Remove workbench and action parameters. Change to Rename Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 85 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L85)):
Can Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 86 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L86)):
Based on the implementation below, it doesn't seem like _destinationView is needed either. All calls to locationInView could just be done on Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 104 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L104)):
Does super.touchesBegan() need to be fired? If so, shouldn't it be at the beginning of the method (like in touchesMoved and touchesEnded)? Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 107 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L107)):
Combine if statements into one. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 112 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L112)):
I think it's awkward having the delegate return something. It's not clear why something is being returned and how the gesture recognizer would use it. I think a better implementation would be to do this:
Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 134 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L134)):
Same question about calling super here. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 183 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L183)):
Same question about calling super here. Blockly/Code/UI/View Controllers/WorkbenchViewController.swift, line 35 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/WorkbenchViewController.swift#L35)):
Move this protocol declaration to the extension that implements the method. Blockly/Code/UI/View Controllers/WorkbenchViewController.swift, line 141 [r4] ([raw file](https://github.com/google/blockly-ios/blob/187aec6736b0a2ce8068bf1cb3a0ff1b1af4f36c/Blockly/Code/UI/View Controllers/WorkbenchViewController.swift#L141)):
Can this be reverted back to before now? Comments from Reviewable |
187aec6
to
78798ab
Compare
Scroll space wasn't getting cleared up because technically the scrollView is tracking when the scrolling fails, which is basically "any time there's a touch being handled." It was being obscured previously by the block views. Turned off zooming for any workspace other than the main one. Fixed the drag out functionality. Review status: 0 of 4 files reviewed at latest revision, 35 unresolved discussions. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 21 at r3 ([raw file](https://github.com/google/blockly-ios/blob/0d532ed64208134096a18e94acbd532b2e178d15/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L21)):
|
78798ab
to
2452e6e
Compare
Nice! Almost there :) Found a few bugs:
Review status: 0 of 4 files reviewed at latest revision, 44 unresolved discussions. Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift, line 37 at r3 ([raw file](https://github.com/google/blockly-ios/blob/0d532ed64208134096a18e94acbd532b2e178d15/Blockly/Code/UI/View Controllers/BlocklyPanGestureRecognizer.swift#L37)):
|
2452e6e
to
af494e6
Compare
Spoke offline - I've seen the first bug before, but I think it's just the device erroneously thinking the first touch has moved, rather than an error with this implementation. Fixed the trash can highlight with multiple drags (and the subsequent bug where the trash can reset when dropping a block not currently touching the trash can.) I haven't seen that yet, but I'll keep testing and see what I can figure out. Review status: 0 of 4 files reviewed at latest revision, 44 unresolved discussions. Blockly/Code/UI/View Controllers/WorkbenchViewController.swift, line 944 at r5 ([raw file](https://github.com/google/blockly-ios/blob/2452e6eeb1b26c92f901ddae835bc8160d4f8767/Blockly/Code/UI/View Controllers/WorkbenchViewController.swift#L944)):
|
Found a couple more bugs:
Sorry for being so tough on this CL. Touch is VERY IMPORTANT to user interaction (ALL CAPS!), so I just want to make sure we get it working 100%. Review status: 0 of 4 files reviewed at latest revision, 38 unresolved discussions. Blockly/Code/UI/BlocklyPanGestureRecognizer.swift, line 37 at r3 (raw file):
|
af494e6
to
00371a3
Compare
Fixed the first by splitting the gesture recognizing bookkeeping further from the delegate. Added #175 for the second. And it's okay. I'd be lying if I said it wasn't frustrating, but that's not your fault. ;) Review status: 0 of 4 files reviewed at latest revision, 38 unresolved discussions. Blockly/Code/UI/BlocklyPanGestureRecognizer.swift, line 37 at r3 (raw file):
|
As discussed offline, it looks like there's only one remaining bug that needs to be addressed. Steps to reproduce:
Review status: 0 of 4 files reviewed at latest revision, 47 unresolved discussions. Blockly/Code/UI/BlocklyPanGestureRecognizer.swift, line 151 at r6 (raw file):
|
dfa7927
to
1f15457
Compare
Fixed in ZIndexedGroupView. I'm not 100% convinced this is the right place, but the containerView is the only place that uses this class, and I want to fix the hit testing of the containerView. Review status: 0 of 5 files reviewed at latest revision, 47 unresolved discussions. Blockly/Code/UI/BlocklyPanGestureRecognizer.swift, line 151 at r6 (raw file):
|
1f15457
to
1e38e64
Compare
Yeah, it's probably not the "correct" place, but we can leave it there until we find we're using it somewhere else. Thanks for your hard work on this! Review status: 0 of 5 files reviewed at latest revision, 50 unresolved discussions, some commit checks failed. Blockly/Code/UI/BlocklyPanGestureRecognizer.swift, line 63 at r7 (raw file):
|
fd9cff2
to
7e07794
Compare
Review status: 0 of 6 files reviewed at latest revision, 50 unresolved discussions, some commit checks failed. Blockly/Code/UI/BlocklyPanGestureRecognizer.swift, line 63 at r7 (raw file):
|
This should reduce overhead for gesture recognition and allow for better multi-touch interactions (like dragging children of currently-dragged blocks.)
7e07794
to
0e72640
Compare
This should reduce overhead for gesture recognition and allow for better
multi-touch interactions (like dragging children of currently-dragged blocks.)
This change is