[Touchable] easy way to disable a Touchable* highlight?
See original GitHub issueHi,
the current pattern I’ve been doing for making Buttons that can be “disabled” is to do the following:
return !disabled ? <TouchableOpacity onPress={onPress}>{btn}</TouchableOpacity> : btn;
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.
Here is my proposal to fix that,
what if I could do that?
return <TouchableOpacity onPress={!disabled ? onPress : null}>{btn}</TouchableOpacity>;
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?
Issue Analytics
- State:
- Created 8 years ago
- Comments:10 (8 by maintainers)
Top Results From Across the Web
react-native - Remove highlighting after onPress?
You can replace Touchable Highlight with Touchable opacity and simply set activeOpactity prop with value 1. It will not highlight the press.
Read more >TouchableHighlight - React Native
A wrapper for making views respond properly to touches. On press down, the opacity of the wrapped view is decreased, which allows the ......
Read more >Disable TouchableOpacity - Swair AQ - Medium
First import TouchableOpacity from react-native and don't do a mistake I did back in my time and let my app auto import it...
Read more >Prevent the touch keyboard from appearing - Microsoft Support
Note: Some third-party software may disable the service again after you have reenabled it. If this is happening, the best way to track...
Read more >TouchableOpacity vs TouchableHighlight // ReactNative ...
Thanks to all the channel supporters, I can create a new full course for React Professionals looking to quickly level up to React...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
What if we can patch
Touchable
mixin?should do the trick. I can send over a PR along with adding a new propType
to
TouchableWithoutFeedback
base class. What do you think?Awesome!