[Inverted FlashList] How to show content on upper side when total content height is less than list height? #773
Replies: 7 comments 4 replies
-
Hi, did you manage to find a workaround for this? |
Beta Was this translation helpful? Give feedback.
-
Same issue. Any solution found? |
Beta Was this translation helpful? Give feedback.
-
Same issue. This should be a simple css matter of applying justifyContent as flex-end (because inverted), but FlashList doesn't honor this container style. I found that a simple conditional switch between FlashList and a standard FlatList when items under some length was a good-enough workaround, but it adds silly complexity to solve something that shouldn't be an issue. |
Beta Was this translation helpful? Give feedback.
-
you can try this: |
Beta Was this translation helpful? Give feedback.
-
You can put ListHeaderComponent when using inverted FlashList. |
Beta Was this translation helpful? Give feedback.
-
@dmahajan980 Hi. Did you solve this issue? |
Beta Was this translation helpful? Give feedback.
-
I got it to work with following patch. Not that this is a quick fix that top aligns all inverted lists. We make this better by allowing flexGrow and flexDirection to be set from outer api or create a new additional prop. @naqvitalha what do you think? I can prepare a PR if you would like this feature? This is a limitation that FlatList currently doesn't have. For Flatlist you can set diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 81d937fa0996aa4340eeb790a53d781fe37c4ea0..0000000000000000000000000000000000000000
diff --git a/dist/FlashList.js b/dist/FlashList.js
index 4f33d6bc679ab1f4daafbacf73172dcb08dc0c1f..702b38209fb6fab1af3ae2a760b7e0115dcf3bef 100644
--- a/dist/FlashList.js
+++ b/dist/FlashList.js
@@ -383,7 +383,10 @@ var FlashList = /** @class */ (function (_super) {
? tslib_1.__assign({}, this.getTransform()) : tslib_1.__assign({ flex: 1, overflow: "hidden" }, this.getTransform()) },
react_1.default.createElement(recyclerlistview_1.ProgressiveListView, tslib_1.__assign({}, restProps, { ref: this.recyclerRef, layoutProvider: this.state.layoutProvider, dataProvider: this.state.dataProvider, rowRenderer: this.emptyRowRenderer, canChangeSize: true, isHorizontal: Boolean(horizontal), scrollViewProps: tslib_1.__assign({ onScrollBeginDrag: this.onScrollBeginDrag, onLayout: this.handleSizeChange, refreshControl: this.props.refreshControl || this.getRefreshControl(),
// Min values are being used to suppress RLV's bounded exception
- style: { minHeight: 1, minWidth: 1 }, contentContainerStyle: tslib_1.__assign({ backgroundColor: this.contentStyle.backgroundColor,
+ style: { minHeight: 1, minWidth: 1, }, contentContainerStyle: tslib_1.__assign({ backgroundColor: this.contentStyle.backgroundColor,
+ // This patch makes inverted list be top aligned like non-inverted lists.
+ flexGrow: restProps.inverted ? 1 : undefined,
+ flexDirection: restProps.inverted ? 'column-reverse' : undefined,
// Required to handle a scrollview bug. Check: https://github.com/Shopify/flash-list/pull/187
minHeight: 1, minWidth: 1 }, (0, ContentContainerUtils_1.getContentContainerPadding)(this.contentStyle, horizontal)) }, this.props.overrideProps), forceNonDeterministicRendering: true, renderItemContainer: this.itemContainer, renderContentContainer: this.container, onEndReached: this.onEndReached, onEndReachedThresholdRelative: onEndReachedThreshold || undefined, extendedState: this.state.extraData, layoutSize: estimatedListSize, maxRenderAhead: 3 * finalDrawDistance, finalRenderAheadOffset: finalDrawDistance, renderAheadStep: finalDrawDistance, initialRenderIndex: (!this.isInitialScrollIndexInFirstRow() && initialScrollIndex) ||
undefined, initialOffset: initialOffset, onItemLayout: this.onItemLayout, onScroll: this.onScroll, onVisibleIndicesChanged: this.viewabilityManager.shouldListenToVisibleIndices |
Beta Was this translation helpful? Give feedback.
-
Hello,
Thanks for this amazing library. We are using this to implement the chat messages list and are hitting some design limitations.
Desired Behavior
The messages list has two requirements:
The images below illustrate the above requirements:
(Kindly ignore the absence of input box in right-side screenshot. It's taken from the simulator and is a WIP.)
Actual Behavior
In the code, the
inverted
prop is enabled to render the list in reverse order and the long-chat case is achieved. However, in the short-chat case, the messages are also rendering on the bottom side.In the desired behavior, the messages should be displayed on top.
Tried Solutions
So far, we have tried the following:
data
prop, removedinverted
prop, and setinitialScrollIndex
to the maximum index value (usingdata.length - 1
). This didn't work as the list displayed somewhere around middle and not the end. Moreover, the list displayed the top messages first and then scrolled down which isn't very ideal.scrollToBottom()
method on the list ref insideuseEffect
. This also suffered the same problems we faced in previous point.Similar discussion/issue
#665
Reproducible
https://snack.expo.dev/@dmahajan98/chat-room-reproducible
I think the solution might be along the lines of not using
inverted
prop. However, the solutions that I tried and am aware of could not render the bottom of list correctly. Also, these solutions do not show the bottom in first render but in subscequent renders.Any help regarding this would be appreciated very much.
Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions