-
Notifications
You must be signed in to change notification settings - Fork 3k
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
replace FlatList with .map solution #53655
Merged
blimpich
merged 14 commits into
Expensify:main
from
callstack-internal:JKobrynski/fix/53027-transaction-violation-flash
Dec 23, 2024
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
95ac502
replace FlatList with .map solution
JKobrynski 0e58ab3
Replace FlatList with .map solution in DebugReportActions.tsx
JKobrynski c44b3df
Merge branch 'main' into JKobrynski/fix/53027-transaction-violation-f…
pac-guerreiro eb9a939
Merge branch 'main' into JKobrynski/fix/53027-transaction-violation-f…
pac-guerreiro 090a98a
fix(debug mode): screen flashing when switching tabs or navigating ba…
pac-guerreiro 6acbbcb
chore: resolve eslint issues
pac-guerreiro 3430d47
chore: resolve eslint issues
pac-guerreiro 928ce4d
Merge branch 'main' into JKobrynski/fix/53027-transaction-violation-f…
pac-guerreiro 0861766
Merge branch 'main' into JKobrynski/fix/53027-transaction-violation-f…
pac-guerreiro 1115836
chore: resolve eslint issues
pac-guerreiro 5887903
Merge branch 'main' into JKobrynski/fix/53027-transaction-violation-f…
pac-guerreiro 17caf6b
Merge branch 'main' into JKobrynski/fix/53027-transaction-violation-f…
pac-guerreiro b6ccc0b
fix(debug mode): app crashing when accessing debug details page
pac-guerreiro 3aa6c45
Merge branch 'main' into JKobrynski/fix/53027-transaction-violation-f…
pac-guerreiro 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 contains 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 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 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 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 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 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,152 @@ | ||
import type {EventMapCore, NavigationProp, NavigationState} from '@react-navigation/native'; | ||
import {useNavigation} from '@react-navigation/native'; | ||
import {createStackNavigator} from '@react-navigation/stack'; | ||
import React, {useEffect, useMemo, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
import * as Expensicons from '@components/Icon/Expensicons'; | ||
import type {LocaleContextProps} from '@components/LocaleContextProvider'; | ||
import getBackgroundColor from '@components/TabSelector/getBackground'; | ||
import getOpacity from '@components/TabSelector/getOpacity'; | ||
import TabSelectorItem from '@components/TabSelector/TabSelectorItem'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useTheme from '@hooks/useTheme'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import CONST from '@src/CONST'; | ||
import type IconAsset from '@src/types/utils/IconAsset'; | ||
|
||
type IconAndTitle = { | ||
icon: IconAsset; | ||
title: string; | ||
}; | ||
|
||
function getIconAndTitle(route: string, translate: LocaleContextProps['translate']): IconAndTitle { | ||
switch (route) { | ||
case CONST.DEBUG.DETAILS: | ||
return {icon: Expensicons.Info, title: translate('debug.details')}; | ||
case CONST.DEBUG.JSON: | ||
return {icon: Expensicons.Eye, title: translate('debug.JSON')}; | ||
case CONST.DEBUG.REPORT_ACTIONS: | ||
return {icon: Expensicons.Document, title: translate('debug.reportActions')}; | ||
case CONST.DEBUG.REPORT_ACTION_PREVIEW: | ||
return {icon: Expensicons.Document, title: translate('debug.reportActionPreview')}; | ||
case CONST.DEBUG.TRANSACTION_VIOLATIONS: | ||
return {icon: Expensicons.Exclamation, title: translate('debug.violations')}; | ||
default: | ||
throw new Error(`Route ${route} has no icon nor title set.`); | ||
} | ||
} | ||
|
||
const StackNavigator = createStackNavigator(); | ||
|
||
type DebugTabNavigatorRoute = { | ||
name: string; | ||
component: () => React.ReactNode; | ||
}; | ||
|
||
type DebugTabNavigatorRoutes = DebugTabNavigatorRoute[]; | ||
|
||
type DebugTabNavigatorProps = { | ||
id: string; | ||
routes: DebugTabNavigatorRoutes; | ||
}; | ||
|
||
function DebugTabNavigator({id, routes}: DebugTabNavigatorProps) { | ||
const styles = useThemeStyles(); | ||
const theme = useTheme(); | ||
const navigation = useNavigation<NavigationProp<Record<string, void>>>(); | ||
const {translate} = useLocalize(); | ||
const [currentTab, setCurrentTab] = useState(routes.at(0)?.name); | ||
const defaultAffectedAnimatedTabs = useMemo(() => Array.from({length: routes.length}, (v, i) => i), [routes.length]); | ||
const [affectedAnimatedTabs, setAffectedAnimatedTabs] = useState(defaultAffectedAnimatedTabs); | ||
|
||
useEffect(() => { | ||
// It is required to wait transition end to reset affectedAnimatedTabs because tabs style is still animating during transition. | ||
setTimeout(() => { | ||
setAffectedAnimatedTabs(defaultAffectedAnimatedTabs); | ||
}, CONST.ANIMATED_TRANSITION); | ||
}, [defaultAffectedAnimatedTabs, currentTab]); | ||
|
||
return ( | ||
<> | ||
<View style={styles.tabSelector}> | ||
{routes.map((route, index) => { | ||
const isActive = route.name === currentTab; | ||
const activeOpacity = getOpacity({ | ||
routesLength: routes.length, | ||
tabIndex: index, | ||
active: true, | ||
affectedTabs: affectedAnimatedTabs, | ||
position: undefined, | ||
isActive, | ||
}); | ||
const inactiveOpacity = getOpacity({ | ||
routesLength: routes.length, | ||
tabIndex: index, | ||
active: false, | ||
affectedTabs: affectedAnimatedTabs, | ||
position: undefined, | ||
isActive, | ||
}); | ||
const backgroundColor = getBackgroundColor({ | ||
routesLength: routes.length, | ||
tabIndex: index, | ||
affectedTabs: affectedAnimatedTabs, | ||
theme, | ||
position: undefined, | ||
isActive, | ||
}); | ||
const {icon, title} = getIconAndTitle(route.name, translate); | ||
|
||
const onPress = () => { | ||
navigation.navigate(route.name); | ||
setCurrentTab(route.name); | ||
}; | ||
|
||
return ( | ||
<TabSelectorItem | ||
key={route.name} | ||
icon={icon} | ||
title={title} | ||
onPress={onPress} | ||
activeOpacity={activeOpacity} | ||
inactiveOpacity={inactiveOpacity} | ||
backgroundColor={backgroundColor} | ||
isActive={isActive} | ||
/> | ||
); | ||
})} | ||
</View> | ||
<StackNavigator.Navigator | ||
id={id} | ||
screenOptions={{ | ||
animationEnabled: false, | ||
headerShown: false, | ||
}} | ||
screenListeners={{ | ||
state: (e) => { | ||
const event = e as unknown as EventMapCore<NavigationState>['state']; | ||
const state = event.data.state; | ||
const routeNames = state.routeNames; | ||
const newSelectedTab = state.routes.at(state.routes.length - 1)?.name; | ||
if (currentTab === newSelectedTab || (currentTab && !routeNames.includes(currentTab))) { | ||
return; | ||
} | ||
setCurrentTab(newSelectedTab); | ||
}, | ||
}} | ||
> | ||
{routes.map((route) => ( | ||
<StackNavigator.Screen | ||
key={route.name} | ||
name={route.name} | ||
component={route.component} | ||
/> | ||
))} | ||
</StackNavigator.Navigator> | ||
</> | ||
); | ||
} | ||
|
||
export default DebugTabNavigator; | ||
|
||
export type {DebugTabNavigatorRoutes}; |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching to
.map()
isn't ideal sinceFlatList
provides built-in virtualization and better performance for large lists.The flashing issue you mentioned might be due to the missing
keyExtractor
prop in theFlatList
.I suggest re-adding
FlatList
with akeyExtractor
like this to see if it resolves the issue:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried it before (forgot to mention it in the proposal) and unfortunately this doesn't fix it.
Here is a demo:
keyextractor-compressed.mov