Skip to content

Commit

Permalink
Fix bottomSheet bottom insets (#8331)
Browse files Browse the repository at this point in the history
* Fix bottomSheet bottom insets

* fix search team picker on android

* ux review

* fix footer padding for message priority modal on iPad
  • Loading branch information
enahum authored Nov 29, 2024
1 parent d25c6fe commit 7cb2ee7
Show file tree
Hide file tree
Showing 56 changed files with 155 additions and 194 deletions.
5 changes: 1 addition & 4 deletions app/components/announcement_banner/announcement_banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import {
View,
} from 'react-native';
import Animated, {useAnimatedStyle, useSharedValue, withTiming} from 'react-native-reanimated';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

import {dismissAnnouncement} from '@actions/local/systems';
import CompassIcon from '@components/compass_icon';
Expand Down Expand Up @@ -85,7 +84,6 @@ const AnnouncementBanner = ({
const intl = useIntl();
const serverUrl = useServerUrl();
const height = useSharedValue(0);
const {bottom} = useSafeAreaInsets();
const theme = useTheme();
const [visible, setVisible] = useState(false);
const style = getStyle(theme);
Expand All @@ -107,7 +105,6 @@ const AnnouncementBanner = ({
const snapPoint = bottomSheetSnapPoint(
1,
SNAP_POINT_WITHOUT_DISMISS + (allowDismissal ? DISMISS_BUTTON_HEIGHT : 0),
bottom,
);

bottomSheet({
Expand All @@ -117,7 +114,7 @@ const AnnouncementBanner = ({
snapPoints: [1, snapPoint],
theme,
});
}, [theme.sidebarHeaderTextColor, intl.locale, renderContent, allowDismissal, bottom]);
}, [theme.sidebarHeaderTextColor, intl.locale, renderContent, allowDismissal]);

const handleDismiss = useCallback(() => {
dismissAnnouncement(serverUrl, bannerText);
Expand Down
15 changes: 9 additions & 6 deletions app/components/channel_bookmarks/add_bookmark.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@

import React, {useCallback} from 'react';
import {useIntl} from 'react-intl';
import {Alert, View, type Insets} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {Alert, Platform, View, type Insets} from 'react-native';

import Button from '@components/button';
import {ITEM_HEIGHT} from '@components/option_item';
import {Screens} from '@constants';
import {useTheme} from '@context/theme';
import {TITLE_HEIGHT} from '@screens/bottom_sheet';
import {BOTTOM_SHEET_ANDROID_OFFSET, TITLE_HEIGHT} from '@screens/bottom_sheet';
import {bottomSheet, showModal} from '@screens/navigation';
import {bottomSheetSnapPoint} from '@utils/helpers';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
Expand Down Expand Up @@ -81,7 +80,6 @@ const getStyleSheet = makeStyleSheetFromTheme((theme) => ({
const AddBookmark = ({bookmarksCount, channelId, currentUserId, canUploadFiles, showLarge}: Props) => {
const theme = useTheme();
const {formatMessage} = useIntl();
const {bottom} = useSafeAreaInsets();
const styles = getStyleSheet(theme);

const onPress = useCallback(() => {
Expand Down Expand Up @@ -126,14 +124,19 @@ const AddBookmark = ({bookmarksCount, channelId, currentUserId, canUploadFiles,
/>
);

let height = bottomSheetSnapPoint(1, (2 * ITEM_HEIGHT)) + TITLE_HEIGHT;
if (Platform.OS === 'android') {
height += BOTTOM_SHEET_ANDROID_OFFSET;
}

bottomSheet({
title: formatMessage({id: 'channel_info.add_bookmark', defaultMessage: 'Add a bookmark'}),
renderContent,
snapPoints: [1, bottomSheetSnapPoint(1, (2 * ITEM_HEIGHT), bottom) + TITLE_HEIGHT],
snapPoints: [1, height],
theme,
closeButtonId: 'close-channel-quick-actions',
});
}, [bottom, bookmarksCount, canUploadFiles, currentUserId, channelId, theme]);
}, [bookmarksCount, canUploadFiles, formatMessage, theme, channelId, currentUserId]);

const button = (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {useIntl, type IntlShape} from 'react-intl';
import {Alert, StyleSheet} from 'react-native';
import Animated from 'react-native-reanimated';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

import {ITEM_HEIGHT} from '@components/option_item';
import {useServerUrl} from '@context/server';
Expand Down Expand Up @@ -90,7 +89,6 @@ const ChannelBookmark = ({
const managedConfig = useManagedConfig<ManagedConfig>();
const serverUrl = useServerUrl();
const intl = useIntl();
const {bottom} = useSafeAreaInsets();
const [action, setAction] = useState<GalleryAction>('none');
const isDocumentFile = useMemo(() => isDocument(file), [file]);
const canCopyPublicLink = Boolean((bookmark.type === 'link' || (file?.id && publicLinkEnabled)) && managedConfig.copyAndPasteProtection !== 'true');
Expand Down Expand Up @@ -124,11 +122,11 @@ const ChannelBookmark = ({
bottomSheet({
title: bookmark.displayName,
renderContent,
snapPoints: [1, bottomSheetSnapPoint(1, (count * ITEM_HEIGHT), bottom) + TITLE_HEIGHT],
snapPoints: [1, bottomSheetSnapPoint(1, (count * ITEM_HEIGHT)) + TITLE_HEIGHT],
theme,
closeButtonId: 'close-channel-bookmark-actions',
});
}, [bookmark, bottom, canCopyPublicLink, canDeleteBookmarks, canDownloadFiles, canEditBookmarks, file, theme]);
}, [bookmark, canCopyPublicLink, canDeleteBookmarks, canDownloadFiles, canEditBookmarks, file, theme]);

const {onGestureEvent, ref} = useGalleryItem(galleryIdentifier, index || 0, handlePress);

Expand Down
5 changes: 3 additions & 2 deletions app/components/channel_bookmarks/channel_bookmarks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ const ChannelBookmarks = ({
/>
);
}, [
attachmentIndex, bookmarks, canDownloadFiles, canDeleteBookmarks, canEditBookmarks,
handlePreviewPress, publicLinkEnabled,
canDeleteBookmarks, canDownloadFiles, canEditBookmarks,
galleryIdentifier, attachmentIndex, handlePreviewPress,
publicLinkEnabled,
]);

const renderItemSeparator = useCallback(() => (<View style={styles.emptyItemSeparator}/>), []);
Expand Down
5 changes: 1 addition & 4 deletions app/components/files_search/file_options/mobile_options.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@ import Header, {HEADER_HEIGHT} from './header';
import OptionMenus from './option_menus';

import type {GalleryAction} from '@typings/screens/gallery';
import type {EdgeInsets} from 'react-native-safe-area-context';

type Props = {
fileInfo: FileInfo;
insets: EdgeInsets;
numOptions: number;
setAction: (action: GalleryAction) => void;
theme: Theme;
}

export const showMobileOptionsBottomSheet = ({
fileInfo,
insets,
numOptions,
setAction,
theme,
Expand All @@ -42,7 +39,7 @@ export const showMobileOptionsBottomSheet = ({
renderContent,
snapPoints: [
1,
bottomSheetSnapPoint(numOptions, ITEM_HEIGHT, insets.bottom) + HEADER_HEIGHT,
bottomSheetSnapPoint(numOptions, ITEM_HEIGHT) + HEADER_HEIGHT,
],
theme,
title: '',
Expand Down
1 change: 0 additions & 1 deletion app/components/files_search/file_results.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ const FileResults = ({
if (!isTablet) {
showMobileOptionsBottomSheet({
fileInfo: fInfo,
insets,
numOptions,
setAction,
theme,
Expand Down
6 changes: 2 additions & 4 deletions app/components/markdown/at_mention/at_mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Clipboard from '@react-native-clipboard/clipboard';
import React, {useCallback, useEffect, useMemo} from 'react';
import {useIntl} from 'react-intl';
import {type GestureResponderEvent, Keyboard, type StyleProp, StyleSheet, Text, type TextStyle, View} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

import {fetchUserOrGroupsByMentionsInBatch} from '@actions/remote/user';
import SlideUpPanelItem, {ITEM_HEIGHT} from '@components/slide_up_panel_item';
Expand Down Expand Up @@ -62,7 +61,6 @@ const AtMention = ({
const intl = useIntl();
const managedConfig = useManagedConfig<ManagedConfig>();
const theme = useTheme();
const {bottom} = useSafeAreaInsets();
const serverUrl = useServerUrl();

const user = useMemoMentionedUser(users, mentionName);
Expand Down Expand Up @@ -144,12 +142,12 @@ const AtMention = ({
bottomSheet({
closeButtonId: 'close-at-mention',
renderContent,
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT, bottom)],
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT)],
title: intl.formatMessage({id: 'post.options.title', defaultMessage: 'Options'}),
theme,
});
}
}, [managedConfig, intl, theme, bottom]);
}, [managedConfig?.copyAndPasteProtection, intl, theme, mentionName, user?.username]);

const mentionTextStyle: StyleProp<TextStyle> = [];

Expand Down
6 changes: 2 additions & 4 deletions app/components/markdown/markdown_code_block/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Clipboard from '@react-native-clipboard/clipboard';
import React, {useCallback, useMemo} from 'react';
import {useIntl} from 'react-intl';
import {Keyboard, StyleSheet, Text, type TextStyle, TouchableOpacity, View} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

import FormattedText from '@components/formatted_text';
import SlideUpPanelItem, {ITEM_HEIGHT} from '@components/slide_up_panel_item';
Expand Down Expand Up @@ -71,7 +70,6 @@ const MarkdownCodeBlock = ({language = '', content, textStyle}: MarkdownCodeBloc
const intl = useIntl();
const managedConfig = useManagedConfig<ManagedConfig>();
const theme = useTheme();
const {bottom} = useSafeAreaInsets();
const style = getStyleSheet(theme);
const SyntaxHighlighter = useMemo(() => {
if (!syntaxHighlighter) {
Expand Down Expand Up @@ -147,12 +145,12 @@ const MarkdownCodeBlock = ({language = '', content, textStyle}: MarkdownCodeBloc
bottomSheet({
closeButtonId: 'close-code-block',
renderContent,
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT, bottom)],
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT)],
title: intl.formatMessage({id: 'post.options.title', defaultMessage: 'Options'}),
theme,
});
}
}, [managedConfig, intl, bottom, theme]);
}, [managedConfig?.copyAndPasteProtection, intl, theme, style.bottomSheet, content]);

const trimContent = (text: string) => {
const lines = text.split('\n');
Expand Down
6 changes: 2 additions & 4 deletions app/components/markdown/markdown_image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React, {useCallback, useMemo, useRef, useState} from 'react';
import {useIntl} from 'react-intl';
import {Alert, Platform, type StyleProp, Text, type TextStyle, TouchableWithoutFeedback, View} from 'react-native';
import Animated from 'react-native-reanimated';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import {SvgUri} from 'react-native-svg';
import parseUrl from 'url-parse';

Expand Down Expand Up @@ -76,7 +75,6 @@ const MarkdownImage = ({
}: MarkdownImageProps) => {
const intl = useIntl();
const isTablet = useIsTablet();
const {bottom} = useSafeAreaInsets();
const theme = useTheme();
const style = getStyleSheet(theme);
const managedConfig = useManagedConfig<ManagedConfig>();
Expand Down Expand Up @@ -182,12 +180,12 @@ const MarkdownImage = ({
bottomSheet({
closeButtonId: 'close-mardown-image',
renderContent,
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT, bottom)],
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT)],
title: intl.formatMessage({id: 'post.options.title', defaultMessage: 'Options'}),
theme,
});
}
}, [managedConfig, intl.locale, bottom, theme]);
}, [managedConfig?.copyAndPasteProtection, intl, theme, style.bottomSheet, linkDestination, source]);

const handleOnError = useCallback(() => {
setFailed(true);
Expand Down
6 changes: 2 additions & 4 deletions app/components/markdown/markdown_latex_block/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Clipboard from '@react-native-clipboard/clipboard';
import React, {useCallback, useMemo} from 'react';
import {useIntl} from 'react-intl';
import {Keyboard, View, Text, StyleSheet, Platform} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

import FormattedText from '@components/formatted_text';
import ErrorBoundary from '@components/markdown/error_boundary';
Expand Down Expand Up @@ -90,7 +89,6 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {

const LatexCodeBlock = ({content, theme}: Props) => {
const intl = useIntl();
const {bottom} = useSafeAreaInsets();
const managedConfig = useManagedConfig<ManagedConfig>();
const styles = getStyleSheet(theme);
const languageDisplayName = getHighlightLanguageName('latex');
Expand Down Expand Up @@ -161,12 +159,12 @@ const LatexCodeBlock = ({content, theme}: Props) => {
bottomSheet({
closeButtonId: 'close-code-block',
renderContent,
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT, bottom)],
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT)],
title: intl.formatMessage({id: 'post.options.title', defaultMessage: 'Options'}),
theme,
});
}
}, [managedConfig?.copyAndPasteProtection, intl, bottom, theme]);
}, [managedConfig?.copyAndPasteProtection, intl, theme, styles.bottomSheet, content]);

const onRenderErrorMessage = useCallback(({error}: {error: Error}) => {
return <Text style={styles.errorText}>{'Render error: ' + error.message}</Text>;
Expand Down
6 changes: 2 additions & 4 deletions app/components/markdown/markdown_link/markdown_link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Clipboard from '@react-native-clipboard/clipboard';
import React, {Children, type ReactElement, useCallback} from 'react';
import {useIntl} from 'react-intl';
import {Alert, StyleSheet, Text, View} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';
import urlParse from 'url-parse';

import SlideUpPanelItem, {ITEM_HEIGHT} from '@components/slide_up_panel_item';
Expand Down Expand Up @@ -47,7 +46,6 @@ const parseLinkLiteral = (literal: string) => {

const MarkdownLink = ({children, experimentalNormalizeMarkdownLinks, href, siteURL, onLinkLongPress}: MarkdownLinkProps) => {
const intl = useIntl();
const {bottom} = useSafeAreaInsets();
const managedConfig = useManagedConfig<ManagedConfig>();
const serverUrl = useServerUrl();
const theme = useTheme();
Expand Down Expand Up @@ -146,12 +144,12 @@ const MarkdownLink = ({children, experimentalNormalizeMarkdownLinks, href, siteU
bottomSheet({
closeButtonId: 'close-mardown-link',
renderContent,
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT, bottom)],
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT)],
title: intl.formatMessage({id: 'post.options.title', defaultMessage: 'Options'}),
theme,
});
}
}, [managedConfig, intl, bottom, theme, onLinkLongPress]);
}, [managedConfig?.copyAndPasteProtection, onLinkLongPress, intl, theme, href]);

const renderChildren = experimentalNormalizeMarkdownLinks ? parseChildren() : children;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import React, {useCallback} from 'react';
import {useIntl} from 'react-intl';
import {Alert, StyleSheet} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

import CompassIcon from '@components/compass_icon';
import {ITEM_HEIGHT} from '@components/slide_up_panel_item';
Expand Down Expand Up @@ -40,7 +39,6 @@ export default function CameraQuickAction({
}: QuickActionAttachmentProps) {
const intl = useIntl();
const theme = useTheme();
const {bottom} = useSafeAreaInsets();

const handleButtonPress = useCallback((options: CameraOptions) => {
const picker = new PickerUtil(intl,
Expand Down Expand Up @@ -72,11 +70,11 @@ export default function CameraQuickAction({
bottomSheet({
title: intl.formatMessage({id: 'mobile.camera_type.title', defaultMessage: 'Camera options'}),
renderContent,
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT, bottom) + TITLE_HEIGHT],
snapPoints: [1, bottomSheetSnapPoint(2, ITEM_HEIGHT) + TITLE_HEIGHT],
theme,
closeButtonId: 'camera-close-id',
});
}, [intl, theme, renderContent, maxFilesReached, maxFileCount, bottom]);
}, [intl, theme, renderContent, maxFilesReached, maxFileCount]);

const actionTestID = disabled ? `${testID}.disabled` : testID;
const color = disabled ? changeOpacity(theme.centerChannelColor, 0.16) : changeOpacity(theme.centerChannelColor, 0.64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function PostPriorityAction({
closeButtonId: POST_PRIORITY_PICKER_BUTTON,
},
});
}, [intl, postPriority, updatePostPriority, theme]);
}, [isTablet, intl, theme, postPriority, updatePostPriority]);

const iconName = 'alert-circle-outline';
const iconColor = changeOpacity(theme.centerChannelColor, 0.64);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import React, {useCallback, useMemo} from 'react';
import {useIntl} from 'react-intl';
import {View, Text, TouchableOpacity, useWindowDimensions} from 'react-native';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

import {acknowledgePost, unacknowledgePost} from '@actions/remote/post';
import {fetchMissingProfilesByIds} from '@actions/remote/user';
Expand Down Expand Up @@ -75,7 +74,6 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
const Acknowledgements = ({currentUserId, currentUserTimezone, hasReactions, location, post, theme}: Props) => {
const intl = useIntl();
const isTablet = useIsTablet();
const {bottom} = useSafeAreaInsets();
const serverUrl = useServerUrl();
const {height} = useWindowDimensions();

Expand Down Expand Up @@ -143,7 +141,7 @@ const Acknowledgements = ({currentUserId, currentUserTimezone, hasReactions, loc
</>
);

const snapPoint1 = bottomSheetSnapPoint(Math.min(userIds.length, 5), USER_ROW_HEIGHT, bottom) + TITLE_HEIGHT;
const snapPoint1 = bottomSheetSnapPoint(Math.min(userIds.length, 5), USER_ROW_HEIGHT) + TITLE_HEIGHT;
const snapPoint2 = height * 0.8;
const snapPoints: number[] = [1, Math.min(snapPoint1, snapPoint2)];
if (userIds.length > 5 && snapPoint1 < snapPoint2) {
Expand All @@ -158,7 +156,11 @@ const Acknowledgements = ({currentUserId, currentUserTimezone, hasReactions, loc
title: intl.formatMessage({id: 'mobile.acknowledgements.header', defaultMessage: 'Acknowledgements'}),
theme,
});
}, [bottom, intl, isTablet, acknowledgements, theme, location, post.channelId, currentUserTimezone]);
}, [
acknowledgements, height, intl,
theme, serverUrl, isTablet, style.listHeaderText,
post.channelId, location, currentUserTimezone,
]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const UserListItem = ({
Keyboard.dismiss();
openAsBottomSheet({screen, title, theme, closeButtonId, props});
}
}, [channelId, location]);
}, [channelId, intl, location, theme]);

return (
<UserItem
Expand Down
Loading

0 comments on commit 7cb2ee7

Please sign in to comment.