-
-
Notifications
You must be signed in to change notification settings - Fork 1k
[android] Fix state manager on unregistered gestures #3913
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
base: next
Are you sure you want to change the base?
Conversation
m-bert
left a comment
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.
As said in the first comment, I'm not a big fan of ForManual suffix. I think we could either use overloading (where possible) or add more descriptive suffix.
| } | ||
|
|
||
| fun prepareForManual(orchestrator: GestureHandlerOrchestrator?) { | ||
| check(this.orchestrator == null) { |
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.
Shouldn't it be this.orchestrator != null? Especially that the condition that starts all this process is if (orchestrator == null).
Also, the only way to end up here is from orchestrator itself, right?
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.
The check works differently than if, this throws the provided message when the orchestrator was already set.
| interactionController = controller | ||
| } | ||
|
|
||
| fun prepareForManual(orchestrator: GestureHandlerOrchestrator?) { |
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.
I'm not a fan of this name. First of all, if it has the same purpose we could overload prepare (maybe with little comment when it is useful). If we want to keep it different, then I guess it should be more descriptive, like prepareForManualStateChange, prepareForManualManagement, or some other form.
Also, it seems to share most of the logic with prepare - we could extract it into separate function if needed so that we don't have this redundancy.
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.
Cleaned up in 27b2aa0. prepare works fine if we pass null as view, so we can just do that.
| fun recordHandlerIfNotPresentForManual(handler: GestureHandler) { | ||
| if (gestureHandlers.contains(handler)) { | ||
| return | ||
| } | ||
|
|
||
| gestureHandlers.add(handler) | ||
| handler.isActive = false | ||
| handler.isAwaiting = false | ||
| handler.activationIndex = Int.MAX_VALUE | ||
| handler.prepareForManual(this) | ||
| } |
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.
Same here, most of the logic is repeated.
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.
As above
| if (orchestrator == null) { | ||
| // If the state is set manually, the handler may not have been fully recorded by the orchestrator. | ||
| hostDetectorView?.recordHandlerIfNotPresentForManual(this) | ||
| } |
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.
I think we should throw error when both, orchestrator and hostDetectorView are null. This may happen if gesture is defined, but is not assigned to any of the detectors. In that case I believe it will still crash, but with other, less descriptive error (probably NullPointerException).
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.
Thanks, f3c1e93, I will check whether this works on other platforms
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.
On web the error is more fitting, Expected delegate view to be HTMLElement and on iOS it fails silently
Description
The new
StateManageris global and givenhandlerTagit can manually set the states of an arbitrary gesture. This causes errors, when the gesture, which state is being set, has not been yet recorded in the orchestrator. Recording gestures in the orchestrator on android is done lazily, thus if it never received touches it is not recorded.Test plan
Tested on the following example
Details