fix(Android): Remove RefreshControl from messages list (#5251)

This commit is contained in:
Diego Mello 2023-10-09 13:18:02 -03:00 committed by GitHub
parent 2589707929
commit 0d7af4088a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 24 additions and 80 deletions

View File

@ -43,7 +43,7 @@ export const List = ({ listRef, jumpToBottom, isThread, ...props }: IListProps)
keyExtractor={item => item.id} keyExtractor={item => item.id}
contentContainerStyle={styles.contentContainer} contentContainerStyle={styles.contentContainer}
style={styles.list} style={styles.list}
inverted={isIOS} inverted
removeClippedSubviews={isIOS} removeClippedSubviews={isIOS}
initialNumToRender={7} initialNumToRender={7}
onEndReachedThreshold={0.5} onEndReachedThreshold={0.5}

View File

@ -1,5 +1,5 @@
import React from 'react'; import React from 'react';
import { StyleSheet, View, Platform } from 'react-native'; import { StyleSheet, View } from 'react-native';
import { CustomIcon } from '../../../../containers/CustomIcon'; import { CustomIcon } from '../../../../containers/CustomIcon';
import { useTheme } from '../../../../theme'; import { useTheme } from '../../../../theme';
@ -43,15 +43,7 @@ const NavBottomFAB = ({
style={[ style={[
styles.container, styles.container,
{ {
...Platform.select({ bottom: 100 + (isThread ? 40 : 0)
ios: {
bottom: 100 + (isThread ? 40 : 0)
},
android: {
top: 15,
scaleY: -1
}
})
} }
]} ]}
testID='nav-jump-to-bottom' testID='nav-jump-to-bottom'

View File

@ -1,38 +0,0 @@
import React from 'react';
import { RefreshControl as RNRefreshControl, RefreshControlProps, StyleSheet } from 'react-native';
import { useTheme } from '../../../../theme';
import { isAndroid } from '../../../../lib/methods/helpers';
const style = StyleSheet.create({
container: {
flex: 1
},
inverted: {
scaleY: -1
}
});
interface IRefreshControl extends RefreshControlProps {
children: React.ReactElement;
}
export const RefreshControl = ({ children, onRefresh, refreshing }: IRefreshControl): React.ReactElement => {
const { colors } = useTheme();
if (isAndroid) {
return (
<RNRefreshControl
onRefresh={onRefresh}
refreshing={refreshing}
tintColor={colors.auxiliaryText}
style={[style.container, style.inverted]}
>
{children}
</RNRefreshControl>
);
}
const refreshControl = <RNRefreshControl onRefresh={onRefresh} refreshing={refreshing} tintColor={colors.auxiliaryText} />;
return React.cloneElement(children, { refreshControl });
};

View File

@ -1,4 +1,3 @@
export * from './NavBottomFAB'; export * from './NavBottomFAB';
export * from './RefreshControl';
export * from './EmptyRoom'; export * from './EmptyRoom';
export * from './List'; export * from './List';

View File

@ -1,21 +1,12 @@
import React, { forwardRef, useImperativeHandle } from 'react'; import React, { forwardRef, useImperativeHandle } from 'react';
import { View, Platform, StyleSheet } from 'react-native'; import { RefreshControl } from 'react-native';
import ActivityIndicator from '../../../containers/ActivityIndicator'; import ActivityIndicator from '../../../containers/ActivityIndicator';
import { useMessages, useRefresh, useScroll } from './hooks'; import { useMessages, useRefresh, useScroll } from './hooks';
import { useDebounce } from '../../../lib/methods/helpers'; import { isIOS, useDebounce } from '../../../lib/methods/helpers';
import { RefreshControl, EmptyRoom, List } from './components'; import { EmptyRoom, List } from './components';
import { IListContainerProps, IListContainerRef, IListProps } from './definitions'; import { IListContainerProps, IListContainerRef, IListProps } from './definitions';
import { useTheme } from '../../../theme';
const styles = StyleSheet.create({
inverted: {
...Platform.select({
android: {
scaleY: -1
}
})
}
});
const ListContainer = forwardRef<IListContainerRef, IListContainerProps>( const ListContainer = forwardRef<IListContainerRef, IListContainerProps>(
({ rid, tmid, renderRow, showMessageInMainThread, serverVersion, hideSystemMessages, listRef, loading }, ref) => { ({ rid, tmid, renderRow, showMessageInMainThread, serverVersion, hideSystemMessages, listRef, loading }, ref) => {
@ -26,6 +17,7 @@ const ListContainer = forwardRef<IListContainerRef, IListContainerProps>(
serverVersion, serverVersion,
hideSystemMessages hideSystemMessages
}); });
const { colors } = useTheme();
const [refreshing, refresh] = useRefresh({ rid, tmid, messagesLength: messages.length }); const [refreshing, refresh] = useRefresh({ rid, tmid, messagesLength: messages.length });
const { const {
jumpToBottom, jumpToBottom,
@ -52,26 +44,25 @@ const ListContainer = forwardRef<IListContainerRef, IListContainerProps>(
return null; return null;
}; };
const renderItem: IListProps['renderItem'] = ({ item, index }) => ( const renderItem: IListProps['renderItem'] = ({ item, index }) => renderRow(item, messages[index + 1], highlightedMessageId);
<View style={styles.inverted}>{renderRow(item, messages[index + 1], highlightedMessageId)}</View>
);
return ( return (
<> <>
<EmptyRoom rid={rid} length={messages.length} /> <EmptyRoom rid={rid} length={messages.length} />
<RefreshControl refreshing={refreshing} onRefresh={refresh}> <List
<List listRef={listRef}
listRef={listRef} data={messages}
data={messages} renderItem={renderItem}
renderItem={renderItem} onEndReached={onEndReached}
onEndReached={onEndReached} ListFooterComponent={renderFooter}
ListFooterComponent={renderFooter} onScrollToIndexFailed={handleScrollToIndexFailed}
onScrollToIndexFailed={handleScrollToIndexFailed} viewabilityConfigCallbackPairs={viewabilityConfigCallbackPairs.current}
viewabilityConfigCallbackPairs={viewabilityConfigCallbackPairs.current} jumpToBottom={jumpToBottom}
jumpToBottom={jumpToBottom} isThread={!!tmid}
isThread={!!tmid} refreshControl={
/> isIOS ? <RefreshControl refreshing={refreshing} onRefresh={refresh} tintColor={colors.auxiliaryText} /> : undefined
</RefreshControl> }
/>
</> </>
); );
} }

View File

@ -1361,8 +1361,8 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
if (showUnreadSeparator || dateSeparator) { if (showUnreadSeparator || dateSeparator) {
return ( return (
<> <>
<Separator ts={dateSeparator} unread={showUnreadSeparator} />
{content} {content}
<Separator ts={dateSeparator} unread={showUnreadSeparator} />
</> </>
); );
} }