react-native -v
: 0.46.4npm ls rnpm-plugin-windows
: [email protected]npm ls react-native-windows
: [email protected]node -v
: v8.2.1npm -v
: 5.3.0yarn --version
:Then, specify:
10.0.10586
(Write your steps here:)
I'm using Touchable Opacity the code is below
<TouchableOpacity
onPress={()=>{props.onItemClick();}}
style={props.isSelected ? styles.itemViewSelected : styles.itemView}>
<View style={styles.subView}>
<Text style={props.isSelected ? styles.itemTextSelected : styles.itemText}>
{props.name}
</Text>
</View>
</TouchableOpacity>
```
itemView:{
flexDirection:'column',
justifyContent:'center'
},
itemViewSelected:{
flexDirection:'column',
justifyContent:'center',
backgroundColor: AppStyles.color.COLOR_MIDNIGHT,
},
subView:{
flexDirection:'row',
justifyContent:'space-between',
alignItems:'center'
},
itemText:{
fontSize:16,
fontFamily: AppStyles.fonts.FONT_NORMAL,
color: AppStyles.color.COLOR_BLACK,
margin:12
},
itemTextSelected :{
fontSize:16,
color: AppStyles.color.COLOR_WHITE,
fontFamily: AppStyles.fonts.FONT_NORMAL,
margin:12
},
```
The Touchable Opacity onPress should fire when we click anywhere in the touchable.
The Touchable Opacity onPress only fire when i click on the text inside the touchable opacity. In iOs onPress works perfectly clicking anywhere inside the touchable,
But in windows the onPress is getting fired only when we click on the content inside the Touchable Opacity. If the text has half the width of touchable opacity .. click will only work on the text (I think this happens when u have nested views inside .. i was bale to reproduce this issue in multiple places)
@victorileaf can you try setting subView
backgroundColor to transparent
?
@rozele Its working when i changed the subView backgroundColor
to transparent
.
But its supposed to work without this right? I have many buttons here and there
Any fixes on the way?
this happens for normal view too
<TouchableOpacity>
<View style={styles.buttonTab}>
<Text style={styles.buttonTabText}>{attributeName}</Text>
</View>
</TouchableOpacity>
I need to put backgroundColor transparent then only click works outside text
Thanks a lot for the response
Cheers man :)
@rozele Any help of this issue (huge blocker) will be highly appreciated man :)
https://github.com/Microsoft/react-native-windows/issues/1370
@victorileaf unfortunately there's not many other options. This is a problem with how the "hit test" works on UWP (it does not pick up Canvas instances without a background). It's too expensive to render all Canvas instances with a transparent background, especially since many Canvas instances are only used for layout. It really has to be app specific to know that a
I'll take a second pass at the code for transparent
setting manually for other apps I've built.
My hack is as follows (I'm using WPF so it may work differently):
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
<TouchableOpacity>
<Text style={StyleSheet.absoluteFillObject} />
<View>
{/* Your content */}
</View>
</TouchableOpacity>
Adding an empty <Text />
component that absolutely fills the touchable makes the entire area.. touchable.
@alexcoady why can't you apply the style to the <View/>? Seems like wasted allocations to add an empty TextBlock.
@rozele This has no effect in the WPF version. The only way I've been able to make the entire area clickable is the approach I posted above.
Closing - we're actually relying on the hit test functionality of UWP Canvas now to optimize the TouchHandler behavior. "Painting" a transparent background is the recommended solution.
Most helpful comment
@victorileaf can you try setting
subView
backgroundColor totransparent
?