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
[Touchable] easy way to disable a Touchable* highlight? #2103
Comments
Try setting the key prop on your button and using your original approach. |
I'm not sure to get how setting Also to me, the fact that the button has highlight is very correlated to the fact that you give an onPress handler. Actually I don't see why you would expect a Touchable effect if no action is listened. I've used this pattern a lot in my react apps, using an handler not only as a callback to call but also as a way to know that the user is listening (so you can adapt the UX without introducing an extra prop). |
Can you check if it is disabled in the press handler? If you are creating a button just create a |
This feature would be handy for me as well |
to summary my need, I don't expect Touchable* to highlight if no valid handler are provided. If you agree with this I can provide a PR. |
@gre how to disable the animation when press on it |
What if we can patch touchableHandleStartShouldSetResponder: function() {
return !this.props.disabled;
}, should do the trick. I can send over a PR along with adding a new propType disabled: React.PropTypes.bool to |
sounds perfect :) is disabled also on all the Touchable components? (since it's a base class) |
@gre it should |
Summary:Introduce a `disabled` property for Touchable* components. Fix facebook#2103 Closes facebook#5931 Differential Revision: D2969790 Pulled By: mkonicek fb-gh-sync-id: 570a4ff882219f52f2d2ebef3eb73b1df50a0877 shipit-source-id: 570a4ff882219f52f2d2ebef3eb73b1df50a0877
Awesome! |
Hi,
the current pattern I've been doing for making Buttons that can be "disabled" is to do the following:
I need to do that because a disabled button should not have any "highlight" effect.
The problem with such approach is it changes the component tree which means
btn
will be re-instanciated every timedisabled
changes. One of the consequence is that ifbtn
wants to do animation, the animation will be suddenly stopped.Here is my proposal to fix that,
what if I could do that?
I'm proposing that if
onPress
is falsy, there should be no highlight effect at all on a Touchable* components.This would also make the code more maintainable because you don't have to branch your logic.
What do you think?
The text was updated successfully, but these errors were encountered: