jjzjj

javascript - React-Native 文本无故被垂直 chop

coder 2024-05-06 原文

我的文本出现了一个有趣的错误。出于某种原因,文本会像这样随机被 chop :

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'flex-start',
    backgroundColor: "#ecf0f1",
    width:"100%",
    paddingTop:"5%"
  },
  itemContainer: {
    backgroundColor:"#fff",
    margin:"5%",
    marginTop: 0,
    borderRadius:5,
    width: "90%"
  },
  itemHeaderContainer: {
    padding:15,
    borderColor: "#E4E2E9",
    borderBottomWidth: 1
  },
  itemHeaderText: {
    height:'auto',
    color:"#333",
    fontSize: 23,
    fontWeight: "800",
  },
  itemButtonContainer: {padding:13, flexWrap: 'wrap',  alignItems: 'flex-start', flexDirection:'row'},
  itemButtonText: { fontSize:19, color:"#fff", fontWeight:"800" },
  itemCreateButton: { backgroundColor:"#3F61E7", borderRadius: 5, paddingVertical:10, paddingHorizontal:15},
});

renderTemplate() {
  if(this.state.loaded) {
    return (
      <View style={{width:"100%"}}>

      <View style={styles.itemContainer}>
        <View style={[styles.itemHeaderContainer, {borderBottomWidth: 0}]}>
          <Text style={styles.itemHeaderText}>{this.state.task_data.title}</Text>
          <Text style={{ marginTop:10, fontSize:18, color:"#333", fontWeight:"400" }}>Line 1</Text> 
          <Text style={{ marginTop:10, fontSize:18, color:"#333", fontWeight:"400" }}>Line 2</Text>
          <Text style={{ marginTop:10, fontSize:18, color:"#333", fontWeight:"400" }}>Line 3</Text> 
          <Text style={{ marginTop:10, fontSize:18, color:"#333", fontWeight:"400" }}>Line 4</Text> 
          <Text style={{ marginTop:10, fontSize:18, color:"#333", fontWeight:"400" }}>Line 5</Text> 
        </View>
      </View>

      <View style={[styles.itemContainer, {padding:15}]}>
        <Text style={[styles.itemHeaderText, {}]}>Cut off Text????</Text>
      </View>

      <View style={styles.itemContainer}>
        <View style={styles.itemHeaderContainer}>
          <Text style={styles.itemHeaderText}>Another Section</Text>
        </View>
        <View style={styles.itemButtonContainer}>
            <TouchableHighlight underlayColor='#3F61E7' style={[styles.itemCreateButton, {marginRight: 10}]}>
              <View style={{flexWrap: 'wrap',  alignItems: 'flex-start', flexDirection:'row'}}>
                <Text style={styles.itemButtonText}>Button 1</Text>
              </View>
            </TouchableHighlight>

             <TouchableHighlight underlayColor='#3F61E7' style={styles.itemCreateButton}>
              <View style={{flexWrap: 'wrap',  alignItems: 'flex-start', flexDirection:'row'}}>
                <Text style={styles.itemButtonText}>Button 2</Text>
              </View>
            </TouchableHighlight>
        </View>
      </View>

      <View style={styles.itemContainer}>
        <View style={styles.itemHeaderContainer}>
          <Text style={styles.itemHeaderText}>Existing Documents</Text>
        </View>
        
        <FlatList data={this.state.task_documents} style={{ paddingBottom:10, paddingHorizontal:0 }} renderItem={
          ({item}) => (

            <View style={{ borderBottomWidth:1, borderColor:"#F1F0F3"}}>
              <View style={[{flexGrow:1, paddingHorizontal:5, flex:1, }]}>
                <Text numberOfLines={1} ellipsizeMode='tail' style={{ flexShrink: 1, fontSize:24, fontWeight:"600",}}>{item.value.title || "No Title"}</Text>
              </View>
            </View>
          )
        } />
      </View>

      </View>
    );
  }
  else return (
    <View style={styles.itemContainer}>
      <View style={[styles.itemHeaderContainer, {borderBottomWidth: 0}]}>
        <Text style={styles.itemHeaderText}>Loading item..</Text>
      </View>
    </View>
  );
}

render() {
  return (
    <ScrollView>
      <View style={styles.container}>
        {this.renderTemplate()}          
      </View>
    </ScrollView>
  );
}

有趣的是,我在测试任务下放置的行越多,它被 chop 的次数就越多。

  • 如果我将所有内容从 renderTemplate() 移动到 render(),它不会被切断
  • 如果我完全删除这些行,文本不会被 chop 。
  • 如果我将 FlatList 替换为 null 或将其删除,它不会被切断。
  • 基本上,当我开始随机删除内容时,事情就会开始以奇怪的方式影响其他元素。

其他人遇到过这种情况吗?难道我做错了什么?接受任何和所有建议。

最佳答案

<View style={[styles.itemContainer, { padding: 15 }]}>
  <Text style={styles.itemHeaderText}>Cut off Text????</Text>
</View>

填充应应用于 Text 组件而不是 View 容器:

<View style={styles.itemContainer}>
  <Text style={[styles.itemHeaderText, { padding: 15 }]}>Cut off Text????</Text>
</View>

工作代码:https://snack.expo.io/Hkn9YIC17

关于javascript - React-Native 文本无故被垂直 chop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50511348/

有关javascript - React-Native 文本无故被垂直 chop的更多相关文章

  1. ruby - 使用 ruby​​ 将 HTML 转换为纯文本并维护结构/格式 - 2

    我想将html转换为纯文本。不过,我不想只删除标签,我想智能地保留尽可能多的格式。为插入换行符标签,检测段落并格式化它们等。输入非常简单,通常是格式良好的html(不是整个文档,只是一堆内容,通常没有anchor或图像)。我可以将几个正则表达式放在一起,让我达到80%,但我认为可能有一些现有的解决方案更智能。 最佳答案 首先,不要尝试为此使用正则表达式。很有可能你会想出一个脆弱/脆弱的解决方案,它会随着HTML的变化而崩溃,或者很难管理和维护。您可以使用Nokogiri快速解析HTML并提取文本:require'nokogiri'h

  2. ruby-on-rails - 错误 : Error installing pg: ERROR: Failed to build gem native extension - 2

    我克隆了一个rails仓库,我现在正尝试捆绑安装背景:OSXElCapitanruby2.2.3p173(2015-08-18修订版51636)[x86_64-darwin15]rails-v在您的Gemfile中列出的或native可用的任何gem源中找不到gem'pg(>=0)ruby​​'。运行bundleinstall以安装缺少的gem。bundleinstallFetchinggemmetadatafromhttps://rubygems.org/............Fetchingversionmetadatafromhttps://rubygems.org/...Fe

  3. ruby - 在 Ruby 中,垂直线是什么? - 2

    1.upto(9){|x|printx}为什么这行不通?{printx|x}}y呢? 最佳答案 它用于传递给您的block的参数。即在您的示例中,upto将使用1到9中的每个数字调用您的block,当前值可作为x获得。block参数可以有任何名称,就像方法参数一样。例如1.upto(9){|num|putsnum是有效的。就像一个方法的参数一样,一个block也可以有多个参数。例如hash.each_pair{|key,value|puts"#{key}is#{value}"} 关于ru

  4. ruby-on-rails - 使用 javascript 更改数据方法不会更改 ajax 调用用户的什么方法? - 2

    我遇到了一个非常奇怪的问题,我很难解决。在我看来,我有一个与data-remote="true"和data-method="delete"的链接。当我单击该链接时,我可以看到对我的Rails服务器的DELETE请求。返回的JS代码会更改此链接的属性,其中包括href和data-method。再次单击此链接后,我的服务器收到了对新href的请求,但使用的是旧的data-method,即使我已将其从DELETE到POST(它仍然发送一个DELETE请求)。但是,如果我刷新页面,HTML与"new"HTML相同(随返回的JS发生变化),但它实际上发送了正确的请求类型。这就是这个问题令我困惑的

  5. ruby-on-rails - rspec - 我怎样才能让 "pendings"有我的文本而不仅仅是 "No reason given" - 2

    我有这个代码:context"Visitingtheusers#indexpage."dobefore(:each){visitusers_path}subject{page}pending('iii'){shouldhave_no_css('table#users')}pending{shouldhavecontent('Youhavereachedthispageduetoapermissionic错误')}它会导致几个待处理,例如ManagingUsersGivenapractitionerloggedin.Visitingtheusers#indexpage.#Noreason

  6. ruby - 如何为 pbcopy 生成富文本链接 - 2

    我一直在玩一个脚本,它在Chrome中获取选定的文本并在Google中查找它,提供四个最佳选择,然后粘贴相关链接。它以不同的格式粘贴,具体取决于当前在Chrome中打开的页面-DokuWiki打开的DokuWiki格式,普通网站的HTML,我想要我的WordPress所见即所得编辑器的富文本。我尝试使用pbpaste-Preferrtf来查看没有其他样式的富文本链接在粘贴板上的样子,但它仍然输出纯文本。在文本编辑中保存文件并进行试验后,我想出了以下内容text=%q|{\rtf1{\field{\*\fldinst{HYPERLINK"URL"}}{\fldrsltTEXT}}}|te

  7. ruby-on-rails - gem install rmagick -v 2.13.1 错误 Failed to build gem native extension on Mac OS 10.9.1 - 2

    我已经通过提供MagickWand.h的路径尝试了一切,我安装了命令工具。谁能帮帮我?$geminstallrmagick-v2.13.1Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingrmagick:ERROR:Failedtobuildgemnativeextension./Users/ghazanfarali/.rvm/rubies/ruby-1.8.7-p357/bin/rubyextconf.rbcheckingforRubyversion>=1.8.5...yescheckingfor/

  8. ruby - Ruby 1.9.1 中的 native 线程,对我有什么好处? - 2

    所以,Ruby1.9.1现在是declaredstable.Rails应该与它一起工作,并且正在慢慢地将gem移植到它。它具有native线程和全局解释器锁(GIL)。自从GIL到位后,原生线程是否比1.9.1中的绿色线程有任何优势? 最佳答案 1.9中的线程是原生的,但它们被“放慢了速度”,一次只允许一个线程运行。这是因为如果线程真的并行运行,它会混淆现有代码。优点:IO现在在线程中是异步的。如果一个线程阻塞在IO上,那么另一个线程将继续执行直到IO完成。C扩展可以使用真正的线程。缺点:任何非线程安全的C扩展都可能存在使用Thre

  9. ruby-on-rails - Ruby 长时间运行的进程对队列事件使用react - 2

    我有一个将某些事件写入队列的Rails3应用。现在我想在服务器上创建一个服务,每x秒轮询一次队列,并按计划执行其他任务。除了创建ruby​​脚本并通过cron作业运行它之外,还有其他稳定的替代方案吗? 最佳答案 尽管启动基于Rails的持久任务是一种选择,但您可能希望查看更有序的系统,例如delayed_job或Starling管理您的工作量。我建议不要在cron中运行某些东西,因为启动整个Rails堆栈的开销可能很大。每隔几秒运行一次它是不切实际的,因为Rails上的启动时间通常为5-15秒,具体取决于您的硬件。不过,每天这样做几

  10. ruby-on-rails - 尝试打开 .gitignore 以在文本编辑器中对其进行编辑,但在 OS X Mountain Lion 上找不到文件位置 - 2

    我使用“newapp_name”创建了一个新的Rails应用程序,我正在尝试编辑.gitignore文件,但在我的应用程序文件夹中找不到它。我在哪里可以找到它?我安装了Git。 最佳答案 .gitignore位于项目的root中,而不是app子目录中。首先打开终端并进入您的目录。您需要使用ls-a来显示stash文件。然后使用打开.gitignore 关于ruby-on-rails-尝试打开.gitignore以在文本编辑器中对其进行编辑,但在OSXMountainLion上找不到文件位

随机推荐