-
Notifications
You must be signed in to change notification settings - Fork 272
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
fix: non-responder wrapping host elements ignore disabled prop #572
fix: non-responder wrapping host elements ignore disabled prop #572
Conversation
Sounds reasonable. @mdjastrzebski could you take a look? |
Overall I like the idea. I have some concerns about code readability that has deteriored, because the code simply got more complex. I think that introducing some helper variables with descriptive names can help here. Also some code comments would be welcomed. |
@mdjastrzebski just updated the code, hopefully it's a bit more readable. Let me know if you have an specific suggestions |
@adkenyon Your code comments help a lot but honestly I still need to wrap my head arounds this. I hope I'll be able to review this tomorrow. |
Thanks @mdjastrzebski. I ran into this issue upgrading RNTL to the latest (we were on ~6). The example here is a bit contrived, let me know you you need more examples |
@adkenyon sorry for late reply, but it took me some longer time to actually wrap my head around current implmentation and your proposed changes. I've done some clean up to simplify structure and improve readability. Please review my changes. Behavior explanationI've diagnosed the RNTL behavior and saw that the cause why your event handler is called is not As you see our Scope of the changesThis fix handles only case when composite component prop is named exactly as child host component.
I guess that having same named event props on composite components and host components is quite common, e.g. in buttons or any kind of simple wrappers, so I think this change is a good idea. |
Thanks @adkenyon for your contribution ❤️ and @mdjastrzebski for cleanups! |
Summary
Effectively, wrapping a disabled
Touchable
with a non-responder host element (plain oldView
) will ignore thedisabled
prop. In the example below (same as spec file),fireEvent.press(screen.getByText('Trigger'));
should not trigger thehandlePress
mock function as theTestChildTouchableComponent
TouchableOpacity is disabled. Since the wrappingView
inTestChildTouchableComponent
is a host element it is then considered thenearestHostDescendant
. Since it is not disabled then the event will eventually trigger.The solution was to only pass host elements that are responders as
nearestHostDescendant
's