Export RefreshControl so we don't have to use theme hoc

This commit is contained in:
Diego Mello 2022-12-02 13:36:37 -03:00
parent b2db5500b6
commit f5615c50f6
3 changed files with 19 additions and 12 deletions

View File

@ -0,0 +1,11 @@
import React from 'react';
import { RefreshControl as RefreshControlRN, RefreshControlProps } from 'react-native';
import { useTheme } from '../../../theme';
type TRefreshControlProps = Pick<RefreshControlProps, 'refreshing' | 'onRefresh'>;
export const RefreshControl = ({ refreshing, onRefresh }: TRefreshControlProps): React.ReactElement => {
const { colors } = useTheme();
return <RefreshControlRN refreshing={refreshing} onRefresh={onRefresh} tintColor={colors.auxiliaryText} />;
};

View File

@ -2,7 +2,7 @@ import { Q } from '@nozbe/watermelondb';
import { dequal } from 'dequal'; import { dequal } from 'dequal';
import moment from 'moment'; import moment from 'moment';
import React from 'react'; import React from 'react';
import { FlatListProps, ViewToken, RefreshControl } from 'react-native'; import { FlatListProps, ViewToken } from 'react-native';
import { event, Value } from 'react-native-reanimated'; import { event, Value } from 'react-native-reanimated';
import { Observable, Subscription } from 'rxjs'; import { Observable, Subscription } from 'rxjs';
@ -18,9 +18,9 @@ import List, { IListProps, TListRef } from './List';
import NavBottomFAB from './NavBottomFAB'; import NavBottomFAB from './NavBottomFAB';
import { loadMissedMessages, loadThreadMessages } from '../../../lib/methods'; import { loadMissedMessages, loadThreadMessages } from '../../../lib/methods';
import { Services } from '../../../lib/services'; import { Services } from '../../../lib/services';
import { TSupportedThemes, withTheme } from '../../../theme'; import { MESSAGE_TYPE_ANY_LOAD } from '../../../lib/constants';
import { MESSAGE_TYPE_ANY_LOAD, themes } from '../../../lib/constants';
import { TMessage } from '../definitions'; import { TMessage } from '../definitions';
import { RefreshControl } from './RefreshControl';
const QUERY_SIZE = 50; const QUERY_SIZE = 50;
@ -50,7 +50,6 @@ export interface IListContainerProps {
navigation: any; // TODO: type me navigation: any; // TODO: type me
showMessageInMainThread: boolean; showMessageInMainThread: boolean;
serverVersion: string | null; serverVersion: string | null;
theme?: TSupportedThemes;
} }
interface IListContainerState { interface IListContainerState {
@ -339,8 +338,8 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
render() { render() {
console.count(`${this.constructor.name}.render calls`); console.count(`${this.constructor.name}.render calls`);
const { rid, tmid, listRef, theme, loading } = this.props; const { rid, tmid, listRef, loading } = this.props;
const { messages, refreshing } = this.state; const { messages, refreshing, highlightedMessage } = this.state;
return ( return (
<> <>
<EmptyRoom rid={rid} length={messages.length} mounted={this.mounted} /> <EmptyRoom rid={rid} length={messages.length} mounted={this.mounted} />
@ -349,7 +348,7 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
scrollEventThrottle={16} scrollEventThrottle={16}
listRef={listRef} listRef={listRef}
data={messages} data={messages}
extraData={loading || messages} extraData={loading || messages || highlightedMessage}
// @ts-ignore // @ts-ignore
renderItem={this.renderItem} renderItem={this.renderItem}
onEndReached={this.onEndReached} onEndReached={this.onEndReached}
@ -358,9 +357,7 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
onViewableItemsChanged={this.onViewableItemsChanged} onViewableItemsChanged={this.onViewableItemsChanged}
viewabilityConfig={this.viewabilityConfig} viewabilityConfig={this.viewabilityConfig}
nativeID={tmid || rid} nativeID={tmid || rid}
refreshControl={ refreshControl={<RefreshControl refreshing={refreshing} onRefresh={this.onRefresh} />}
<RefreshControl refreshing={refreshing} onRefresh={this.onRefresh} tintColor={themes[theme!].auxiliaryText} />
}
/> />
<NavBottomFAB y={this.y} onPress={this.jumpToBottom} isThread={!!tmid} /> <NavBottomFAB y={this.y} onPress={this.jumpToBottom} isThread={!!tmid} />
</> </>
@ -370,4 +367,4 @@ class ListContainer extends React.Component<IListContainerProps, IListContainerS
export type ListContainerType = ListContainer; export type ListContainerType = ListContainer;
export default withTheme(ListContainer); export default ListContainer;

View File

@ -1535,7 +1535,6 @@ class RoomView extends React.Component<IRoomViewProps, IRoomViewState> {
<StatusBar /> <StatusBar />
<Banner title={I18n.t('Announcement')} text={announcement} bannerClosed={bannerClosed} closeBanner={this.closeBanner} /> <Banner title={I18n.t('Announcement')} text={announcement} bannerClosed={bannerClosed} closeBanner={this.closeBanner} />
<List <List
// @ts-ignore
ref={this.list} ref={this.list}
listRef={this.flatList} listRef={this.flatList}
rid={rid} rid={rid}