Skip to content

Commit

Permalink
[MM-54599] Fix Servers bottom sheet (mattermost#7609)
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-vrn authored and Рахман Рустамов committed Jan 12, 2024
1 parent 42f0370 commit 7e1ff06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
15 changes: 11 additions & 4 deletions app/screens/home/channel_list/servers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import React, {useCallback, useEffect, useImperativeHandle, useRef, useState} from 'react';
import {useIntl} from 'react-intl';
import {StyleSheet} from 'react-native';
import {Dimensions, StyleSheet} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

import ServerIcon from '@components/server_icon';
Expand All @@ -27,7 +27,8 @@ export type ServersRef = {
openServers: () => void;
}

export const SERVER_ITEM_HEIGHT = 72;
export const SERVER_ITEM_HEIGHT = 75;
export const PUSH_ALERT_TEXT_HEIGHT = 42;
const subscriptions: Map<string, UnreadSubscription> = new Map();

const styles = StyleSheet.create({
Expand Down Expand Up @@ -116,12 +117,18 @@ const Servers = React.forwardRef<ServersRef>((_, ref) => {
<ServerList servers={registeredServers.current!}/>
);
};
const maxScreenHeight = Math.ceil(0.6 * Dimensions.get('window').height);
const maxSnapPoint = Math.min(
maxScreenHeight,
bottomSheetSnapPoint(registeredServers.current.length, SERVER_ITEM_HEIGHT, bottom) + TITLE_HEIGHT + BUTTON_HEIGHT +
(registeredServers.current.filter((s: ServersModel) => s.lastActiveAt).length * PUSH_ALERT_TEXT_HEIGHT),
);

const snapPoints: BottomSheetProps['snapPoints'] = [
1,
bottomSheetSnapPoint(Math.min(2.5, registeredServers.current.length), 72, bottom) + TITLE_HEIGHT + BUTTON_HEIGHT,
maxSnapPoint,
];
if (registeredServers.current.length > 1) {
if (maxSnapPoint === maxScreenHeight) {
snapPoints.push('80%');
}

Expand Down
7 changes: 6 additions & 1 deletion app/screens/home/channel_list/servers/servers_list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
import {BottomSheetFlatList} from '@gorhom/bottom-sheet';
import React, {useCallback, useMemo} from 'react';
import {useIntl} from 'react-intl';
import {FlatList, type ListRenderItemInfo, StyleSheet, View} from 'react-native';
import {FlatList, StyleSheet, View, type ListRenderItemInfo} from 'react-native';

import {useServerUrl} from '@context/server';
import {useTheme} from '@context/theme';
import {useIsTablet} from '@hooks/device';
import {BUTTON_HEIGHT} from '@screens/bottom_sheet';
import BottomSheetContent from '@screens/bottom_sheet/content';
import {addNewServer} from '@utils/server';

Expand All @@ -29,6 +30,9 @@ const styles = StyleSheet.create({
contentContainer: {
marginVertical: 4,
},
serverList: {
marginBottom: BUTTON_HEIGHT,
},
});

const keyExtractor = (item: ServersModel) => item.url;
Expand Down Expand Up @@ -68,6 +72,7 @@ const ServerList = ({servers}: Props) => {
<View style={[styles.container, {marginTop: isTablet ? 12 : 0}]}>
<List
data={servers}
style={styles.serverList}
renderItem={renderServer}
keyExtractor={keyExtractor}
contentContainerStyle={styles.contentContainer}
Expand Down

0 comments on commit 7e1ff06

Please sign in to comment.