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

fix: sample app ui bugs #2854

Merged
merged 3 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion examples/SampleApp/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { ChannelPinnedMessagesScreen } from './src/screens/ChannelPinnedMessages
import { ChatScreen } from './src/screens/ChatScreen';
import { GroupChannelDetailsScreen } from './src/screens/GroupChannelDetailsScreen';
import { LoadingScreen } from './src/screens/LoadingScreen';
import { MenuDrawer } from './src/screens/MenuDrawer';
import { MenuDrawer } from './src/components/MenuDrawer';
import { NewDirectMessagingScreen } from './src/screens/NewDirectMessagingScreen';
import { NewGroupChannelAddMemberScreen } from './src/screens/NewGroupChannelAddMemberScreen';
import { NewGroupChannelAssignNameScreen } from './src/screens/NewGroupChannelAssignNameScreen';
Expand Down
19 changes: 12 additions & 7 deletions examples/SampleApp/src/components/AddMemberBottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React, { useState } from 'react';
import { ActivityIndicator, StyleSheet, Text, TextInput, View } from 'react-native';
import { TouchableOpacity } from '@gorhom/bottom-sheet';
import {
ActivityIndicator,
StyleSheet,
Text,
TextInput,
TouchableOpacity,
View,
} from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { CircleClose, Search, useTheme } from 'stream-chat-react-native';

Expand Down Expand Up @@ -37,16 +43,15 @@ const styles = StyleSheet.create({
alignItems: 'center',
borderRadius: 18,
borderWidth: 1,
flex: 1,
flexDirection: 'row',
marginRight: 16,
paddingHorizontal: 10,
paddingVertical: 8,
},
inputRow: {
alignItems: 'center',
flexDirection: 'row',
padding: 16,
justifyContent: 'center',
},
text: {
marginLeft: 10,
Expand Down Expand Up @@ -135,10 +140,10 @@ export const AddMemberBottomSheet: React.FC = () => {
]}
value={searchText}
/>
<TouchableOpacity onPress={clearText}>
<CircleClose pathFill={grey} />
</TouchableOpacity>
</View>
<TouchableOpacity onPress={clearText}>
<CircleClose pathFill={grey} />
</TouchableOpacity>
</View>
<View style={styles.flex}>
{addMemberQueryInProgress && (
Expand Down
9 changes: 5 additions & 4 deletions examples/SampleApp/src/components/ChannelInfoOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import Animated, {
import {
Avatar,
CircleClose,
Delete,
User,
UserMinus,
useTheme,
Expand All @@ -32,7 +33,6 @@ import {
import { useAppOverlayContext } from '../context/AppOverlayContext';
import { useBottomSheetOverlayContext } from '../context/BottomSheetOverlayContext';
import { useChannelInfoOverlayContext } from '../context/ChannelInfoOverlayContext';
import { Delete } from '../icons/Delete';

dayjs.extend(relativeTime);

Expand Down Expand Up @@ -77,9 +77,10 @@ const styles = StyleSheet.create({
borderBottomWidth: 1,
borderTopWidth: 1,
flexDirection: 'row',
paddingVertical: 16,
},
row: { alignItems: 'center', borderTopWidth: 1, flexDirection: 'row' },
rowInner: { paddingLeft: 16, paddingRight: 10, paddingVertical: 20 },
row: { alignItems: 'center', borderTopWidth: 1, flexDirection: 'row', paddingVertical: 16 },
rowInner: { paddingLeft: 16, paddingRight: 10 },
rowText: {
fontSize: 14,
fontWeight: '700',
Expand Down Expand Up @@ -408,7 +409,7 @@ export const ChannelInfoOverlay = (props: ChannelInfoOverlayProps) => {
]}
>
<View style={styles.rowInner}>
<Delete height={32} pathFill={accent_red} width={32} />
<Delete size={24} fill={accent_red} />
</View>
<Text style={[styles.rowText, { color: accent_red }]}>
Delete conversation
Expand Down
4 changes: 2 additions & 2 deletions examples/SampleApp/src/components/ChannelPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Swipeable from 'react-native-gesture-handler/Swipeable';
import {
ChannelPreviewMessenger,
ChannelPreviewMessengerProps,
Delete,
MenuPointHorizontal,
useChatContext,
useTheme,
Expand All @@ -18,7 +19,6 @@ import { useChannelInfoOverlayContext } from '../context/ChannelInfoOverlayConte
import type { StackNavigationProp } from '@react-navigation/stack';

import type { StackNavigatorParamList, StreamChatGenerics } from '../types';
import { Delete } from '../icons/Delete';

const styles = StyleSheet.create({
leftSwipeableButton: {
Expand Down Expand Up @@ -99,7 +99,7 @@ export const ChannelPreview: React.FC<ChannelPreviewMessengerProps<StreamChatGen
}}
style={[styles.rightSwipeableButton]}
>
<Delete height={32} pathFill={accent_red} width={32} />
<Delete size={32} fill={accent_red} />
</RectButton>
</View>
)}
Expand Down
8 changes: 3 additions & 5 deletions examples/SampleApp/src/components/ConfirmationBottomSheet.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { TouchableOpacity } from '@gorhom/bottom-sheet';
import { StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { UserMinus, useTheme } from 'stream-chat-react-native';
import { Delete, UserMinus, useTheme } from 'stream-chat-react-native';

import { useAppOverlayContext } from '../context/AppOverlayContext';
import {
isAddMemberBottomSheetData,
useBottomSheetOverlayContext,
} from '../context/BottomSheetOverlayContext';
import { Delete } from '../icons/Delete';

const styles = StyleSheet.create({
actionButtonLeft: {
Expand Down Expand Up @@ -79,7 +77,7 @@ export const ConfirmationBottomSheet: React.FC = () => {
{confirmText === 'LEAVE' ? (
<UserMinus pathFill={grey} />
) : (
<Delete height={32} pathFill={accent_red} width={32} />
<Delete size={32} fill={accent_red} />
)}
<Text style={[styles.title, { color: black }]}>{title}</Text>
<Text style={[styles.subtext, { color: black }]}>{subtext}</Text>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,48 +57,68 @@ export const MenuDrawer = ({ navigation }: DrawerContentComponentProps) => {
}

return (
<SafeAreaView style={[styles.container, { backgroundColor: white }]}>
<View style={styles.userRow}>
<Image
source={{
uri: chatClient.user?.image,
}}
style={styles.avatar}
/>
<Text
style={[
styles.userName,
{
color: black,
},
]}
>
{chatClient.user?.name}
</Text>
</View>
<View style={styles.menuContainer}>
<View>
<TouchableOpacity
onPress={() => navigation.navigate('NewDirectMessagingScreen')}
style={styles.menuItem}
<View style={[styles.container, { backgroundColor: white }]}>
<SafeAreaView style={{ flex: 1 }}>
<View style={[styles.userRow]}>
<Image
source={{
uri: chatClient.user?.image,
}}
style={styles.avatar}
/>
<Text
style={[
styles.userName,
{
color: black,
},
]}
>
<Edit height={24} pathFill={grey} width={24} />
<Text
style={[
styles.menuTitle,
{
color: black,
},
]}
{chatClient.user?.name}
</Text>
</View>
<View style={styles.menuContainer}>
<View>
<TouchableOpacity
onPress={() => navigation.navigate('NewDirectMessagingScreen')}
style={styles.menuItem}
>
New Direct Messages
</Text>
</TouchableOpacity>
<Edit height={24} pathFill={grey} width={24} />
<Text
style={[
styles.menuTitle,
{
color: black,
},
]}
>
New Direct Messages
</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => navigation.navigate('NewGroupChannelAddMemberScreen')}
style={styles.menuItem}
>
<Group height={24} pathFill={grey} width={24} />
<Text
style={[
styles.menuTitle,
{
color: black,
},
]}
>
New Group
</Text>
</TouchableOpacity>
</View>
<TouchableOpacity
onPress={() => navigation.navigate('NewGroupChannelAddMemberScreen')}
onPress={() => {
logout();
}}
style={styles.menuItem}
>
<Group height={24} pathFill={grey} width={24} />
<User height={24} pathFill={grey} width={24} />
<Text
style={[
styles.menuTitle,
Expand All @@ -107,29 +127,11 @@ export const MenuDrawer = ({ navigation }: DrawerContentComponentProps) => {
},
]}
>
New Group
Sign Out
</Text>
</TouchableOpacity>
</View>
<TouchableOpacity
onPress={() => {
logout();
}}
style={styles.menuItem}
>
<User height={24} pathFill={grey} width={24} />
<Text
style={[
styles.menuTitle,
{
color: black,
},
]}
>
Sign Out
</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</SafeAreaView>
</View>
);
};
22 changes: 18 additions & 4 deletions examples/SampleApp/src/components/NewDirectMessagingSendButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import {
import { NewDirectMessagingScreenNavigationProp } from '../screens/NewDirectMessagingScreen';

import { StreamChatGenerics as LocalStreamChatGenerics } from '../types';
import { useUserSearchContext } from '../context/UserSearchContext';
import { useAppContext } from '../context/AppContext';

type NewDirectMessagingSendButtonPropsWithContext<
StreamChatGenerics extends DefaultStreamChatGenerics = DefaultStreamChatGenerics,
Expand Down Expand Up @@ -97,24 +99,36 @@ export type SendButtonProps<
* UI Component for send button in MessageInput component.
*/
export const NewDirectMessagingSendButton = (props: SendButtonProps<LocalStreamChatGenerics>) => {
const { chatClient } = useAppContext();
const navigation = useNavigation<NewDirectMessagingScreenNavigationProp>();
const { channel } = useChannelContext<LocalStreamChatGenerics>();
const { selectedUserIds, reset } = useUserSearchContext();

const { giphyActive, text } = useMessageInputContext<LocalStreamChatGenerics>();

const sendMessage = async () => {
if (!channel) {
return;
}
if (!chatClient || !chatClient.user) {
return;
}
const members = [chatClient.user.id, ...selectedUserIds];
channel.initialized = false;
await channel.query({});
const newChannel = chatClient.channel('messaging', {
members,
});
try {
await channel.sendMessage({ text });
await newChannel.watch();
await newChannel.sendMessage({ text });
navigation.replace('ChannelScreen', {
channelId: channel.id,
channelId: newChannel.id,
});
reset();
} catch (e) {
Alert.alert('Error sending a message');
if (e instanceof Error) {
Alert.alert('Error sending a message', e.message);
}
}
};

Expand Down
2 changes: 2 additions & 0 deletions examples/SampleApp/src/components/ScreenHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export const ScreenHeader: React.FC<ScreenHeaderProps> = (props) => {
color: black,
},
]}
numberOfLines={1}
>
{titleText}
</Text>
Expand All @@ -182,6 +183,7 @@ export const ScreenHeader: React.FC<ScreenHeaderProps> = (props) => {
color: grey,
},
]}
numberOfLines={1}
>
{subtitleText}
</Text>
Expand Down
26 changes: 18 additions & 8 deletions examples/SampleApp/src/components/UserInfoOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { useEffect } from 'react';
import { Keyboard, SafeAreaView, StyleSheet, Text, View, ViewStyle } from 'react-native';
import { Alert, Keyboard, SafeAreaView, StyleSheet, Text, View, ViewStyle } from 'react-native';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
import {
Expand Down Expand Up @@ -302,14 +302,24 @@ export const UserInfoOverlay = (props: UserInfoOverlayProps) => {
members,
});

const newChannel =
channels.length === 1
? channels[0]
: client.channel('messaging', {
members,
});
console.log('channels', channels.length);
khushal87 marked this conversation as resolved.
Show resolved Hide resolved
let newChannel;
if (channels.length === 1) {
newChannel = channels[0];
} else {
try {
newChannel = client.channel('messaging', { members });
await newChannel.watch();
} catch (error) {
newChannel = undefined;
if (error instanceof Error) {
Alert.alert('Error creating channel', error.message);
}
}
}

setOverlay('none');
if (navigation) {
if (navigation && newChannel) {
navigation.navigate('OneOnOneChannelDetailScreen', {
channel: newChannel,
});
Expand Down
Loading
Loading