Skip to content

Commit

Permalink
Merge pull request #30962 from s-alves10/fix/issue-30935
Browse files Browse the repository at this point in the history
fix: remove wrong use of createRef
(cherry picked from commit 73ded84)
  • Loading branch information
robertjchen authored and OSBotify committed Nov 8, 2023
1 parent 7c71518 commit f7da265
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/components/InvertedFlatList/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import PropTypes from 'prop-types';
import React, {forwardRef, useEffect, useRef} from 'react';
<<<<<<< HEAD
import {DeviceEventEmitter, FlatList, StyleSheet} from 'react-native';
import _ from 'underscore';
import styles from '@styles/styles';
=======
import {DeviceEventEmitter, FlatList} from 'react-native';
>>>>>>> 73ded84 (Merge pull request #30962 from s-alves10/fix/issue-30935)
import CONST from '@src/CONST';
import BaseInvertedFlatList from './BaseInvertedFlatList';

Expand All @@ -24,31 +28,24 @@ const propTypes = {
// It's a HACK alert since FlatList has inverted scrolling on web
function InvertedFlatList(props) {
const {innerRef, contentContainerStyle} = props;
const listRef = React.createRef();

const lastScrollEvent = useRef(null);
const scrollEndTimeout = useRef(null);
const updateInProgress = useRef(false);
const eventHandler = useRef(null);

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

return () => {
useEffect(
() => () => {
if (scrollEndTimeout.current) {
clearTimeout(scrollEndTimeout.current);
}

if (eventHandler.current) {
eventHandler.current.remove();
}
};
}, [innerRef, listRef]);
},
[innerRef],
);

/**
* Emits when the scrolling is in progress. Also,
Expand Down Expand Up @@ -114,7 +111,7 @@ function InvertedFlatList(props) {
<BaseInvertedFlatList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={listRef}
ref={innerRef}
shouldMeasureItems
contentContainerStyle={StyleSheet.compose(contentContainerStyle, styles.justifyContentEnd)}
onScroll={handleScroll}
Expand Down

0 comments on commit f7da265

Please sign in to comment.