Javascript 如何在我的';盒子';在中国?

Javascript 如何在我的';盒子';在中国?,javascript,react-native,Javascript,React Native,我已经构建了一个包含我的组件风格的“框”,我已经成功地将文本放在那里,但没有成功地使用图标/图像plz帮助 App: .....import Box from './src/box'; ...... <View style={{height: 100,flexDirection:'row',flex:1}}> <Box someText={'sushi'} //, background source={require('./asset

我已经构建了一个包含我的组件风格的“框”,我已经成功地将文本放在那里,但没有成功地使用图标/图像plz帮助

App:

.....import Box from './src/box';
......

<View style={{height: 100,flexDirection:'row',flex:1}}>
          <Box someText={'sushi'}
          //, background source={require('./assets/sushi.png')}
          //,TouchableHighlight onPress={this.message_function}
          />
</View>

box:

import { StyleSheet, Dimensions, Text,View ,Image} from "react-native";
import React from 'react' ;

export default class Box extends React.Component {

   render() {
       return (
       <View style={styles.box}>

   <Text style={styles.paragraph}> {this.props.someText}</Text>
       </View>
       );
   }
}

const styles = StyleSheet.create({
    box: {
        flex: 1,
        height: 100,
        //backgroundColor: '#ccc',
        margin: 8,



    },
    paragraph: {


    //margin: 24,
    fontSize: 15,
    textAlignVertical:10,
    fontWeight: 'bold',
    textAlign: 'center',
    textAlignVertical: 'bottom',
    //top:0, left: 0, right: 0,
    color: '#000',
     width: '100%',
      height: '70%',
      backgroundColor: 'rgba(255,255,255,0.8)'
  }

});
我已经构建了一个包含我的组件风格的“框”,我已经成功地将文本放在那里,但没有成功地使用图标/图像plz帮助

App:

.....import Box from './src/box';
......

<View style={{height: 100,flexDirection:'row',flex:1}}>
          <Box someText={'sushi'}
          //, background source={require('./assets/sushi.png')}
          //,TouchableHighlight onPress={this.message_function}
          />
</View>

box:

import { StyleSheet, Dimensions, Text,View ,Image} from "react-native";
import React from 'react' ;

export default class Box extends React.Component {

   render() {
       return (
       <View style={styles.box}>

   <Text style={styles.paragraph}> {this.props.someText}</Text>
       </View>
       );
   }
}

const styles = StyleSheet.create({
    box: {
        flex: 1,
        height: 100,
        //backgroundColor: '#ccc',
        margin: 8,



    },
    paragraph: {


    //margin: 24,
    fontSize: 15,
    textAlignVertical:10,
    fontWeight: 'bold',
    textAlign: 'center',
    textAlignVertical: 'bottom',
    //top:0, left: 0, right: 0,
    color: '#000',
     width: '100%',
      height: '70%',
      backgroundColor: 'rgba(255,255,255,0.8)'
  }

});
我已经构建了一个包含我的组件风格的“框”,我已经成功地将文本放在那里,但没有成功地使用图标/图像plz帮助

App:

.....import Box from './src/box';
......

<View style={{height: 100,flexDirection:'row',flex:1}}>
          <Box someText={'sushi'}
          //, background source={require('./assets/sushi.png')}
          //,TouchableHighlight onPress={this.message_function}
          />
</View>

box:

import { StyleSheet, Dimensions, Text,View ,Image} from "react-native";
import React from 'react' ;

export default class Box extends React.Component {

   render() {
       return (
       <View style={styles.box}>

   <Text style={styles.paragraph}> {this.props.someText}</Text>
       </View>
       );
   }
}

const styles = StyleSheet.create({
    box: {
        flex: 1,
        height: 100,
        //backgroundColor: '#ccc',
        margin: 8,



    },
    paragraph: {


    //margin: 24,
    fontSize: 15,
    textAlignVertical:10,
    fontWeight: 'bold',
    textAlign: 'center',
    textAlignVertical: 'bottom',
    //top:0, left: 0, right: 0,
    color: '#000',
     width: '100%',
      height: '70%',
      backgroundColor: 'rgba(255,255,255,0.8)'
  }

});
应用程序:
..…从“/src/Box”导入框;
......
方框:
从“react native”导入{样式表、维度、文本、视图、图像};
从“React”导入React;
导出默认类框扩展了React.Component{
render(){
返回(
{this.props.someText}
);
}
}
const styles=StyleSheet.create({
方框:{
弹性:1,
身高:100,
//背景颜色:“#ccc”,
差额:8,
},
第段:{
//差额:24,
尺寸:15,
text:10,
fontWeight:'粗体',
textAlign:'中心',
textAlignVertical:'底部',
//顶部:0,左侧:0,右侧:0,
颜色:“#000”,
宽度:“100%”,
身高:70%,
背景颜色:“rgba(255255,0.8)”
}
});
您可以将一个
或图标组件包装在您的盒子中

所以它最终会是这样的:

<View style={styles.box}>
  <Image source={require('your-image-path')} />
</View>

图像组件文档:

有几个lib可以处理图标组件:

反应本机元素:

从'react native elements'导入{Icon}
反应本机矢量图标:

从'react native vector icons/MaterialIcons'导入图标;
反应本机图标:

从“反应本机图标”导入图标;

希望有帮助

你能举个例子,像我在文本中做的那样,放一个通用的图像吗?(this.props.someText)我认为这个答案也能帮助你:
import Icon from 'react-native-icons';
<Icon
  name='ion|beer'
  size={40}
  color='#887700'
/>