react-native: Flex wrap has bugs
flex style has some bug, just like the chat scene:
textContainer: {
flexDirection: 'row',
flexWrap: 'wrap',
},
textContent: {
color: '#333',
fontSize: 16,
},
url: {
color: '#007aff',
},
wrap is not ok.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17 (3 by maintainers)
Commits related to this issue
- HAMO-16: Fix https://github.com/facebook/react-native/issues/8960 — committed to mboraski/HastyMobile by deleted user 7 years ago
- Hamo 16 (#5) * HAMO-16: Match mockup * HAMO-16: Add styling for selected filter * fix package.json * Use components from HAMO-8 and use em in stylesheets * Add missing tests and snapshots... — committed to mboraski/HastyMobile by deleted user 7 years ago
@jaynsw Have you tried using
alignItems: 'flex-start'
?I’m not sure if this is the same issue @jaynsw is talking about but I see this with
flexDirection: 'row'
andflexWrap: 'wrap'
:Adding
alignItems: 'flex-start'
fixed it. I’ll need to study the reason why later…Thanks, @kulmajaba!
alignItems: 'flex-start'
also works on my projectUsing version 0.34.1, it looks like
flexWrap: 'wrap'
preventsalignItems: any
from working:results in:
flexWrap: 'nowrap'
(or just commenting it out) results in:I’ve tried all the combinations of
flexDirection
,flexWrap
andalignItems
. WhenflexWrap: 'wrap'
,alignItems
has no effect.Hi @chrbradley , I foo faced the same issue. I fixed it by wrapping the container
View
by anotherView
and applied this style{flex:1,justifyContent:'center'}
In your case it should be something like this,
Elements inside a
View
withflexDirection: 'wrap'
andflexWrap: 'wrap'
will behave as they should,Text
elements will overflow to the right because of theflexDirection
.A common solution to this is to wrap the
Text
element in a separateView
that hasflexDirection: 'column'
in the styles.Hope this helps.
alignItems: 'flex-start'
Fixed the issue for me.@idibidiart What kind of an issue?
To recap the issues on this thread:
The original issue with text wrap inside a flex container
In a fresh React Native 0.44 project I could not reproduce this issue. Text will wrap in the following cases, all components inside a
View
container:Text
is inside aView
,View
stylesflexDirection
andflexWrap
can be any combinationText
is standalone in the containerView
,Text
stylesflexDirection
andflexWrap
can be any combinationOriginally the workaround would have been to wrap the
Text
component in aView
with styleflexDirection: 'column'
. Now it seems this is not needed.Empty space in the bottom of
View
components inside a flex containerAgain, could not reproduce the issue in React Native 0.44, seems like this is fixed as well. Tested by placing a bunch of
View
components with stylesminHeight: 100, minWidth: 100
inside a containerView
with stylesflexDirection: 'row', flexWrap: 'wrap'
. The boxes will take up minimum space.Taking out
flexWrap
from the containerView
, the boxes will fill vertical space as expected, because the default behavior foralignItems
is'stretch'
and the primary flex direction has been set to'row'
.Using
flexWrap: 'wrap'
preventsalignItems
from workingThis is true, but it’s not an issue, it’s a feature and complies with the CSS3 reference.
alignItems
aligns the children components in the cross direction. However you are already defining how the children should be aligned in the cross direction by usingflexWrap.
You need to usealignContent
style instead as this will align the rows in the cross direction, not the children.@kulmajaba
thanks.
if I want to input emoji which is an image, the result is one image one row, it’s so ugly.