StyleSheet
Yuan Ma Wei Zhi
- Xian Shang Di Zhi : https://github.com/facebook/react-native/blob/master/Libraries/StyleSheet/StyleSheet.js
- Ben Di Lu Jing : node_modules/react-native/Libraries/StyleSheet/StyleSheet.js
1, Xi Xian (Ru Tou Fa Si Yi Ban Xi )
-
Yuan Ma
const hairlineWidth = PixelRatio.roundToNearestPixel(0.4);
if (hairlineWidth === 0) {
hairlineWidth = 1 / PixelRatio.get();
}
if (hairlineWidth === 0) {
hairlineWidth = 1 / PixelRatio.get();
}
-
Jie Du
Yong PixelRatio Han Shu Lai Huo Qu Shou Ji She Bei De Ping Mu Xiang Su Bi ,Ran Hou Ji Suan Chu Tou Fa Si Yi Yang Xi De Xian ,Zhe Yang Jiu Neng You Xiao De Bao Zhang Liao Bu Tong Shou Ji Shang Kan Dao De Xi Xian Du Yi Yang De .
-
Shi Yong
{
borderBottomColor: '#bbb',
borderBottomWidth: StyleSheet.hairlineWidth
}
borderBottomColor: '#bbb',
borderBottomWidth: StyleSheet.hairlineWidth
}
2, Ding Wei (Jue Dui Ding Wei )
-
Yuan Ma
const absoluteFillObject = {
position: "absolute",
left: 0,
right: 0,
top: 0,
bottom: 0
};
position: "absolute",
left: 0,
right: 0,
top: 0,
bottom: 0
};
-
Jie Du
react native Wei Wo Men Ding Yi Liao Yi Zu Chang Yong De Jue Dui Ding Wei Dai Ma Pian Duan ,Hao Tie Xin A
-
Shi Yong
const styles = StyleSheet.create({
wrapper: {
...StyleSheet.absoluteFillObject,
top: 10,
backgroundColor: "transparent"
}
});
wrapper: {
...StyleSheet.absoluteFillObject,
top: 10,
backgroundColor: "transparent"
}
});
3, Zhan Kai (Yang Shi )
-
Yuan Ma
function getStyle(style) {
if (typeof style === "number") {
return ReactNativePropRegistry.getByID(style);
}
return style;
}
function flattenStyle(style: ?StyleObj): ?Object {
if (!style) {
return undefined;
}
invariant(style !== true, "style may be false but not true");
if (!Array.isArray(style)) {
return getStyle(style);
}
var result = {};
for (var i = 0, styleLength = style.length; i < styleLength; ++i) {
var computedStyle = flattenStyle(style[i]);
if (computedStyle) {
for (var key in computedStyle) {
result[key] = computedStyle[key];
}
}
}
return result;
}
if (typeof style === "number") {
return ReactNativePropRegistry.getByID(style);
}
return style;
}
function flattenStyle(style: ?StyleObj): ?Object {
if (!style) {
return undefined;
}
invariant(style !== true, "style may be false but not true");
if (!Array.isArray(style)) {
return getStyle(style);
}
var result = {};
for (var i = 0, styleLength = style.length; i < styleLength; ++i) {
var computedStyle = flattenStyle(style[i]);
if (computedStyle) {
for (var key in computedStyle) {
result[key] = computedStyle[key];
}
}
}
return result;
}
-
Jie Du
Jiang Shu Zu Yang Shi He Pu Tong Yang Shi Zhuan Huan Cheng Yi Ge Dui Xiang Ge Shi De Yang Shi
-
Shi Yong
- StyleSheet.flatten([styles.listItem, styles.selectedListItem]) , Shu Chu :{ flex: 1, fontSize: 16, color: 'green' }
- StyleSheet.flatten(styles.listItem),Shu Chu :return { flex: 1, fontSize: 16, color: 'white' }
4, He Bing (Yang Shi )
-
Yuan Ma
compose(style1: ?StyleProp, style2: ?StyleProp): ?StyleProp {
if (style1 && style2) {
return [style1, style2];
} else {
return style1 || style2;
}
}
if (style1 && style2) {
return [style1, style2];
} else {
return style1 || style2;
}
}
-
Jie Du
Jiang Yang Shi He Bing Zai Yi Qi
-
Shi Yong
- StyleSheet.compose(style1, style1)