【发布时间】:2017-12-19 01:56:42
【问题描述】:
在我的 react native 应用程序中,我只是尝试添加一个名为 RoundImageComponent 的共享组件,并添加了一个 RoundImageComponent.style 来添加 css 样式。使用此圆形图像组件时,图像的宽度将根据应用程序的要求作为道具传递。在某些情况下,宽度不会被添加到组件标签中,如下所示,
RoundImageComponent width={90} roundImage="https://media.wired.com/photos/593222b926780e6c04d2a195/master/w_2400,c_limit/Zuck-TA-AP_17145748750763.jpg" />
或
RoundImageComponent roundImage="https://media.wired.com/photos/593222b926780e6c04d2a195/master/w_2400,c_limit/Zuck-TA-AP_17145748750763.jpg" />
RoundImageComponent 代码
import React from 'react';
import {
Text,
View,
} from 'react-native';
import Config from 'react-native-config';
import SplashScreen from 'react-native-splash-screen';
import RoundImageComponent from "./shared/avatar/RoundImageComponent";
import styles from './App.styles';
const resolveSession = async () => {
// const session = sessionActions.getSession();
SplashScreen.hide();
};
setTimeout(() => {
resolveSession();
}, 2000);
const App = () => (
<View style={styles.container}>
<RoundImageComponent width={90}roundImage="https://media.wired.com/photos/593222b926780e6c04d2a195/master/w_2400,c_limit/Zuck-TA-AP_17145748750763.jpg" />
</View>
);
export default App;
圆形图像组件
import {
StyleSheet,
} from 'react-native';
import { container, primaryText } from '../../theme/base';
export const defaultImage = {
height: 100,
borderRadius: 50,
width: 100
}
const styles = StyleSheet.create({
container: {
...container,
},
userDefinedImage: {
...defaultImage,
width: 40
}
});
export default styles;
当用户将宽度作为道具传递时,图像宽度应覆盖为默认宽度,否则图像宽度应保持为默认宽度。 可以用这种方式吗?
【问题讨论】:
标签: css reactjs react-native