Skip to content

Conversation

@gavin-gmlab
Copy link

Implementation for FlatList instead of ListView component

Copy link

@radko93 radko93 left a comment

Choose a reason for hiding this comment

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

Please remove react-native-invertible-scroll-view from dependencies.

this.setState({
dataSource: this.state.dataSource.cloneWithRows(messagesData.blob, messagesData.keys)
});
messagesData: this.prepareMessages(nextProps.messages)

Choose a reason for hiding this comment

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

This will cause all chat messages to re-render every time a new message is added.

Copy link

@redwind redwind Nov 8, 2017

Choose a reason for hiding this comment

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

i think we should remove prepareMessages and move set value for nextMessage and previousMessage into renderItem function

Copy link
Author

Choose a reason for hiding this comment

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

My thoughts:
Its not worse than what it was with the ListView approach. Correct me if I am wrong since the old approach was rerendering the whole ListView anyway. FlatList is supposed to render only what is actually viewable anyway, and not those components that are outside the view, so we are getting an improvement right there.

I was more thinking of getting a quick fix in for now, and we can always have perf improvements later? But just my opinion.

Choose a reason for hiding this comment

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

It is not the prepareMessages that will cause everything (in the view) to rerender, that will happen anyway when a new message arrives. What we can do about that is make the components being rendered pure, and allow them to be effective PureComponent-s

@wizza-smile
Copy link

maybe you guys have some thoughts to share on this! @Kabangi @radko93 @dralletje @bartolkaruza @DavidKuennen @Ashoat

return output = messages.reduce((o,m,i) => {
const previousMessage = messages[i + 1] || {}
const nextMessage = messages[i - 1] || {}
o.push( {
Copy link

@dralletje dralletje Nov 26, 2017

Choose a reason for hiding this comment

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

Two small questions here:

  1. It seems to me this is a lot simpler done using .map, maybe even more performant? (Dunno if that even matters here)

  2. Because you merge previousMessage and nextMessage props onto the existing message, that message will be "invalidated" when matching it against existing messages (causing PureComponent or shouldComponentUpdate to always see change). I'd recommend setting { currentMessage, previousMessage, nextMessage } and properly using item.currentMessage instead of just item in https://github.com/FaridSafi/react-native-gifted-chat/pull/629/files#diff-bd8395a0a94eca8b61a34ec66f8a605cR102

It might be that I miss something why this is necessary, let me know :)

Choose a reason for hiding this comment

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

About the second one, I see that Message isn't PureComponent yet, but I think it is still good to these optimisations already, if we want Message to be an effective PureComponent later ;)

https://github.com/gavin-gmlab/react-native-gifted-chat/blob/33dc31f41d29be98e441c4b27ad74e453b9801b5/src/Message.js#L16

};

if (this.props.renderMessage) {
return this.props.renderMessage(messageProps);

Choose a reason for hiding this comment

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

Is it on purpose that this is outside of the { transform: [{ scaleY: -1 }] } ? I don't think people will want to have to set that themselves, and when we go to use invert={true} on the container later, the people that do have their own { transform: [{ scaleY: -1 }] } will have to remove it again and ughhhhh hahaha :)

renderFooter={this.renderLoadEarlier}
renderScrollComponent={this.renderScrollComponent}
renderFooter={this.renderLoadEarlier()}
style={{transform: [{scaleY: -1 },{perspective: 1280}]}}
Copy link

@dralletje dralletje Nov 26, 2017

Choose a reason for hiding this comment

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

One last thing, what is the reasoning behind using this transform ourselves, and not using inverted={true}? I'm not sure why it not in the documentation (so you may very well know something I don't) :-)

But this would solve the problem of us having to set the transform on all the items, and it would also spare us a view per item (FlatList applies inverted styles on the view it would create anyway, we introduce a new one :-/)

I understand if it is for version support: I think inverted only is supported in a couple of last version

https://github.com/facebook/react-native/blob/master/Libraries/Lists/FlatList.js#L142

Choose a reason for hiding this comment

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

Inverted works only on RN 0.49 and above. Atleast for Huawei phones running Android 7

Choose a reason for hiding this comment

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

Then maybe it is even a combination of the fact that inverted got added later + the perspective fix... Maybe good to wait some version before we use inverted, but still worth adding a TODO/NOTE?

@xcarpentier
Copy link
Collaborator

I've been creating #705 to have a clean history.

Please let me know if I can close this one?

@gavin-gmlab
Copy link
Author

@xcarpentier , yes, feel free to close this PR

xcarpentier added a commit that referenced this pull request May 30, 2018
chilinh added a commit to chilinh/react-native-gifted-chat that referenced this pull request Jun 18, 2018
* r_master:
  Move listViewProps to the end (FaridSafi#882)
  chore(package): update react-test-renderer to version 16.4.0 (FaridSafi#868)
  chore(package): update babel-jest to version 23.0.0 (FaridSafi#869)
  Update and Fix Slack Example (FaridSafi#895)
  Remove prop removeClippedSubviews on Flatlist (FaridSafi#897)
  Update Chatkit readme.md
  Fix typos in TS Types (FaridSafi#877)
  Modified for flatlist (from FaridSafi#629) (FaridSafi#705)
  fix tabs
  ignore example folder
  Add Chatkit asset to README.md
  Add Chatkit banner asset
  chore(package): update react-test-renderer to version 16.3.2 (FaridSafi#829)
  Update README.md (FaridSafi#827)
  add image beacon to readme
  chore(package): update react-test-renderer to version 16.3.1 (FaridSafi#821)

# Conflicts:
#	.eslintignore
#	src/MessageContainer.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.