I'm developing a chat with the messages virtualized. It works well as a normal list.
Now I'm trying to "style" the messages to go from bottom up (like Whatsapp, Telegram and every message app works).
I have included a display: flex
, a flex-direction: column
, a justify-content: flex-end
on the parent, shown on code down below.
Edit: I have also included a display: flex
, a flex-direction: column-reverse
on the messages, so they already are in the right order. The problem is their position in the chat, related to the input on the bottom.
I've also put a div between parents with flexbox and AutoSizer because it's required on React-virtualized docs.
<div style={{ position: 'relative', minHeight: '100%', display: 'flex', justifyContent: 'flex-end', flexDirection: 'column' }} >
<div style={{ flex: '1 1 auto' }}>
<AutoSizer onResize={scrollToBottom}>
{({ width, height }) => (
<List
ref={ListRef}
deferredMeasurementCache={_cache.current}
width={width}
height={height}
overscanRowCount={props.overscanRowCount}
noRowsRenderer={_noRowsRenderer}
rowCount={xRowCount}
rowHeight={_cache.current.rowHeight}
rowRenderer={_rowRenderer}
scrollToIndex={xRowCount}
/>
)}
</AutoSizer>
</div>
</div>
As described in React-virtualized docs:
One word of caution about using AutoSizer with flexbox containers. Flex containers don't prevent their children from growing and AutoSizer greedily grows to fill as much space as possible. Combining the two can cause a loop. The simple way to fix this is to nest AutoSizer inside of a block element (like a ) rather than putting it as a direct child of the flex container.
The problem is: the flex-end style is not being applied. The list is working as it was before, from top to bottom.
Is there any other way I can do that? If so, I'm open to do it. If this is the way, does anyone know what the problem is?
Edit: I have created a demo for this problem: https://codesandbox.io/s/flexendreactvirtualize-hospg