简体   繁体   English

React Native Text Components:如何组合 url 和其他字符串?

[英]React Native Text Components: How to combine a url and other strings?

I have a url format like http://abc.go.com or http://abc.go.com .我有一个 url 格式,如http://abc.go.comhttp://abc.go.com

In React Native, i have a <Text>...</Text> to contain some child <Text>...</Text>在 React Native 中,我有一个<Text>...</Text>来包含一些子<Text>...</Text>

My structure is below :我的结构如下:

<Text>
    <Text>
      My homepage is a link like : 
    </Text>
    <Text>
      http://abc.go.com
    </Text>
    <Text>
      Welcome Welcome
    </Text>
</Text>

In small size Device to check, it shows the below result :在要检查的小尺寸设备中,它显示以下结果:

My homepage is a link like : http://
abc.go.com Welcome Welcome

this result is not my want.这个结果不是我想要的。 (If one line is not enough to show url) I want the result should be: (如果一行不足以显示网址)我希望结果应该是:

My homepage is a link like : 
http://abc.go.com Welcome Welcome

My question is how to combine of a whole url with 'http://' prefix with other strings?我的问题是如何将整个 url 与 'http://' 前缀与其他字符串组合?

My environment is React Native, JavaScript我的环境是 React Native、JavaScript

A simple solution could be the following一个简单的解决方案可能如下

<Text>
    <Text style={{flex:1}}>
        My homepage is a link like : 
    </Text>
    <Text>
        http://abc.go.com
    </Text>
    <Text>
       Welcome Welcome
     </Text>
</Text>

But this would make但这会让

My homepage is a link like:我的主页是一个链接,如:

always take up a whole line on screen which might not suite all use cases if you would give a bit more detailed description I could think of a more universal solution.总是在屏幕上占据一整行,如果你能给出更详细的描述,我可以想到一个更通用的解决方案,这可能不适合所有用例。

You can force a line break by inserting the newline character at the position where you don't want another text to appear.您可以通过在不希望出现其他文本的位置插入换行符来强制换行。

<Text>
  <Text>
    `My homepage is a link like :{'\r\n'}`
  </Text>
  <Text>
    http://abc.go.com
  </Text>
  <Text>
    Welcome Welcome
  </Text>
</Text>

PS I could not entirely reproduce your error. PS 我无法完全重现您的错误。 In my case the separate inner Text components were all in a separate line.在我的例子中,单独的内部Text组件都在一个单独的行中。

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

相关问题 react-native 如何在其他组件上方显示浮动按钮? - How to display a floating button above other components in react native? React Native-如何在其他组件之上创建和渲染组件 - React Native - How to create and render a component on top of other components 如何将路径名与 URL 字符串组合 - How to combine pathname with URL strings 无法在React Native中导入其他组件 - Cannot import other components in React Native 在主要组件中响应本机获取数据并发送到所有其他组件 - react native fetch data in main components and send to all other components 在React Native中的其他.tsx组件中使用.tsx组件 - Using .tsx components in other .tsx components in React Native 我如何从其他组件中获取this.state.value - How do I get a this.state.value from other components in react native 如何阻止视图占用屏幕宽度并与 React Native 中的其他组件重叠? - How do I stop a view from taking the screen's width and overlapping other components in React Native? 我在react-native中获取了带有fetch的JSON,如何将结果发送到其他组件 - I get a JSON with fetch in react-native how can i send the results to other components 如何结合“react-native-contacts”和“react-native-communications”? - How to combine "react-native-contacts" and "react-native-communications"?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM