Skip to content

feat: prevent events on disabled elements #460

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

Merged
merged 7 commits into from
Jul 28, 2020

Conversation

mdjastrzebski
Copy link
Member

@mdjastrzebski mdjastrzebski commented Jul 27, 2020

Summary

Prevent calling event handlers for disabled components.

Fixes #28

Test plan

Added tests for TouchableOpacity and Pressable in two configuration: lone element (expected throw no handler found) and nested elements: inner disabled, outer handling event.

@mdjastrzebski mdjastrzebski requested a review from thymikee July 27, 2020 11:17
@mdjastrzebski mdjastrzebski force-pushed the feat/prevent-events-on-disabled-elements branch from 2d0f8f0 to 1ebd7ce Compare July 27, 2020 11:19
@mdjastrzebski mdjastrzebski changed the title Feat/prevent events on disabled elements feat: prevent events on disabled elements Jul 27, 2020
@mdjastrzebski mdjastrzebski requested a review from thymikee July 28, 2020 08:04
@mdjastrzebski
Copy link
Member Author

I've managed to implement this using props.onStartShouldSetResponder(), the same check that React Native uses to verify whether it should start events. The problematic issues has been that, when using React Test Renderer output, event handlers like onPress are usually props of composite components while props.onStartShouldSetResponder() is available on a descedant host component.

This implementation captures the last host component when traversing up the element tree when looking for event handler.

@thymikee thymikee marked this pull request as ready for review July 28, 2020 08:38
@mdjastrzebski mdjastrzebski force-pushed the feat/prevent-events-on-disabled-elements branch from ddd63f8 to 44a9d27 Compare July 28, 2020 08:43
@thymikee
Copy link
Member

Please update the migration guide accordingly as well :)

@mdjastrzebski
Copy link
Member Author

Updated docs

@mdjastrzebski mdjastrzebski requested a review from Esemesek July 28, 2020 09:56
@thymikee thymikee merged commit 611c60f into 7.x Jul 28, 2020
@thymikee thymikee deleted the feat/prevent-events-on-disabled-elements branch July 28, 2020 13:11
thymikee pushed a commit that referenced this pull request Jul 30, 2020
* feat: add tests

* feat: prevent event handling on disabled element

* refactor: code cleanup

* feat: use props.onStartShouldSetResponder to check for event handling

* refactor: code review changes

* feat: updated docs

* feat: added test for fake 'disabled' prop
thymikee pushed a commit that referenced this pull request Jul 30, 2020
* feat: add tests

* feat: prevent event handling on disabled element

* refactor: code cleanup

* feat: use props.onStartShouldSetResponder to check for event handling

* refactor: code review changes

* feat: updated docs

* feat: added test for fake 'disabled' prop
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.

2 participants