今天同事碰到一個神奇的問題:一加手機上,顯示日期的Text組件,最后一位被截斷沒有顯示。他說是Text的樣式設置了fontWeight: "400"
導致的。。。
oneplus-text-cutoff
我下意識覺得可能是給Text指定的空間不足導致的,就調試了下,發現空間綽綽有余,最后一位數字就是生生被cut off了,而且在其他手機上沒發現有這個問題。
Text樣式如下:
dateText: {
fontSize: 15,
fontWeight: "400",
},
解決方法
- 拿掉
fontWeight: "400"
樣式,本來在android上也沒啥效果 - 不拿掉
fontWeight
,增加fontFamily: "System"
樣式
dateText: {
fontSize: 15,
fontWeight: "400",
fontFamily: "System",
},
參考:
https://stackoverflow.com/questions/54750503/text-is-getting-cut-off-in-android-for-react-native
https://github.com/facebook/react-native/issues/15114