简体   繁体   English

如何在React-Native中实现文本环绕视图

[英]How to achieve text surround view in react-native

problem: i want to achieve the effect as flowing: 问题:我想达到流动的效果:

在此处输入图片说明

i try to use view as the rounded rectangle,but it can't use in Android. 我尝试将视图用作圆角矩形,但在Android中无法使用。

<Text>
 <View></View>
 <Text></Text>
</Text>

i also try use image as the rounded rectangle, but the text align vertical bottom. 我也尝试使用图像作为圆角矩形,但文本在垂直底部对齐。

So now i don't know how can to achieve the effect 所以现在我不知道该如何达到效果

try this way: 尝试这种方式:

             <Text>
                <View style={{ borderWidth:1, borderColor:'#a2a2a2', borderRadius:6 }}>
                <Text > ADAFAF </Text>
                </View>
                <Text> styleborder Width style border Width style borderWidth style borderWidth styleborderWidth</Text>
            </Text>

在此处输入图片说明

can you try this 你可以试试这个吗

  <View style={{flex:1}}>
    <View style={{justifyContent:'flex-start',flexDirection:'row', marginTop:10}}>
      <View style={{ borderWidth:1, borderColor:'#a2a2a2', borderRadius:6, height:25, padding:2}}>
        <Text> hhshs </Text>
      </View>
      <Text style={{marginLeft:10}}> side content </Text>
    </View>
    <Text style={{marginLeft:10, marginTop:10}}>down content</Text>
  </View>

Although I don't consider this a proper solution but this should work for longer lines of text: 虽然我认为这不是一个合适的解决方案,但是它应该适用于更长的文本行:

import * as React from 'react';
import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
import { Constants } from 'expo';

// You can import from local files
import AssetExample from './components/AssetExample';

// or any pure javascript modules available in npm
import { Card } from 'react-native-elements'; // Version can be specified in package.json

export default class App extends React.Component {
  render() {
    return (
      <View style={styles.container}>
      <View style={styles.section}>
        <View style={styles.button}>
          <Text> TEST </Text>
        </View>  
        {
        "lorem ipsum dollar smit lorem ipsum dollar smit lorem ipsum dollar smit lorem ipsum dollar smit lorem ipsum dollar smit lorem ipsum dollar smit lorem ipsum dollar smit".split(" ").map(val=>{
          return (<Text> {val}</Text>);
        }) 
        }
      </View>
  </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {padding: 50},
  section:{flexDirection:'row', flexWrap:"wrap", alignItems:"center"},
  button: { borderWidth:1, borderColor:'#222', borderRadius:6, padding:5, backgroundColor:"#eee", justifyContent:"center", marginBottom: 10}
});

The concept is to create multiple text components split by blank space, this would allow the text to break. 概念是创建多个由空白分隔的文本组件,这将使文本断裂。 Again it's not an optimised solution but android doesn't support View inside the text so this is the workaround. 同样,它不是一个优化的解决方案,但android不支持在文本内部查看,因此这是解决方法。 Unless we come up with some proper solution. 除非我们提出一些适当的解决方案。

You can also checkout this expo snack: https://snack.expo.io/rJpjWP_BQ 您还可以签出此博览会小吃: https : //snack.expo.io/rJpjWP_BQ

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM