今天同事碰到一個神奇的問題:一加手機上,顯示日期的Text組件,最后一位被截斷沒有顯示。他說是Text的樣式設(shè)置了fontWeight: "400" 導(dǎo)致的。。。

oneplus-text-cutoff
我下意識覺得可能是給Text指定的空間不足導(dǎo)致的,就調(diào)試了下,發(fā)現(xiàn)空間綽綽有余,最后一位數(shù)字就是生生被cut off了,而且在其他手機上沒發(fā)現(xiàn)有這個問題。
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