regression(Android): Poor performance in messages list (#5267)
* fix: remove RefreshControl from RoomView * fix: add container to verify android or ios
This commit is contained in:
parent
74cd85a069
commit
231057af10
|
@ -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
|
inverted={isIOS}
|
||||||
removeClippedSubviews={isIOS}
|
removeClippedSubviews={isIOS}
|
||||||
initialNumToRender={7}
|
initialNumToRender={7}
|
||||||
onEndReachedThreshold={0.5}
|
onEndReachedThreshold={0.5}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { StyleSheet, View } from 'react-native';
|
import { StyleSheet, View, Platform } from 'react-native';
|
||||||
|
|
||||||
import { CustomIcon } from '../../../../containers/CustomIcon';
|
import { CustomIcon } from '../../../../containers/CustomIcon';
|
||||||
import { useTheme } from '../../../../theme';
|
import { useTheme } from '../../../../theme';
|
||||||
|
@ -43,7 +43,15 @@ const NavBottomFAB = ({
|
||||||
style={[
|
style={[
|
||||||
styles.container,
|
styles.container,
|
||||||
{
|
{
|
||||||
|
...Platform.select({
|
||||||
|
ios: {
|
||||||
bottom: 100 + (isThread ? 40 : 0)
|
bottom: 100 + (isThread ? 40 : 0)
|
||||||
|
},
|
||||||
|
android: {
|
||||||
|
top: 15,
|
||||||
|
scaleY: -1
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
]}
|
]}
|
||||||
testID='nav-jump-to-bottom'
|
testID='nav-jump-to-bottom'
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
export * from './useMessages';
|
export * from './useMessages';
|
||||||
export * from './useRefresh';
|
|
||||||
export * from './useScroll';
|
export * from './useScroll';
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
import moment from 'moment';
|
|
||||||
import { useState } from 'react';
|
|
||||||
|
|
||||||
import log from '../../../../lib/methods/helpers/log';
|
|
||||||
import { loadMissedMessages, loadThreadMessages } from '../../../../lib/methods';
|
|
||||||
|
|
||||||
export const useRefresh = ({ rid, tmid, messagesLength }: { rid: string; tmid?: string; messagesLength: number }) => {
|
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
|
||||||
|
|
||||||
const refresh = async () => {
|
|
||||||
if (messagesLength) {
|
|
||||||
setRefreshing(true);
|
|
||||||
try {
|
|
||||||
if (tmid) {
|
|
||||||
await loadThreadMessages({ tmid, rid });
|
|
||||||
} else {
|
|
||||||
await loadMissedMessages({ rid, lastOpen: moment().subtract(7, 'days').toDate() });
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
log(e);
|
|
||||||
}
|
|
||||||
setRefreshing(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return [refreshing, refresh] as const;
|
|
||||||
};
|
|
|
@ -1,12 +1,24 @@
|
||||||
import React, { forwardRef, useImperativeHandle } from 'react';
|
import React, { forwardRef, useImperativeHandle } from 'react';
|
||||||
import { RefreshControl } from 'react-native';
|
import { Platform, StyleSheet, View } from 'react-native';
|
||||||
|
|
||||||
import ActivityIndicator from '../../../containers/ActivityIndicator';
|
import ActivityIndicator from '../../../containers/ActivityIndicator';
|
||||||
import { useMessages, useRefresh, useScroll } from './hooks';
|
import { isAndroid, useDebounce } from '../../../lib/methods/helpers';
|
||||||
import { isIOS, useDebounce } from '../../../lib/methods/helpers';
|
|
||||||
import { 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';
|
import { useMessages, useScroll } from './hooks';
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
inverted: {
|
||||||
|
...Platform.select({
|
||||||
|
android: {
|
||||||
|
scaleY: -1
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const Container = ({ children }: { children: React.ReactElement }) =>
|
||||||
|
isAndroid ? <View style={{ flex: 1, scaleY: -1 }}>{children}</View> : <>{children}</>;
|
||||||
|
|
||||||
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) => {
|
||||||
|
@ -17,8 +29,6 @@ const ListContainer = forwardRef<IListContainerRef, IListContainerProps>(
|
||||||
serverVersion,
|
serverVersion,
|
||||||
hideSystemMessages
|
hideSystemMessages
|
||||||
});
|
});
|
||||||
const { colors } = useTheme();
|
|
||||||
const [refreshing, refresh] = useRefresh({ rid, tmid, messagesLength: messages.length });
|
|
||||||
const {
|
const {
|
||||||
jumpToBottom,
|
jumpToBottom,
|
||||||
jumpToMessage,
|
jumpToMessage,
|
||||||
|
@ -44,11 +54,14 @@ const ListContainer = forwardRef<IListContainerRef, IListContainerProps>(
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderItem: IListProps['renderItem'] = ({ item, index }) => renderRow(item, messages[index + 1], highlightedMessageId);
|
const renderItem: IListProps['renderItem'] = ({ item, index }) => (
|
||||||
|
<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} />
|
||||||
|
<Container>
|
||||||
<List
|
<List
|
||||||
listRef={listRef}
|
listRef={listRef}
|
||||||
data={messages}
|
data={messages}
|
||||||
|
@ -59,10 +72,8 @@ const ListContainer = forwardRef<IListContainerRef, IListContainerProps>(
|
||||||
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
|
|
||||||
}
|
|
||||||
/>
|
/>
|
||||||
|
</Container>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1361,8 +1361,8 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
|
||||||
if (showUnreadSeparator || dateSeparator) {
|
if (showUnreadSeparator || dateSeparator) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{content}
|
|
||||||
<Separator ts={dateSeparator} unread={showUnreadSeparator} />
|
<Separator ts={dateSeparator} unread={showUnreadSeparator} />
|
||||||
|
{content}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue