在大文本的第三行末尾添加更多读取按钮

发布于 2025-02-07 12:18:52 字数 1491 浏览 1 评论 0原文

在React-Native应用程序上工作,我有一个具有文本的组件,在文本的末尾,您可以单击“阅读更多”,然后转到另一个屏幕。即使文本不超过3行,我也必须在最后显示更多阅读。这就是我到目前为止的:

const ShowReadMore = () => {
  const SOME_LONG_TEXT_BLOCK =
    'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';

  return (
    <View style={{flexDirection: 'row'}}>
      <Text numberOfLines={3} style={{flex: 1, alignItems: 'center'}}>
        {SOME_LONG_TEXT_BLOCK}
      </Text>
      <Text onPress={() => navigationRef.navigate('somepage')} style={{alignSelf: 'flex-end'}}>
        Read More
      </Text>
    </View>
  );
};

它给了我:

​我想在句子的末尾看到“阅读更多”。如果只有1行的文本效果很好,但是超过2行,我将始终有前2行右侧的一些空空间,我该如何用类似的文本填充:

working on a react-native app, I have a component that has text and at the end of the text you can click on read more, to go to another screen. Even if the text is not more than 3 lines I have to show read more at the end. This is what I have so far:

const ShowReadMore = () => {
  const SOME_LONG_TEXT_BLOCK =
    'Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.';

  return (
    <View style={{flexDirection: 'row'}}>
      <Text numberOfLines={3} style={{flex: 1, alignItems: 'center'}}>
        {SOME_LONG_TEXT_BLOCK}
      </Text>
      <Text onPress={() => navigationRef.navigate('somepage')} style={{alignSelf: 'flex-end'}}>
        Read More
      </Text>
    </View>
  );
};

and it gives me this:

enter image description here

It's not exactly what I want, I want the text to be a of full length for the first 2 lines, and then on the 3rd line I want to see the 'read more' at the end of the sentences. If there is only 1 line of text it works good but more than 2 lines, I will always have for the first 2 lines some empty spaces on the right, how can I fill that with the text like:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

偷得浮生 2025-02-14 12:18:52

您可以尝试将视图替换为text

return (
<Text style={{flexDirection: 'row'}}>
  <Text numberOfLines={3} style={{flex: 1, alignItems: 'center'}}>
    {SOME_LONG_TEXT_BLOCK}
  </Text>
  <Text onPress={() => navigationRef.navigate('somepage')} style={{alignSelf: 'flex-end'}}>
    Read More
  </Text>
</Text>

);

您可能需要查看在外面作为容器

You can try to replace View to Text

return (
<Text style={{flexDirection: 'row'}}>
  <Text numberOfLines={3} style={{flex: 1, alignItems: 'center'}}>
    {SOME_LONG_TEXT_BLOCK}
  </Text>
  <Text onPress={() => navigationRef.navigate('somepage')} style={{alignSelf: 'flex-end'}}>
    Read More
  </Text>
</Text>

);

You might need View outside as a container

陌生 2025-02-14 12:18:52

您是否试图将&lt; text&gt;这样:

 <View style={{flexDirection: 'row'}}>
      <Text numberOfLines={3} style={{flex: 1, alignItems: 'center'}}>
        {SOME_LONG_TEXT_BLOCK}
        <Text onPress={() => navigationRef.navigate('somepage')} style {{alignSelf: 'flex-end'}}>
        Read More
        </Text>
      </Text>
    </View>

然后,修改您的样式以实现想要的要素。

Have you tried to put <Text> like this:

 <View style={{flexDirection: 'row'}}>
      <Text numberOfLines={3} style={{flex: 1, alignItems: 'center'}}>
        {SOME_LONG_TEXT_BLOCK}
        <Text onPress={() => navigationRef.navigate('somepage')} style {{alignSelf: 'flex-end'}}>
        Read More
        </Text>
      </Text>
    </View>

Then, modify your style to achieve want you want.

回眸一笑 2025-02-14 12:18:52

要删除空白,您可以从视图中删除此属性style = {{flexDirection:'row'}}

To remove the white space you can remove this property style={{flexDirection: 'row'}} from the view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文