1

I have some text overflowing my container view.I would like the word that appears cut in the picture to be moved to the second line. I have tried textShrink as proposed in similar posts, but it doesn't work, so I must be doing something wrong in a parent view???. Can you see it?

Text not wrapping

<View style={styles.container}>
<ScrollView style={styles.scrollview}>
(...)
 <View style={styles.line}>
          <View style={[styles.bubble2,{}]}>
            <Text style={{color:'white', fontSize:18, flexShrink:1}}>{strings('profilescreen.birthday')}</Text> 
          </View>
          <Text style={styles.maintext}>{userInfo.birthday}</Text>
        </View>
(...)
      </ScrollView>
    </View>

styles:

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: Colors.pointo,
    paddingTop: Constants.statusBarHeight+10,

  },

  bubble2:{
    height: 40,
    width:130,
    borderRadius:25,
    backgroundColor: Colors.pointosecondary,
    paddingHorizontal:20,
    alignSelf:'flex-start',
    alignItems:'center',
    justifyContent:'center',
    marginHorizontal:5,
    flexDirection:'column',

  },

  scrollview:{
    backgroundColor:'#fFF',
    height:'100%',
    paddingTop:10,
  },
  line:{
    height:50,
    flexDirection:'row',
    alignItems:'center',
    paddingHorizontal:20,
    paddingTop:15,
    flex:1,
  },
  maintext:{
    color:'gray',
    fontSize:16,
    paddingLeft:20,
  },
  
})

1 Answer 1

4

Use flexWrap

Update your text component style like this:

<Text style={{color:'white', fontSize:18, flexShrink:1, flexWrap: 'wrap'}}>
  {strings('profilescreen.birthday')}
</Text> 

CodeSandbox example

Sign up to request clarification or add additional context in comments.

7 Comments

doesn't do anything... its as if the text "didn't know" that it is overflowing
hmm, you are using a static height for your wrapper view (height: 40). can you try to remove it and give a flex:1 instead?
now the height is just enough to fit the one Line text, but the longer text didn't shrink anyway
did you also remove height:50 from line style? Our purpose is to allow text component have enough space to gain auto height based on its content. Static heights prevent this from happening.
This solution works for me. Perhaps the parent container must be flex also.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.