diff --git a/src/view/shell/bottom-bar/BottomBar.tsx b/src/view/shell/bottom-bar/BottomBar.tsx index 855ba21b23..0845316e02 100644 --- a/src/view/shell/bottom-bar/BottomBar.tsx +++ b/src/view/shell/bottom-bar/BottomBar.tsx @@ -121,6 +121,107 @@ export function BottomBar({navigation}: BottomTabBarProps) { accountSwitchControl.open() }, [accountSwitchControl, playHaptic]) + const renderHomeIcon = React.useCallback( + () => + isAtHome ? ( + + ) : ( + + ), + [isAtHome, pal.text], + ) + + const renderSearchIcon = React.useCallback( + () => + isAtSearch ? ( + + ) : ( + + ), + [isAtSearch, pal.text], + ) + + const renderMessagesIcon = React.useCallback( + () => + isAtMessages ? ( + + ) : ( + + ), + [isAtMessages, pal.text], + ) + + const renderNotificationsIcon = React.useCallback( + () => + isAtNotifications ? ( + + ) : ( + + ), + [isAtNotifications, pal.text], + ) + + const renderProfileIcon = React.useCallback( + () => ( + + {isAtMyProfile ? ( + + + + ) : ( + + + + )} + + ), + [isAtMyProfile, profile?.avatar, profile?.associated?.labeler, pal.text], + ) + return ( <> @@ -140,39 +241,15 @@ export function BottomBar({navigation}: BottomTabBarProps) { <> - ) : ( - - ) - } + renderIcon={renderHomeIcon} onPress={onPressHome} accessibilityRole="tab" accessibilityLabel={_(msg`Home`)} accessibilityHint="" /> - ) : ( - - ) - } + testID="bottomBarSearchBtn" + renderIcon={renderSearchIcon} onPress={onPressSearch} accessibilityRole="search" accessibilityLabel={_(msg`Search`)} @@ -180,19 +257,7 @@ export function BottomBar({navigation}: BottomTabBarProps) { /> - ) : ( - - ) - } + renderIcon={renderMessagesIcon} onPress={onPressMessages} notificationCount={numUnreadMessages.numUnread} accessible={true} @@ -206,19 +271,7 @@ export function BottomBar({navigation}: BottomTabBarProps) { /> - ) : ( - - ) - } + renderIcon={renderNotificationsIcon} onPress={onPressNotifications} notificationCount={numUnreadNotifications} accessible={true} @@ -232,39 +285,7 @@ export function BottomBar({navigation}: BottomTabBarProps) { /> - {isAtMyProfile ? ( - - - - ) : ( - - - - )} - - } + renderIcon={renderProfileIcon} onPress={onPressProfile} onLongPress={onLongPressProfile} accessibilityRole="tab" @@ -332,22 +353,22 @@ interface BtnProps | 'accessibilityLabel' > { testID?: string - icon: JSX.Element + renderIcon: () => React.ReactNode notificationCount?: string onPress?: (event: GestureResponderEvent) => void onLongPress?: (event: GestureResponderEvent) => void } -function Btn({ +let Btn = ({ testID, - icon, + renderIcon, notificationCount, onPress, onLongPress, accessible, accessibilityHint, accessibilityLabel, -}: BtnProps) { +}: BtnProps): React.ReactNode => { return ( - {icon} + {renderIcon()} {notificationCount ? ( {notificationCount} @@ -367,3 +388,4 @@ function Btn({ ) } +Btn = React.memo(Btn)