admin管理员组文章数量:1287513
There's a problem with the border on android when using a borderColor with some level of transparency. Not only that, but when combining it with any level of borderRadius turns into another problem.
The borders seem to be one over another when using transparency, this results in weird edges with a different color. Then when adding borderRadius to the element, instead of the border being over the background, it grows outside of the element, so the transparency of the border will be merged with the background color of the container instead of the one on the element.
Here's a reproduction. The first one is a solid border, the second one is a border with some transparency and the third one is a border with transparency an some border-radius.
import { View, SafeAreaView, StyleSheet } from 'react-native';
export default function App() {
return (
<SafeAreaView style={styles.container}>
<View style={[styles.box, styles.solidBorder]} />
<View style={[styles.box, styles.borderWithOpacity]} />
<View style={[styles.box, styles.borderWithRadius]} />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
gap: 20
},
box: {
backgroundColor: '#FF5E3B',
height: 60,
borderWidth: 5
},
solidBorder: {
borderColor: '#000000'
},
borderWithOpacity: {
borderColor: '#00000033'
},
borderWithRadius: {
borderColor: '#00000033',
borderRadius: 1
}
});
/@ldiaz-occ/border-error-on-android?platform=android
Is there a workaround? If not, I would have to remove the border or change it to use a solid color.
There's a problem with the border on android when using a borderColor with some level of transparency. Not only that, but when combining it with any level of borderRadius turns into another problem.
The borders seem to be one over another when using transparency, this results in weird edges with a different color. Then when adding borderRadius to the element, instead of the border being over the background, it grows outside of the element, so the transparency of the border will be merged with the background color of the container instead of the one on the element.
Here's a reproduction. The first one is a solid border, the second one is a border with some transparency and the third one is a border with transparency an some border-radius.
import { View, SafeAreaView, StyleSheet } from 'react-native';
export default function App() {
return (
<SafeAreaView style={styles.container}>
<View style={[styles.box, styles.solidBorder]} />
<View style={[styles.box, styles.borderWithOpacity]} />
<View style={[styles.box, styles.borderWithRadius]} />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
gap: 20
},
box: {
backgroundColor: '#FF5E3B',
height: 60,
borderWidth: 5
},
solidBorder: {
borderColor: '#000000'
},
borderWithOpacity: {
borderColor: '#00000033'
},
borderWithRadius: {
borderColor: '#00000033',
borderRadius: 1
}
});
https://snack.expo.dev/@ldiaz-occ/border-error-on-android?platform=android
Is there a workaround? If not, I would have to remove the border or change it to use a solid color.
Share Improve this question asked Feb 25 at 6:31 Luis Fernando Diaz GarciaLuis Fernando Diaz Garcia 112 bronze badges1 Answer
Reset to default 0I don't know why the opacity on a border style doesn't work, but here is a workaround.
It isn't pretty but it basically places a background behind your view where you are able to control the color, opacity and borderRadius:
import { View, SafeAreaView, StyleSheet } from 'react-native';
import { useState } from 'react';
export default function App() {
const [height, setHeight] = useState(null)
const [width, setWidth] = useState(null)
const borderSize = 20
const setSize = (height, width) => {
setHeight(height + borderSize)
setWidth(width + borderSize)
}
return (
<SafeAreaView style={styles.container}>
<View style={styles.wrapper}>
<View onLayout={(event) => setSize(event.nativeEvent.layout.height, event.nativeEvent.layout.width)} style={styles.box} />
<View style={[styles.borderWithOpacity, {height, width, top: -borderSize / 2, left: -borderSize / 2}]} />
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
gap: 20
},
box: {
backgroundColor: '#FF5E3B',
height: 100,
zIndex: 1
},
borderWithOpacity: {
backgroundColor: '#000000',
opacity: 0.3,
position: 'absolute',
zIndex: 0
},
wrapper: {
position: 'relative'
}
});
本文标签: expoBorders with opacity and border radius don39t work on Android (React native)Stack Overflow
版权声明:本文标题:expo - Borders with opacity and border radius don't work on Android (React native) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741224675a2361632.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论