私の反応するネイティブAppでは、というRoundImageComponentという共有コンポーネントを追加しようとしています。とRoundImageComponent.styleを追加してCSSスタイルを追加しました。このRound画像コンポーネントを使用する場合、アプリケーションの要件に従って、画像の幅が小道具として渡されます。いくつかのケースでは、幅は、以下どのようにデフォルトのスタイルとユーザー定義のスタイルを設定するには、ネイティブで動的に反応しますか?
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;
としてコンポーネントタグに追加されないであろうRoundImageComponent
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;
ユーザーが小道具として幅を渡すと、画像の幅がデフォルトの幅にオーバーライドする必要があります。それ以外の場合、画像の幅はデフォルト幅のままにしてください。 このようにすることは可能ですか?
この「<画像スタイル= {[styles.image、this.props.style]} ソース= {{URI:。this.props.roundImage }} /> "私のために働いた。ありがとう –
""これを使用するとエラーが発生します "変数を見つけることができません: " –
あなたの呼び出しから名前スタイルの小道具を送る必要があります。もしstatefullコンポーネントであれば、' this.props.style'でなければなりません。**他の賢い 'props.state'は** presentational component ** – Revansiddh