连续文本组件中的空文本空间反应本机

2023-12-01

我有这个问题:

enter image description here

我需要将“dummy”一词放在第一行中,直到该行完成。

您可以在此处查看示例:https://snack.expo.io/B1KcRgGWX

代码:

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

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <View style={styles.paragraphs}>
          <Text style={styles.textParagraph}>Lorem Ipsum is</Text>
          <Text style={styles.emptyTerm} />
          <Text style={styles.textParagraph}>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</Text>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    padding: 25,
    paddingTop: Constants.statusBarHeight,
    backgroundColor: '#ecf0f1',
  },
    emptyTerm: {
    borderBottomWidth: 1,
    marginLeft: 5,
    marginRight: 5,
    minWidth: "25%"
  },
    paragraphs: {
    flexDirection: "row",
    flexWrap: "wrap"
  },
});

你必须把你所有的<Text>组件与<Text>!

所以我们有:

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>
          <Text>Lorem Ipsum is </Text>
          <Text>{'     '}</Text>
          <Text>
            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
          </Text>
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    padding: 25,
    paddingTop: 20,
    backgroundColor: '#ecf0f1'
  }
});

但问题是你无法设置borderBottomWidth给你的empty <Text>!


解决方案

  1. 嵌套一个<View>在你的中间<Text>.

所以我们有:

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>
          <Text>Lorem Ipsum is </Text>
          <View style={styles.nestedViewStyle}>
            <Text>{'     '}</Text>
          </View>
          <Text>
            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
          </Text>
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    padding: 25,
    paddingTop: 20,
    backgroundColor: '#ecf0f1'
  },

  nestedViewStyle: {
    width: 50,
    borderBottomWidth: 1,
    marginVertical: 5
  }
});

but 嵌套视图仅限 iOS(Docs)!

  1. 对于 Android 来说,这是一些肮脏的编码,但似乎可以工作!

所以我们有这样的东西:

import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';

export default class App extends Component {
  render() {
    return (
      <View style={styles.container}>
        <Text>
          <Text>Lorem Ipsum is </Text>
          <Text style={{ textDecorationLine: 'underline' }}>
            {'            '}
          </Text>
          <Text>
            {' '}
            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
          </Text>
        </Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    flexDirection: 'row',
    alignItems: 'center',
    justifyContent: 'center',
    padding: 25,
    paddingTop: 20,
    backgroundColor: '#ecf0f1'
  }
});

我认为这就是我们可以做到的方式!如果有人有更好的解决方案,我将不胜感激为此撰写答案!

UPDATE

我刚刚创建了一个为此问题在react-native 仓库中!

再次更新!

您可以使用此功能:

splitPhrase = (phrase, isTerm = false) => {
  let words = phrase.split(' ');
  return words.map((i, k) => {
    return (
      <Text key={k} style={isTerm ? styles.emptyTerm : styles.paragraphs}>
        {' '}
        {i}{' '}
      </Text>
    );
  });
};
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

连续文本组件中的空文本空间反应本机 的相关文章

随机推荐

  • 什么时候使用 CRC 比 MD5/SHA1 更合适?

    何时适合使用 CRC 进行错误检测 而不是使用 MD5 或 SHA1 等更现代的哈希函数 前者更容易在嵌入式硬件上实现吗 CRC 可以很好地检测数据中可能出现的随机错误 例如网络干扰 线路噪声 失真等 CRC 的计算复杂度远低于 MD5 或
  • 默认显示 Visual Studio 扩展工具栏

    在 Visual Studio 扩展中 我在 vsct 文件中将工具栏定义为 menu type Toolbar menu
  • 在什么情况下使用 EJB?网站/网络应用程序开发需要它们吗?

    EJBS 是否用于数据库支持的网站 所有人都可以访问 没有什么是永远的required当然 如果你愿意 你可以构建一个 Web 应用程序作为背后的单个大型 C 函数CGI 也就是说 EJB 确实使 Web 应用程序开发变得更加容易 它们被纳
  • SwiftUI 父子绑定:@StateObject 中的 @Published 不起作用,而 @State 起作用

    我有一个来自的自定义模态结构这个问题 代码如下 某些属性在模态视图中进行了修改 并通过Binding 问题是 当房产来自 StateObject Published更改不会反映在模式视图中 当使用一个简单的 State 最小示例 完整代码
  • 避免在使用层次结构参数的操作中进行静态绑定

    我发现了一个关于静态绑定的问题 我的真实课程非常扩展 所以我将使用几个玩具课程来表达我的问题 我们假设我们有以下层次结构 public class Element public class Element1 extends Element
  • 添加(减去)月份但不超过新月份的最后一天

    我希望可靠地添加和减去六个月 债券时间 lubridate 例如 添加六个月12 31 2014应该导致6 30 2015 并添加到2 28 2014应该导致8 31 2014 问题与as Date 2014 12 31 months 6
  • DOT 可以生成更结构化的图表吗?

    我不太确定如何描述我的客户想要什么 所以我会让一张图片来说明大部分内容 我正在使用 DOT 生成或多或少的物料清单问题的图表 显示所有级别的传入批次和所有传出批次 这些批次是根据传入批次中的材料创建的 我已经获得了创建包含适当结构化数据的图
  • 访问生产中的 Google App Engine Python 应用程序代码

    背景 我是 Google App Engine 的新手 熟悉其他云提供商的服务 我正在寻找类似于对生产节点的 shell 访问的访问 视图 使用基于 Python Django 的 Google App Engine 应用程序 我想查看生产
  • WPF Tab 键顺序工作错误

    我在 WPF 中有一个观点 我一直在努力使 Tab 键顺序正确 我有三个文本框 我们称它们为 Text1 Text2 和 Text3 和两个自定义控件 每个控件上都有几个其他文本框和各种控件 我们称它们为 Custom1 和 Custom2
  • Objective-c 在我的控制器中添加子视图

    我有一个与代表 控制器和其他一些东西相关的应用程序 问题是我用 init 初始化了控制器中的所有内容 此 init 创建 3 个 UIVIew openGL imagepickerview 和 MKMapView 我希望将这些视图添加到窗口
  • 获取 QF_UFNRA 中实数的小数部分

    使用 smtlib 我想使用 QF UFNRA 进行类似模数的操作 这使我无法使用 mod to int to real 之类的东西 最后我想在以下代码中获取 z 的小数部分 set logic QF UFNRA declare fun z
  • Rails 上的 Angular JS - 参数“RaffleCtrl”不是函数,未定义

    我正在关注 RoR 项目上的整数 Angular JS 教程 在我的控制器 js 文件中 我有以下内容 抽奖咖啡 Place all the behaviors and hooks related to the matching contr
  • 发布 Gmail 插件时出现问题

    我计划推出一个简单的 Gmail 插件 我已遵循发布指南中的每一步并填写了提交表格 然而现在已经过去两周了 我还没有收到任何回复 谁能告诉我我提交的内容需要多长时间才能得到审核 或者发布公共 Gmail 插件的步骤是什么 指南中的那些似乎不
  • 使用python解码tcp数据包

    我正在尝试解码通过 TCP 连接收到的数据 数据包很小 不超过100字节 然而 当它们很多时 我会收到一些连接在一起的数据包 有没有办法防止这种情况 我正在使用Python 我尝试分离数据包 我的来源如下 数据包以STX字节开始 以ETX字
  • 为什么这个 PDO 异常没有被捕获? [关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 我有一个包含在 try catch 中的 INSERT
  • 在 java 中使用带有重写方法的 throws 子句时出现错误? [复制]

    这个问题在这里已经有答案了 当我在方法中使用 throw 子句时出现错误demo 我想知道在继承中使用 throws 有什么限制 错误是 异常ClassNotFoundException与 throws 子句不兼容Test demo Cla
  • 在域中设置命名管道安全性

    我有一个通过命名管道设置的服务器 它对于域管理员来说工作得很好 但是当我在普通用户上测试客户端时 它给出了异常 访问路径被拒绝 因此 这就是我尝试设置的权限 以授予域中所有经过身份验证的用户访问权限 我在这里做错了什么 Server Nam
  • 如何在 Rust 中分割字符串?

    来自文档 尚不清楚 在Java中你可以使用split像这样的方法 some string 123 ffd split 123 Use split let parts some string 123 content split 123 这给出
  • KVO 中的更改字典对于选择索引始终包含 NULL

    我正在使用 KVO 来获取 NSArrayController 的选择索引更改的通知 contoller addObserver self forKeyPath selectionIndex options NSKeyValueObserv
  • 连续文本组件中的空文本空间反应本机

    我有这个问题 我需要将 dummy 一词放在第一行中 直到该行完成 您可以在此处查看示例 https snack expo io B1KcRgGWX 代码 import React Component from react import T