React Native のテキストが画面からはみ出して折り返されません。どうすればいいですか? 質問する

React Native のテキストが画面からはみ出して折り返されません。どうすればいいですか? 質問する

次のコードはこのライブ例

次の React Native 要素があります:

'use strict';

var React = require('react-native');
var {
  AppRegistry,
  StyleSheet,
  Text,
  View,
} = React;

var SampleApp = React.createClass({
  render: function() {
    return      (
  <View style={styles.container}>

        <View style={styles.descriptionContainerVer}>
          <View style={styles.descriptionContainerHor}>
            <Text style={styles.descriptionText} numberOfLines={5} >
              Here is a really long text that you can do nothing about, its gonna be long wether you like it or not, so be prepared for it to go off screen. Right? Right..!
            </Text>
          </View>
        </View>

        <View style={styles.descriptionContainerVer2}>
          <View style={styles.descriptionContainerHor}>
            <Text style={styles.descriptionText} numberOfLines={5} >Some other long text which you can still do nothing about.. Off the screen we go then.</Text>
          </View>
        </View>



  </View>);
  }
});
AppRegistry.registerComponent('SampleApp', () => SampleApp);

以下のスタイルで:

var styles = StyleSheet.create({
  container:{
        flex:1,
    flexDirection:'column',
        justifyContent: 'flex-start',
        backgroundColor: 'grey'
    },
    descriptionContainerVer:{
    flex:0.5, //height (according to its parent)
    flexDirection: 'column', //its children will be in a row
    alignItems: 'center',
    backgroundColor: 'blue',
    // alignSelf: 'center',
  },
  descriptionContainerVer2:{
    flex:0.5, //height (according to its parent)
    flexDirection: 'column', //its children will be in a row
    alignItems: 'center',
    backgroundColor: 'orange',
    // alignSelf: 'center',
  },
  descriptionContainerHor:{
    //width: 200, //I DON\'T want this line here, because I need to support many screen sizes
    flex: 0.3,  //width (according to its parent)
    flexDirection: 'column',    //its children will be in a column
    alignItems: 'center', //align items according to this parent (like setting self align on each item)
    justifyContent: 'center',
    flexWrap: 'wrap'
  },
  descriptionText: {
    backgroundColor: 'green',//Colors.transparentColor,
    fontSize: 16,
    color: 'white',
    textAlign: 'center',
    flexWrap: 'wrap'
  }
});

次の画面が表示されます。

画面外テキストアプリ

テキストが画面からはみ出さないようにし、親の幅の 80% 程度で画面の中央に収めるにはどうすればよいですか。

widthこれを多数の異なるモバイル画面で実行し、動的にしたいので、を使用するべきではないと思います。そのため、 に完全に依存する必要があると思いますflexbox

flex: 0.8(それが私がの中にいた最初の理由でしたdescriptionContainerHor

私が達成したいのは次のようなことです:

私が達成したいこと

ありがとう!

ベストアンサー1

以下のリンクから解決策を見つけました。

[テキスト] テキストが折り返されません #1438

<View style={{flexDirection:'row'}}> 
   <Text style={{flex: 1, flexWrap: 'wrap'}}> You miss fdddddd dddddddd 
     You miss fdd
   </Text>
</View>

出力

彼に感謝したい場合は、以下の Github プロファイル ユーザー リンクを参照してください。

アリー・リプリー


編集: 2019年4月9日火曜日

@sudoPlz がコメントで述べたように、flexShrink: 1この回答を更新すると機能します。

ここに画像の説明を入力してください

おすすめ記事