我正在尝试创建一个看起来像这样的按钮组件。
TouchableOpacity 组件被包裹在一个 LinearGradient 组件中。当我触摸按钮时,内部视图的星星具有非常低的不透明度。我知道这是 TouchableOpacity 的功能之一,但有没有办法禁用它?
我玩过道具activeOpacity和focusOpacity但它仍然渲染不正确。
这是代码
import React from 'react';
import {
View,
Text,
TouchableOpacity,
Dimensions
} from 'react-native';
import LinearGradient from 'react-native-linear-gradient';
import em from './../../styles/calculateSize';
const deviceWidth = Dimensions.get('window').width;
const GradientButton = ({ propStyle, buttonText, onPress }) => {
const { centerEverything, buttonGradientStyle, buttonStyle, buttonTextStyle } = styles;
return (
<LinearGradient colors={['#FF7676', '#F54EA2']} style={[buttonGradientStyle, centerEverything]}>
<TouchableOpacity
style={[buttonStyle, centerEverything]}
activeOpacity={1}
focusedOpacity={1}
onPress={onPress}>
<Text style={buttonTextStyle}>{buttonText}</Text>
</TouchableOpacity>
</LinearGradient>
);
}
const styles = {
centerEverything: {
justifyContent: 'center',
alignItems: 'center',
},
buttonGradientStyle: {
height: 27,
width: deviceWidth * 0.23,
borderRadius: 5,
marginLeft: 5
},
buttonStyle: {
height: 24,
width: deviceWidth * 0.23 - 3,
backgroundColor: '#fff',
opacity: 0.1,
justifyContent: 'center',
borderRadius: 3,
},
buttonTextStyle: {
fontSize: em(0.75),
color: '#F54EA2',
backgroundColor: 'transparent',
}
}
export { GradientButton };