2015-05-18 3 views
1

Я хотел бы иметь заголовок с заголовком слева и меню справа. Между текстом разной длины. Теперь я хочу, чтобы текст был вырезан, если он слишком длинный.React native flexible header

<View style={styles.header}> 
 
       <View style={styles.headline}> 
 
        <Text style={styles.headlineFluorine}>{"Fluorine "}</Text> 
 
        <Text style={styles.headlinePath}>{this.props.text}</Text> 
 
       </View> 
 
      
 
       <View ref="navi" style={styles.nav}> 
 
        <NavButton onPress={() => { this.props.navigator.push({id: 'drawings',}); }} text={textMyDrawings} /> 
 
        <NavButton onPress={() => { this.props.navigator.push({id: 'users',}); }} text={textUsers} /> 
 
        <NavButton onPress={() => { this.props.navigator.push({id: 'templates',}); }} text={textTemplates} /> 
 
        <NavButton onPress={() => { this.props.navigator.push({id: 'logout',}); }} text={textLogout} /> 
 
       </View> 
 
      </View>
header: { 
 
     flexDirection: 'row', 
 
     //justifyContent: 'space-around', 
 
     backgroundColor: '#DDDDDD', 
 
    }, 
 
          
 
    headline: { 
 
     flexDirection: 'row', 
 
     overflow: 'hidden', 
 
    }, 
 

 
    headlineFluorine: { 
 
     textAlign: 'left', 
 
     color: '#666666', 
 
     fontSize: 24, 
 
     margin: 10, 
 
    }, 
 
    
 
    headlinePath: { 
 
     fontSize: 18, 
 
     textAlign: 'left', 
 
     margin: 13, 
 
     overflow: 'hidden', 
 
    }, 
 
          
 
    nav: { 
 
     flexDirection: 'row', 
 
    },

ответ

0

попробовать подстрока только перед возвращением?

var txtlimit = 25;   
    var myheadertext = (this.props.text).length>txtlimit ? (this.props.text).substring(0,txtlimit) : this.props.text; 

затем

<Text style={styles.headlinePath}>{myheadertext}</Text> 
+0

Спасибо, сейчас я сделал это таким образом. Но лучшее решение для меня было бы более гибким. –