Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
0e16488
Base useMessages
diegolmello Sep 11, 2023
de540a8
onEndReached
diegolmello Sep 11, 2023
1e7b049
Thread
diegolmello Sep 11, 2023
275c351
hide system messages
diegolmello Sep 11, 2023
ed10616
Empty room
diegolmello Sep 11, 2023
19113ab
debounce onEndReached
diegolmello Sep 11, 2023
1958849
onRefresh
diegolmello Sep 11, 2023
f387bd8
FAB
diegolmello Sep 11, 2023
f915f19
lint
diegolmello Sep 11, 2023
c28bd2f
useRefresh hook
diegolmello Sep 12, 2023
9f43acf
jumpToMessage base: need to fix closure
diegolmello Sep 12, 2023
03ae2ca
export fetchMessages from useMessage
diegolmello Sep 12, 2023
e09772e
Fix jump to message
diegolmello Sep 12, 2023
4fd19fa
Rename to ListContainer and add some logs
diegolmello Sep 13, 2023
4f64fac
useJump and definitions
diegolmello Sep 13, 2023
42b10c2
constants
diegolmello Sep 13, 2023
6f2a32f
Highlight message
diegolmello Sep 13, 2023
7889dcb
Move messageIds to useMessage
diegolmello Sep 13, 2023
31e8a42
Layout animation
diegolmello Sep 13, 2023
a395b74
Read thread
diegolmello Sep 13, 2023
4d0ace2
render footer
diegolmello Sep 13, 2023
4797496
Import TListRef from correct location
diegolmello Sep 13, 2023
eaa67a5
hooks folder
diegolmello Sep 13, 2023
4d05ab4
components folder
diegolmello Sep 13, 2023
03794b2
Move styles
diegolmello Sep 13, 2023
656a0db
Remove outdated props
diegolmello Sep 13, 2023
f46f13a
🚨 Properly type list ref and remove some code
diegolmello Sep 13, 2023
7f4c3ca
Remove some logs
diegolmello Sep 13, 2023
fd5d8ed
Fix some types
diegolmello Sep 13, 2023
f7f55e7
Map messages inside subscribe
diegolmello Sep 13, 2023
a87a6cd
Fix empty debounce
diegolmello Sep 13, 2023
0e245e1
Simplify some types
diegolmello Sep 14, 2023
98be0cc
Call animateNextTransition for iOS only, so it doesn't create unneces…
diegolmello Sep 14, 2023
fe3524b
Remove unnecessary handleOnPress function
diegolmello Sep 21, 2023
cbe8327
theme -> colors
diegolmello Sep 21, 2023
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
49 changes: 0 additions & 49 deletions app/views/RoomView/List/List.tsx

This file was deleted.

75 changes: 0 additions & 75 deletions app/views/RoomView/List/NavBottomFAB.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { ImageBackground, StyleSheet } from 'react-native';

import { useTheme } from '../../theme';
import { useTheme } from '../../../../theme';

const styles = StyleSheet.create({
image: {
Expand All @@ -11,12 +11,10 @@ const styles = StyleSheet.create({
}
});

const EmptyRoom = React.memo(({ length, mounted, rid }: { length: number; mounted: boolean; rid: string }) => {
export const EmptyRoom = React.memo(({ length, rid }: { length: number; rid: string }) => {
const { theme } = useTheme();
if ((length === 0 && mounted) || !rid) {
if (length === 0 || !rid) {
return <ImageBackground source={{ uri: `message_empty_${theme}` }} style={styles.image} />;
}
return null;
});

export default EmptyRoom;
60 changes: 60 additions & 0 deletions app/views/RoomView/List/components/List.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React, { useState } from 'react';
import { FlatListProps, StyleSheet } from 'react-native';
import { FlatList } from 'react-native-gesture-handler';
import Animated, { runOnJS, useAnimatedScrollHandler } from 'react-native-reanimated';

import { isIOS } from '../../../../lib/methods/helpers';
import scrollPersistTaps from '../../../../lib/methods/helpers/scrollPersistTaps';
import NavBottomFAB from './NavBottomFAB';
import { IListProps } from '../definitions';
import { SCROLL_LIMIT } from '../constants';
import { TAnyMessageModel } from '../../../../definitions';

const AnimatedFlatList = Animated.createAnimatedComponent<FlatListProps<TAnyMessageModel>>(FlatList);

const styles = StyleSheet.create({
list: {
flex: 1
},
contentContainer: {
paddingTop: 10
}
});

export const List = ({ listRef, jumpToBottom, isThread, ...props }: IListProps) => {
const [visible, setVisible] = useState(false);

const scrollHandler = useAnimatedScrollHandler({
onScroll: event => {
if (event.contentOffset.y > SCROLL_LIMIT) {
runOnJS(setVisible)(true);
} else {
runOnJS(setVisible)(false);
}
}
});

return (
<>
<AnimatedFlatList
testID='room-view-messages'
// @ts-ignore createAnimatedComponent is making this fail
ref={listRef}
keyExtractor={item => item.id}
contentContainerStyle={styles.contentContainer}
style={styles.list}
inverted={isIOS}
removeClippedSubviews={isIOS}
initialNumToRender={7}
onEndReachedThreshold={0.5}
maxToRenderPerBatch={5}
windowSize={10}
scrollEventThrottle={16}
onScroll={scrollHandler}
{...props}
{...scrollPersistTaps}
/>
<NavBottomFAB visible={visible} onPress={jumpToBottom} isThread={isThread} />
</>
);
};
68 changes: 68 additions & 0 deletions app/views/RoomView/List/components/NavBottomFAB.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import React from 'react';
import { StyleSheet, View, Platform } from 'react-native';

import { CustomIcon } from '../../../../containers/CustomIcon';
import { useTheme } from '../../../../theme';
import Touch from '../../../../containers/Touch';

const styles = StyleSheet.create({
container: {
position: 'absolute',
right: 15
},
button: {
borderRadius: 25
},
content: {
width: 50,
height: 50,
borderRadius: 25,
borderWidth: 1,
alignItems: 'center',
justifyContent: 'center'
}
});

const NavBottomFAB = ({
visible,
onPress,
isThread
}: {
visible: boolean;
onPress: Function;
isThread: boolean;
}): React.ReactElement | null => {
const { colors } = useTheme();

if (!visible) {
return null;
}

return (
<View
style={[
styles.container,
{
...Platform.select({
ios: {
bottom: 100 + (isThread ? 40 : 0)
},
android: {
top: 15,
scaleY: -1
}
})
}
]}
testID='nav-jump-to-bottom'
>
<Touch onPress={() => onPress()} style={[styles.button, { backgroundColor: colors.backgroundColor }]}>
<View style={[styles.content, { borderColor: colors.borderColor }]}>
<CustomIcon name='chevron-down' color={colors.auxiliaryTintColor} size={36} />
</View>
</Touch>
</View>
);
};

export default NavBottomFAB;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React from 'react';
import { RefreshControl as RNRefreshControl, RefreshControlProps, StyleSheet } from 'react-native';

import { useTheme } from '../../../theme';
import { isAndroid } from '../../../lib/methods/helpers';
import { useTheme } from '../../../../theme';
import { isAndroid } from '../../../../lib/methods/helpers';

const style = StyleSheet.create({
container: {
Expand All @@ -17,7 +17,7 @@ interface IRefreshControl extends RefreshControlProps {
children: React.ReactElement;
}

const RefreshControl = ({ children, onRefresh, refreshing }: IRefreshControl): React.ReactElement => {
export const RefreshControl = ({ children, onRefresh, refreshing }: IRefreshControl): React.ReactElement => {
const { colors } = useTheme();
if (isAndroid) {
return (
Expand All @@ -36,5 +36,3 @@ const RefreshControl = ({ children, onRefresh, refreshing }: IRefreshControl): R

return React.cloneElement(children, { refreshControl });
};

export default RefreshControl;
4 changes: 4 additions & 0 deletions app/views/RoomView/List/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export * from './NavBottomFAB';
export * from './RefreshControl';
export * from './EmptyRoom';
export * from './List';
7 changes: 7 additions & 0 deletions app/views/RoomView/List/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const QUERY_SIZE = 50;

export const VIEWABILITY_CONFIG = {
itemVisiblePercentThreshold: 10
};

export const SCROLL_LIMIT = 200;
31 changes: 31 additions & 0 deletions app/views/RoomView/List/definitions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { RefObject } from 'react';
import { FlatListProps } from 'react-native';
import { FlatList } from 'react-native-gesture-handler';

import { TAnyMessageModel } from '../../../definitions';

export type TListRef = RefObject<FlatList<TAnyMessageModel>>;

export type TMessagesIdsRef = RefObject<string[]>;

export interface IListProps extends FlatListProps<TAnyMessageModel> {
listRef: TListRef;
jumpToBottom: () => void;
isThread: boolean;
}

export interface IListContainerRef {
jumpToMessage: (messageId: string) => Promise<void>;
cancelJumpToMessage: () => void;
}

export interface IListContainerProps {
renderRow: Function;
rid: string;
tmid?: string;
loading: boolean;
listRef: TListRef;
hideSystemMessages: string[];
showMessageInMainThread: boolean;
serverVersion: string | null;
}
3 changes: 3 additions & 0 deletions app/views/RoomView/List/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './useMessages';
export * from './useRefresh';
export * from './useScroll';
Loading