没什么用,所以我自己解决了。
- pressable 应该被包裹在一个视图(View)中
- 视图(View)必须有边距(margin),而不是内边距(padding)
- 圆角(border radius)必须在视图(View)上而不是在 pressable 上
- pressable 组件必须有填充(padding)而不是外边距(margin)
- 然后通过 android_ripple={{color: 'black', borderless: true}} 添加涟漪效果到 pressable 上。
<View style={styles.buttonView}>
<Pressable
onPress={() => {}}
android_ripple={{color: 'black', borderless: true}}
style={styles.loginButton}>
<Text style={styles.buttonText}>Login</Text>
</Pressable>
</View>
buttonView: {
alignSelf: 'stretch',
justifyContent: 'center',
borderRadius: 10,
elevation: 25,
margin: 10,
},
loginButton: {
height: 50,
backgroundColor: '#0f4c75',
padding: 10,
alignItems: 'center',
justifyContent: 'center',
},
buttonText: {
color: 'white',
fontSize: 16,
textTransform: 'uppercase',
fontFamily: 'sans-serif-light',
},
更新:-
浮动可按组件的波纹泄漏问题已得到修复
<View style={{
position: 'absolute',
bottom: 250,
borderRadius: 50,
overflow: 'hidden',
alignSelf: 'center'
}}>
<Pressable
style={{
height: 60,
width: 60,
borderRadius: 50,
backgroundColor: 'red',
justifyContent: 'center',
alignItems: 'center',
elevation: 4,
}}
android_ripple={{
color: 'black',
}}
onPress={() => { console.log('om') }}>
<Text>O</Text>
</Pressable>
</View>
alignSelf: center
样式会发生什么? - wobsoriano