diff --git a/native/navigation/chat-tab-bar-button.react.js b/native/navigation/chat-tab-bar-button.react.js new file mode 100644 index 000000000..1e3f006db --- /dev/null +++ b/native/navigation/chat-tab-bar-button.react.js @@ -0,0 +1,101 @@ +// @flow + +import { useRoute } from '@react-navigation/core'; +import * as React from 'react'; +import { Animated, Text, View } from 'react-native'; +import { TabBarItem } from 'react-native-tab-view'; + +import type { NUXTipRouteNames } from './route-names.js'; +import { useSelector } from '../redux/redux-utils.js'; +import { useStyles } from '../themes/colors.js'; +import { LightTheme, DarkTheme } from '../themes/navigation.js'; +import type { NUXTipsOverlayProps } from '../tooltip/nux-tips-overlay.react.js'; + +const dummyCallback = () => {}; +const dummyNavigationState = { index: 0, routes: [] }; + +const unboundStyles = { + button: { + flexDirection: 'row', + backgroundColor: 'tabBarBackground', + }, + label: { + textAlign: 'center', + textTransform: 'uppercase', + fontSize: 13, + margin: 4, + backgroundColor: 'transparent', + }, + icon: { + height: 24, + width: 24, + }, +}; + +type Props = { + +tabBarIcon: ({ +color: string, ... }) => React$Node, + +title: string, +}; + +function createChatTabBarButton( + props: Props, +): React.ComponentType> { + function ChatTabBarButton(): React.Node { + const { title, tabBarIcon: Icon } = props; + + const position = React.useRef(() => new Animated.Value(0)); + const route = useRoute(); + + const activeTheme = useSelector(state => state.globalThemeInfo.activeTheme); + const color = React.useMemo( + () => + activeTheme === 'dark' ? DarkTheme.colors.text : LightTheme.colors.text, + [activeTheme], + ); + + const styles = useStyles(unboundStyles); + + const renderLabel = React.useCallback( + ({ color: labelColor }: { color: string, ... }) => { + return ( + {title} + ); + }, + [styles.label, title], + ); + + const renderIcon = React.useCallback( + ({ color: iconColor }: { color: string, ... }) => { + return ( + + + + ); + }, + [styles.icon], + ); + + const renderLabelText = React.useCallback(() => title, [title]); + + return ( + + ); + } + return React.memo(ChatTabBarButton); +} + +export { createChatTabBarButton }; diff --git a/native/navigation/muted-tab-tip.react.js b/native/navigation/muted-tab-tip.react.js index bb8bcdc53..ccea321e5 100644 --- a/native/navigation/muted-tab-tip.react.js +++ b/native/navigation/muted-tab-tip.react.js @@ -1,116 +1,39 @@ // @flow -import { useRoute } from '@react-navigation/core'; import * as React from 'react'; -import { Animated, Text, View } from 'react-native'; -import { TabBarItem } from 'react-native-tab-view'; import { useCurrentUserFID } from 'lib/utils/farcaster-utils.js'; +import { createChatTabBarButton } from './chat-tab-bar-button.react.js'; import { backgroundChatThreadListOptions } from '../chat/chat-options.js'; -import { useSelector } from '../redux/redux-utils.js'; -import { useStyles } from '../themes/colors.js'; -import { LightTheme, DarkTheme } from '../themes/navigation.js'; import { type NUXTipsOverlayProps, createNUXTipsOverlay, } from '../tooltip/nux-tips-overlay.react.js'; const mutedTabTipTextBase = 'When you mute a chat, it automatically gets moved to this tab.'; const mutedTabTipTextIfFID = ' When Comm automatically adds you to a community associated with a ' + 'Farcaster channel you follow, we mute them by default.'; -const dummyCallback = () => {}; -const dummyNavigationState = { index: 0, routes: [] }; - -const unboundStyles = { - button: { - flexDirection: 'row', - backgroundColor: 'tabBarBackground', - }, - label: { - textAlign: 'center', - textTransform: 'uppercase', - fontSize: 13, - margin: 4, - backgroundColor: 'transparent', - }, - icon: { - height: 24, - width: 24, - }, -}; - -function WrappedChatTabBarButton(): React.Node { - const { title, tabBarIcon: Icon } = backgroundChatThreadListOptions; - - const position = React.useRef(() => new Animated.Value(0)); - const route = useRoute(); - - const activeTheme = useSelector(state => state.globalThemeInfo.activeTheme); - const color = React.useMemo( - () => - activeTheme === 'dark' ? DarkTheme.colors.text : LightTheme.colors.text, - [activeTheme], - ); - - const styles = useStyles(unboundStyles); - - const renderLabel = React.useCallback( - ({ color: labelColor }: { color: string, ... }) => { - return {title}; - }, - [styles.label, title], - ); - - const renderIcon = React.useCallback( - ({ color: iconColor }: { color: string, ... }) => { - return ( - - - - ); - }, - [styles.icon], - ); - - const renderLabelText = React.useCallback(() => title, [title]); - - return ( - - ); -} - function MutedTabTip(props: NUXTipsOverlayProps<'MutedTabTip'>): React.Node { const fid = useCurrentUserFID(); const text = React.useMemo(() => { if (!fid) { return mutedTabTipTextBase; } return mutedTabTipTextBase + mutedTabTipTextIfFID; }, [fid]); const MutedTabTipComponent: React.ComponentType< NUXTipsOverlayProps<'MutedTabTip'>, - > = createNUXTipsOverlay(WrappedChatTabBarButton, text); + > = createNUXTipsOverlay( + createChatTabBarButton<'MutedTabTip'>(backgroundChatThreadListOptions), + text, + ); return ; } export default MutedTabTip;