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

Fix missing avatars #2099

Merged
merged 5 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/components/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Avatar extends PureComponent {

return (
<Image
ref={el => this.image = el}
source={{uri: this.props.source}}
style={_.union([
this.props.size === 'small' ? styles.avatarSmall : styles.avatarNormal,
Expand Down
12 changes: 6 additions & 6 deletions src/components/InvertedFlatList/BaseInvertedFlatList.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable react/jsx-props-no-multi-spaces */
import _ from 'underscore';
import React, {forwardRef, Component} from 'react';
import PropTypes from 'prop-types';
Expand Down Expand Up @@ -25,11 +26,15 @@ const propTypes = {

// Should we measure these items and call getItemLayout?
shouldMeasureItems: PropTypes.bool,

// Should we remove the clipped sub views?
removeClippedSubviews: PropTypes.bool,
marcaaron marked this conversation as resolved.
Show resolved Hide resolved
};

const defaultProps = {
data: [],
shouldMeasureItems: false,
removeClippedSubviews: false,
};

class BaseInvertedFlatList extends Component {
Expand Down Expand Up @@ -146,18 +151,13 @@ class BaseInvertedFlatList extends Component {

// Native platforms do not need to measure items and work fine without this.
// Web requires that items be measured or else crazy things happen when scrolling.
// eslint-disable-next-line react/jsx-props-no-multi-spaces
getItemLayout={this.props.shouldMeasureItems ? this.getItemLayout : undefined}
bounces={false}

// We keep this property very low so that chat switching remains fast
// eslint-disable-next-line react/jsx-props-no-multi-spaces
maxToRenderPerBatch={1}
windowSize={15}

// Setting removeClippedSubviews will break text selection on Android
// eslint-disable-next-line react/jsx-props-no-multi-spaces
removeClippedSubviews={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.

@AndrewGable do you remember how this broke text selection on Android? I tested it and seemed to work ok to me, but maybe I misinterpreted this comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

I believe it was something along the lines of https://stackoverflow.com/a/66703331/2509962

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chatted with Andrew and neither one of us could remember why it was added. We're also going to implement a long press menu to select the entire contents of a message IIRC so whatever this refers to (still not entirely sure) might be even less relevant in the future.

removeClippedSubviews={this.props.removeClippedSubviews}
/>
);
}
Expand Down
15 changes: 15 additions & 0 deletions src/components/InvertedFlatList/index.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, {forwardRef} from 'react';
import BaseInvertedFlatList from './BaseInvertedFlatList';

export default forwardRef((props, ref) => (
<BaseInvertedFlatList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}

// Remove clipped subviews helps prevent avatars and attachments from eating up excess memory on Android. When
// we run out of memory images stop appearing without any warning.
// eslint-disable-next-line react/jsx-props-no-multi-spaces
removeClippedSubviews
/>
));
3 changes: 2 additions & 1 deletion src/components/OptionsList.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import _ from 'underscore';
import React, {forwardRef, Component} from 'react';
import {View, SectionList, Text} from 'react-native';
import {View, Text} from 'react-native';
import PropTypes from 'prop-types';
import styles from '../styles/styles';
import OptionRow from '../pages/home/sidebar/OptionRow';
import optionPropTypes from './optionPropTypes';
import SectionList from './SectionList';

const propTypes = {
// Style for hovered state
Expand Down
15 changes: 15 additions & 0 deletions src/components/SectionList/index.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React, {forwardRef} from 'react';
import {SectionList} from 'react-native';

export default forwardRef((props, ref) => (
<SectionList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}

// For Android we want to use removeClippedSubviews since it helps manage memory consumption. When we
// run out memory images stop loading and appear as grey circles
// eslint-disable-next-line react/jsx-props-no-multi-spaces
removeClippedSubviews
/>
));
3 changes: 3 additions & 0 deletions src/components/SectionList/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {SectionList} from 'react-native';

export default SectionList;

Choose a reason for hiding this comment

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

What does this file do ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not much 😄 . It imports the unmodified SectionList and then re-exports it. This is because we have different builds depending on the platform and will switch extensions e.g.

import SectionList from './SectionList';

On web, this will pull from /SectionList/index.js but on Android it will use /SectionList/index.android.js

So we are basically saying, when building for web use the unmodified SectionList