Skip to content
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

MainTabsScreen: Add Users icon to bottom nav #5506

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions src/main/MainTabsScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import type { AppNavigationMethods, AppNavigationProp } from '../nav/AppNavigato
import { bottomTabNavigatorConfig } from '../styles/tabs';
import HomeScreen from './HomeScreen';
import PmConversationsScreen from '../pm-conversations/PmConversationsScreen';
import { IconInbox, IconStream, IconPeople } from '../common/Icons';
import { IconInbox, IconStream, IconPeople, IconPrivateChat } from '../common/Icons';
import OwnAvatar from '../common/OwnAvatar';
import OfflineNotice from '../common/OfflineNotice';
import ProfileScreen from '../account-info/ProfileScreen';
import styles, { BRAND_COLOR, ThemeContext } from '../styles';
import SubscriptionsScreen from '../streams/SubscriptionsScreen';
import UsersProfileScreen from '../users/UsersProfileScreen';

export type MainTabsNavigatorParamList = {|
+home: RouteParamsOf<typeof HomeScreen>,
Expand Down Expand Up @@ -77,14 +78,22 @@ export default function MainTabsScreen(props: Props): Node {
component={PmConversationsScreen}
options={{
tabBarLabel: 'Private messages',
tabBarIcon: ({ color }) => <IconPeople size={24} color={color} />,
tabBarIcon: ({ color }) => <IconPrivateChat size={24} color={color} />,
tabBarBadge: unreadPmsCount > 0 ? unreadPmsCount : undefined,
tabBarBadgeStyle: {
color: 'white',
backgroundColor: BRAND_COLOR,
},
}}
/>
<Tab.Screen
name="users"
component={UsersProfileScreen}
options={{
tabBarLabel: 'Users',
tabBarIcon: ({ color }) => <IconPeople size={24} color={color} />,
}}
/>
<Tab.Screen
name="profile"
component={ProfileScreen}
Expand Down
32 changes: 32 additions & 0 deletions src/users/UsersProfileCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* @flow strict-local */

import React, { useCallback } from 'react';
import type { Node } from 'react';

import type { UserOrBot } from '../types';
import { useSelector } from '../react-redux';
import UserList from './UserList';
import { getUsers, getPresence } from '../selectors';
import { useNavigation } from '../react-navigation';

type Props = $ReadOnly<{|
filter: string,
|}>;

export default function UsersProfileCard(props: Props): Node {
const { filter } = props;
const users = useSelector(getUsers);
const presences = useSelector(getPresence);

const navigation = useNavigation();
const handleUserNarrow = useCallback(
(user: UserOrBot) => {
navigation.push('account-details', { userId: user.user_id });
},
[navigation],
);

return (
<UserList users={users} filter={filter} presences={presences} onPress={handleUserNarrow} />
);
}
19 changes: 19 additions & 0 deletions src/users/UsersProfileScreen.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* @flow strict-local */
import React from 'react';
import type { Node } from 'react';
import { SafeAreaView } from 'react-native-safe-area-context';

import type { AppNavigationProp } from '../nav/AppNavigator';
import UsersProfileCard from './UsersProfileCard';

type Props = $ReadOnly<{|
navigation: AppNavigationProp<'users'>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should follow the model of the other screen components that have the same navigation-related context -- which means the ones that also appear in MainTabsScreen in the same way that you're adding this one there. Take a look at the navigation props on those.

|}>;

export default function UsersInfoScreen(props: Props): Node {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: function name of default export should match filename

return (
<SafeAreaView mode="padding" edges={['top']} style={{ flex: 1 }} scrollEnabled={false}>
<UsersProfileCard filter="" />
</SafeAreaView>
);
Comment on lines +13 to +18
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of having a trivial wrapper component like this, let's have just one component that does the job of both this and the inner component.

(I see the existing UsersScreen looks this way too. Maybe I'll go and fix that now.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I see the existing UsersScreen looks this way too. Maybe I'll go and fix that now.)

#5540

}