Skip to content

Commit

Permalink
fix: sample-app crash because of viewport changes
Browse files Browse the repository at this point in the history
  • Loading branch information
khushal87 committed Nov 21, 2023
1 parent 2e39142 commit 8f6e5ec
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { FlatList, StyleSheet, Text, TouchableOpacity, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import dayjs from 'dayjs';
import { Avatar, Spinner, useTheme, vw } from 'stream-chat-react-native';
import { Avatar, Spinner, useTheme, useViewport } from 'stream-chat-react-native';

import { MESSAGE_SEARCH_LIMIT } from '../../hooks/usePaginatedSearchedMessages';

Expand Down Expand Up @@ -43,9 +43,6 @@ const styles = StyleSheet.create({
paddingLeft: 8,
},
title: { fontSize: 14, fontWeight: '700' },
titleContainer: {
maxWidth: vw(80) - 16 - 40,
},
});

export type MessageSearchListProps = {
Expand Down Expand Up @@ -73,6 +70,7 @@ export const MessageSearchList: React.FC<MessageSearchListProps> = React.forward
colors: { black, border, grey, white_snow },
},
} = useTheme();
const { vw } = useViewport();
const navigation = useNavigation();

if (loading && !refreshing && (!messages || messages.length === 0)) {
Expand Down Expand Up @@ -134,7 +132,10 @@ export const MessageSearchList: React.FC<MessageSearchListProps> = React.forward
/>
<View style={styles.flex}>
<View style={styles.row}>
<Text numberOfLines={1} style={[styles.titleContainer, { color: black }]}>
<Text
numberOfLines={1}
style={[styles.titleContainer, { color: black, maxWidth: vw(80) - 16 - 40 }]}
>
<Text style={styles.title}>{`${item.user?.name} `}</Text>
{!!item.channel?.name && (
<Text style={styles.detailsText}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from 'react-native';
import dayjs from 'dayjs';
import Svg, { Defs, LinearGradient, Rect, Stop } from 'react-native-svg';
import { Avatar, CheckSend, Close, useTheme, vw } from 'stream-chat-react-native';
import { Avatar, CheckSend, Close, useTheme, useViewport } from 'stream-chat-react-native';

import { useUserSearchContext } from '../../context/UserSearchContext';

Expand Down Expand Up @@ -103,6 +103,7 @@ export const UserSearchResults: React.FC<UserSearchResultsProps> = ({
},
},
} = useTheme();
const { vw } = useViewport();

const results = resultsProp || resultsContext;
const resultsLength = results.length;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { ActivityIndicator, FlatList, StyleSheet, Text, View } from 'react-native';
import { vw } from 'stream-chat-react-native';
import { useViewport } from 'stream-chat-react-native';

import { UserGridItem } from './UserGridItem';

Expand All @@ -10,8 +10,6 @@ import type { UserResponse } from 'stream-chat';

import type { StreamChatGenerics } from '../../types';

const totalUserSpace = vw(100) - 56; // 36 = outside margin 8 * 2 + inner padding 20 * 2;

const styles = StyleSheet.create({
container: {
flex: 1,
Expand Down Expand Up @@ -47,48 +45,53 @@ export const UserSearchResultsGrid: React.FC<UserSearchResultsGridProps> = ({
onPress,
results,
searchText,
}) => (
<View style={styles.container}>
{loading && results.length === 0 && searchText === '' ? (
<ActivityIndicator size='small' />
) : (
<FlatList
contentContainerStyle={styles.contentContainer}
data={results}
keyboardDismissMode='interactive'
keyboardShouldPersistTaps='handled'
keyExtractor={(item, index) => `${item.id}-${index}`}
ListEmptyComponent={() => (
<View style={styles.emptyResultIndicator}>
<EmptySearchState height={124} width={124} />
<Text>No user matches these keywords</Text>
<Text>{loading ? 'true' : 'false'}</Text>
<Text>{results.length}</Text>
</View>
)}
numColumns={gridSize}
onEndReached={loadMore}
renderItem={({ index, item: user }) => (
<View
style={[
styles.userGridItemContainer,
{
marginLeft: index % gridSize !== 0 ? (totalUserSpace - 64 * gridSize) / 3 : 0,
},
]}
>
<UserGridItem
onPress={() => {
onPress(user);
}}
removeButton={false}
user={user}
/>
</View>
)}
showsVerticalScrollIndicator={false}
style={styles.flex}
/>
)}
</View>
);
}) => {
const { vw } = useViewport();
const totalUserSpace = vw(100) - 56; // 36 = outside margin 8 * 2 + inner padding 20 * 2;

return (
<View style={styles.container}>
{loading && results.length === 0 && searchText === '' ? (
<ActivityIndicator size='small' />
) : (
<FlatList
contentContainerStyle={styles.contentContainer}
data={results}
keyboardDismissMode='interactive'
keyboardShouldPersistTaps='handled'
keyExtractor={(item, index) => `${item.id}-${index}`}
ListEmptyComponent={() => (
<View style={styles.emptyResultIndicator}>
<EmptySearchState height={124} width={124} />
<Text>No user matches these keywords</Text>
<Text>{loading ? 'true' : 'false'}</Text>
<Text>{results.length}</Text>
</View>
)}
numColumns={gridSize}
onEndReached={loadMore}
renderItem={({ index, item: user }) => (
<View
style={[
styles.userGridItemContainer,
{
marginLeft: index % gridSize !== 0 ? (totalUserSpace - 64 * gridSize) / 3 : 0,
},
]}
>
<UserGridItem
onPress={() => {
onPress(user);
}}
removeButton={false}
user={user}
/>
</View>
)}
showsVerticalScrollIndicator={false}
style={styles.flex}
/>
)}
</View>
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useState } from 'react';
import { StyleSheet, Text, TextInput, View } from 'react-native';
import Svg, { Defs, LinearGradient, Rect, Stop } from 'react-native-svg';
import { Check, generateRandomId, useTheme, vw } from 'stream-chat-react-native';
import { Check, generateRandomId, useTheme, useViewport } from 'stream-chat-react-native';

import { RoundButton } from '../components/RoundButton';
import { ScreenHeader } from '../components/ScreenHeader';
Expand Down Expand Up @@ -89,6 +89,7 @@ export const NewGroupChannelAssignNameScreen: React.FC<NewGroupChannelAssignName
colors: { bg_gradient_end, bg_gradient_start, black, border, grey, white_snow },
},
} = useTheme();
const { vw } = useViewport();

const [groupName, setGroupName] = useState('');

Expand Down

0 comments on commit 8f6e5ec

Please sign in to comment.