You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Touchable] easy way to disable a Touchable* highlight? #2103
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 time disabled changes. One of the consequence is that if btn wants to do animation, the animation will be suddenly stopped.
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.
I'm not sure to get how setting key would change anything. btn will change its place in the tree every time disabled change so there will be a new instantiation (and all the related issues).
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 handlePress inside this button component then call the props.onPress if it isn't disabled.
Also maybe set the activeOpacity to 1 if it is disabled so on press it doesn't look like it's doing anything?
to summary my need, I don't expect Touchable* to highlight if no valid handler are provided.
A simple way to implement this is to use activeOpacity=1 if all on*Press handlers are falsy (maybe better is to completely disable the animation to trigger, i'm not aware of the complexity to do this).
Activity
ide commentedon Jul 23, 2015
Try setting the key prop on your button and using your original approach.
gre commentedon Jul 23, 2015
I'm not sure to get how setting
keywould change anything.btnwill change its place in the tree every timedisabledchange so there will be a new instantiation (and all the related issues).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).
browniefed commentedon Jul 23, 2015
Can you check if it is disabled in the press handler? If you are creating a button just create a
handlePressinside this button component then call theprops.onPressif it isn't disabled.Also maybe set the activeOpacity to 1 if it is disabled so on press it doesn't look like it's doing anything?
[-]easy way to disable a Touchable* highlight?[/-][+][Touchable] easy way to disable a Touchable* highlight?[/+]Intellicode commentedon Sep 9, 2015
This feature would be handy for me as well
gre commentedon Jan 2, 2016
to summary my need, I don't expect Touchable* to highlight if no valid handler are provided.
A simple way to implement this is to use
activeOpacity=1if all on*Press handlers are falsy (maybe better is to completely disable the animation to trigger, i'm not aware of the complexity to do this).If you agree with this I can provide a PR.
ShawnKuan commentedon Feb 15, 2016
@gre how to disable the animation when press on it
Kureev commentedon Feb 15, 2016
What if we can patch
Touchablemixin?should do the trick. I can send over a PR along with adding a new propType
to
TouchableWithoutFeedbackbase class. What do you think?gre commentedon Feb 15, 2016
sounds perfect :) is disabled also on all the Touchable components? (since it's a base class)
Kureev commentedon Feb 15, 2016
@gre it should
TheoGit commentedon Sep 7, 2016
Awesome!