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

Migrate index.js to function component #25818

Merged
Changes from all 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
45 changes: 20 additions & 25 deletions src/components/InvertedFlatList/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {forwardRef} from 'react';
import React, {forwardRef, useEffect} from 'react';
import PropTypes from 'prop-types';
import {FlatList, StyleSheet} from 'react-native';
import _ from 'underscore';
Expand All @@ -18,34 +18,29 @@ const propTypes = {

// This is adapted from https://codesandbox.io/s/react-native-dsyse
// It's a HACK alert since FlatList has inverted scrolling on web
class InvertedFlatList extends React.Component {
constructor(props) {
super(props);
function InvertedFlatList(props) {
const {innerRef, contentContainerStyle} = props;
const listRef = React.createRef();

this.list = undefined;
}

componentDidMount() {
if (!_.isFunction(this.props.innerRef)) {
useEffect(() => {
if (!_.isFunction(innerRef)) {
// eslint-disable-next-line no-param-reassign
this.props.innerRef.current = this.list;
innerRef.current = listRef.current;
} else {
this.props.innerRef(this.list);
innerRef(listRef);
}
}

render() {
return (
<BaseInvertedFlatList
// eslint-disable-next-line react/jsx-props-no-spreading
{...this.props}
inverted
ref={(el) => (this.list = el)}
shouldMeasureItems
contentContainerStyle={StyleSheet.compose(this.props.contentContainerStyle, styles.justifyContentEnd)}
/>
);
}
}, [innerRef, listRef]);

return (
<BaseInvertedFlatList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
inverted
ref={listRef}
shouldMeasureItems
contentContainerStyle={StyleSheet.compose(contentContainerStyle, styles.justifyContentEnd)}
/>
);
}

InvertedFlatList.propTypes = propTypes;
Expand Down