Repository navigation
chore: Migrate RoomView/List to Hooks #5207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
0e16488
Base useMessages
diegolmello de540a8
onEndReached
diegolmello 1e7b049
Thread
diegolmello 275c351
hide system messages
diegolmello ed10616
Empty room
diegolmello 19113ab
debounce onEndReached
diegolmello 1958849
onRefresh
diegolmello f387bd8
FAB
diegolmello f915f19
lint
diegolmello c28bd2f
useRefresh hook
diegolmello 9f43acf
jumpToMessage base: need to fix closure
diegolmello 03ae2ca
export fetchMessages from useMessage
diegolmello e09772e
Fix jump to message
diegolmello 4fd19fa
Rename to ListContainer and add some logs
diegolmello 4f64fac
useJump and definitions
diegolmello 42b10c2
constants
diegolmello 6f2a32f
Highlight message
diegolmello 7889dcb
Move messageIds to useMessage
diegolmello 31e8a42
Layout animation
diegolmello a395b74
Read thread
diegolmello 4d0ace2
render footer
diegolmello 4797496
Import TListRef from correct location
diegolmello eaa67a5
hooks folder
diegolmello 4d05ab4
components folder
diegolmello 03794b2
Move styles
diegolmello 656a0db
Remove outdated props
diegolmello f46f13a
🚨 Properly type list ref and remove some code
diegolmello 7f4c3ca
Remove some logs
diegolmello fd5d8ed
Fix some types
diegolmello f7f55e7
Map messages inside subscribe
diegolmello a87a6cd
Fix empty debounce
diegolmello 0e245e1
Simplify some types
diegolmello 98be0cc
Call animateNextTransition for iOS only, so it doesn't create unneces…
diegolmello fe3524b
Remove unnecessary handleOnPress function
diegolmello cbe8327
theme -> colors
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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} /> | ||
| </> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| import React from 'react'; | ||
| import { StyleSheet, View, Platform } from 'react-native'; | ||
|
|
||
| import { themes } from '../../../../lib/constants'; | ||
| 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 { theme } = useTheme(); | ||
| const handleOnPress = () => onPress(); | ||
|
|
||
| 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={handleOnPress} style={[styles.button, { backgroundColor: themes[theme].backgroundColor }]}> | ||
| <View style={[styles.content, { borderColor: themes[theme].borderColor }]}> | ||
| <CustomIcon name='chevron-down' color={themes[theme].auxiliaryTintColor} size={36} /> | ||
| </View> | ||
| </Touch> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default NavBottomFAB; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| export * from './useMessages'; | ||
| export * from './useRefresh'; | ||
| export * from './useScroll'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.