Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[POC] Bidirectional Flatlist concept #3705

Closed

Conversation

kidroca
Copy link
Contributor

@kidroca kidroca commented Jun 21, 2021

Details

Don't merge! This is a proof of concept work for the pagination of the Flat List.

Findings

Not ready for WEB

The web implementation has some stopper bugs and is not ready for prime time

  • does not always trigger onEndReached to load past messages
  • scrolling performance degraded compared to what we already have
Other points

I've removed the prop reportActions so that report actions are always fetched and we can see how moving up and down the list loads actions. I can make it work with Onyx data as well but will make the logic more complicated for review and harder to test the POC.
The above change also means that sending a new message would not update the chat.
Bug: When I scroll up to load past messages the chat is sometimes returned all the way to the bottom - I think this is related: GetStream/react-native-bidirectional-infinite-scroll#8 It never happened on scrolling down to load recent messages

I've hooked this up with deeplinking so you can use any past message as the starting point of a report. The message would also have a slightly tinted background so it's easy to trace it (only for review/debug purposes)

Fixed Issues

Related to #2985

Tests

Check for regressions

  1. Open a chat
  2. Scroll up to load older messages

Test loading relative to an older message

You can trigger this by either triggering a deep link like expensify-cash://r/{reportID}/{sequenceNumber} or by manually editing the prop passed here:

<ReportActionsView reportID={reportID} anchorSequenceNumber={anchorSequenceNumber} />

E.g. change it to 1 to load every opened chat from the start

<ReportActionsView reportID={reportID} anchorSequenceNumber={1} />
  1. Start from a past message
  2. Scrolling up/down show load more message without compromising scroll position

QA Steps

N/A

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Screenshots

Web

Does not work very well on web ATM

NEW.Expensify.cash.-.Google.Chrome.2021-06-21.14-27-08.mp4

Mobile Web

Desktop

Android

Android.Bidirectional.Scroll.mp4

iOS

For some reason this popup is constantly triggered when I try to scroll. But overall it functions the same way as in Android

Screen.Recording.2021-06-21.at.14.23.48.mov

@kidroca kidroca requested a review from a team as a code owner June 21, 2021 14:32
@MelvinBot MelvinBot requested review from tgolen and removed request for a team June 21, 2021 14:32
Comment on lines +156 to +157
maxToRenderPerBatch={CONST.REPORT.ACTIONS.LIMIT}
windowSize={CONST.REPORT.ACTIONS.LIMIT / 2}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These work better for the new library, or they can also be removed altogether to use the defaults, but maxToRenderPerBatch={1} does not work good with all the updates in this PR

Comment on lines -35 to -37
this.list
.getScrollableNode()
.addEventListener('wheel', this.invertedWheelEvent);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Scroll is handled automatically from the new library

Comment on lines -39 to -43
this.list.setNativeProps({
style: {
transform: 'translate3d(0,0,0) scaleY(-1)',
},
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer seems needed.
The reason to have it is to fix image rendering, but it does seem to have any effect removing it
scaleY(-1) is added by default

// eslint-disable-next-line react/jsx-props-no-spreading
<InvertedFlatList {...props} innerRef={ref} />
));
export default BaseInvertedFlatList;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the end the whole file became a BaseInvertedFlatList with shouldMeasureItems set to true

@@ -879,6 +879,8 @@ function fetchActions(reportID, offset) {

Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, indexedData);
Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {maxSequenceNumber});

return {indexedData, maxSequenceNumber, history: data.history};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made these changes so that paging can be hooked directly to fetch
It's makes the POC simpler - when we scroll up or down add 25 more messages to component state
Otherwise we need to have some additional handling if data already exists in Onyx

Comment on lines -305 to -306
.sortBy('sequenceNumber')
.filter(action => action.actionName === CONST.REPORT.ACTIONS.TYPE.IOU)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the items passed here (from state) are already sorted and filtered

Comment on lines +378 to +382
if (this.waitItemsLayoutTask) {
this.waitItemsLayoutTask.resolve();
this.waitItemsLayoutTask = null;
this.forceUpdate();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the action items render we're resolving any pending waitItemsLayoutTask promises
This removes the full screen loader and scrolls to the anchor item

Comment on lines -383 to -386
// Comments have not loaded at all yet do nothing
if (!_.size(this.props.reportActions)) {
return null;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed as we're showing a loader

Comment on lines +454 to +455
<FullScreenLoadingIndicator visible={isLoading} />
<InvertedFlatList
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're showing this loader for the initial loading that happens during mount
Scrolling up/down uses a small loading indicator provided by default from the library

Comment on lines -434 to -437
reportActions: {
key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
canEvict: false,
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prop is removed so it's easier to test the POC

@kidroca
Copy link
Contributor Author

kidroca commented Oct 19, 2021

Hey @roryabraham I think we can just close this one

@kidroca kidroca closed this Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants