[Gekidou] Get theme from useTheme (#6485)

* get theme from useTheme. No need to pass in as a prop

* get theme from useTheme hook instead of passing in as props
This commit is contained in:
Jason Frerich
2022-07-28 06:08:38 -05:00
committed by GitHub
parent adde833ea9
commit 309c2c01bc
12 changed files with 15 additions and 23 deletions

View File

@@ -12,6 +12,7 @@ import tinyColor from 'tinycolor2';
import ProgressBar from '@components/progress_bar';
import {DOWNLOAD_TIMEOUT} from '@constants/network';
import {useServerUrl} from '@context/server';
import {useTheme} from '@context/theme';
import NetworkManager from '@managers/network_manager';
import {alertDownloadDocumentDisabled, alertDownloadFailed, alertFailedToOpenDocument} from '@utils/document';
import {fileExists, getLocalFilePathFromFile} from '@utils/file';
@@ -29,7 +30,6 @@ type DocumentFileProps = {
backgroundColor?: string;
canDownloadFiles: boolean;
file: FileInfo;
theme: Theme;
}
const styles = StyleSheet.create({
@@ -42,9 +42,10 @@ const styles = StyleSheet.create({
},
});
const DocumentFile = forwardRef<DocumentFileRef, DocumentFileProps>(({backgroundColor, canDownloadFiles, file, theme}: DocumentFileProps, ref) => {
const DocumentFile = forwardRef<DocumentFileRef, DocumentFileProps>(({backgroundColor, canDownloadFiles, file}: DocumentFileProps, ref) => {
const intl = useIntl();
const serverUrl = useServerUrl();
const theme = useTheme();
const [didCancel, setDidCancel] = useState(false);
const [downloading, setDownloading] = useState(false);
const [preview, setPreview] = useState(false);

View File

@@ -6,6 +6,7 @@ import {View, TouchableWithoutFeedback} from 'react-native';
import Animated from 'react-native-reanimated';
import TouchableWithFeedback from '@components/touchable_with_feedback';
import {useTheme} from '@context/theme';
import {useGalleryItem} from '@hooks/gallery';
import {isDocument, isImage, isVideo} from '@utils/file';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
@@ -30,7 +31,6 @@ type FileProps = {
publicLinkEnabled: boolean;
channelName?: string;
onOptionsPress?: (index: number) => void;
theme: Theme;
wrapperWidth?: number;
showDate?: boolean;
updateFileForGallery: (idx: number, file: FileInfo) => void;
@@ -76,11 +76,11 @@ const File = ({
onPress,
publicLinkEnabled,
showDate = false,
theme,
updateFileForGallery,
wrapperWidth = 300,
}: FileProps) => {
const document = useRef<DocumentFileRef>(null);
const theme = useTheme();
const style = getStyleSheet(theme);
const handlePreviewPress = useCallback(() => {
@@ -114,13 +114,11 @@ const File = ({
showDate={showDate}
channelName={channelName}
onPress={handlePreviewPress}
theme={theme}
/>
);
const renderImageFileOverlay = (
<ImageFileOverlay
theme={theme}
value={nonVisibleImagesCount}
/>
);
@@ -165,7 +163,6 @@ const File = ({
ref={document}
canDownloadFiles={canDownloadFiles}
file={file}
theme={theme}
/>
</View>
);

View File

@@ -5,6 +5,7 @@ import React from 'react';
import {Text, TouchableOpacity, View} from 'react-native';
import FormattedDate from '@components/formatted_date';
import {useTheme} from '@context/theme';
import {getFormattedFileSize} from '@utils/file';
import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme';
import {typography} from '@utils/typography';
@@ -14,7 +15,6 @@ type FileInfoProps = {
showDate: boolean;
channelName?: string ;
onPress: () => void;
theme: Theme;
}
const FORMAT = ' • MMM DD HH:MM A';
@@ -58,7 +58,8 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
};
});
const FileInfo = ({file, channelName, showDate, onPress, theme}: FileInfoProps) => {
const FileInfo = ({file, channelName, showDate, onPress}: FileInfoProps) => {
const theme = useTheme();
const style = getStyleSheet(theme);
return (
<View style={style.attachmentContainer}>

View File

@@ -25,7 +25,6 @@ type FilesProps = {
isReplyPost: boolean;
postId: string;
publicLinkEnabled: boolean;
theme: Theme;
}
const MAX_VISIBLE_ROW_IMAGES = 4;
@@ -46,7 +45,7 @@ const styles = StyleSheet.create({
},
});
const Files = ({canDownloadFiles, failed, filesInfo, isReplyPost, layoutWidth, location, postId, publicLinkEnabled, theme}: FilesProps) => {
const Files = ({canDownloadFiles, failed, filesInfo, isReplyPost, layoutWidth, location, postId, publicLinkEnabled}: FilesProps) => {
const galleryIdentifier = `${postId}-fileAttachments-${location}`;
const [inViewPort, setInViewPort] = useState(false);
const isTablet = useIsTablet();
@@ -99,7 +98,6 @@ const Files = ({canDownloadFiles, failed, filesInfo, isReplyPost, layoutWidth, l
file={file}
index={attachmentIndex(file.id!)}
onPress={handlePreviewPress}
theme={theme}
isSingleImage={singleImage}
nonVisibleImagesCount={nonVisibleImagesCount}
publicLinkEnabled={publicLinkEnabled}

View File

@@ -4,11 +4,11 @@
import React, {useMemo} from 'react';
import {PixelRatio, StyleSheet, Text, useWindowDimensions, View} from 'react-native';
import {useTheme} from '@context/theme';
import {useIsTablet} from '@hooks/device';
import {makeStyleSheetFromTheme} from '@utils/theme';
type ImageFileOverlayProps = {
theme: Theme;
value: number;
}
@@ -27,9 +27,10 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
},
}));
const ImageFileOverlay = ({theme, value}: ImageFileOverlayProps) => {
const ImageFileOverlay = ({value}: ImageFileOverlayProps) => {
const dimensions = useWindowDimensions();
const isTablet = useIsTablet();
const theme = useTheme();
const style = getStyleSheet(theme);
const textStyles = useMemo(() => {
const scale = isTablet ? dimensions.scale : 1;

View File

@@ -6,6 +6,7 @@ import {StyleProp, View, ViewStyle} from 'react-native';
import FormattedDate from '@components/formatted_date';
import FormattedText from '@components/formatted_text';
import {useTheme} from '@context/theme';
import {isSameYear, isToday, isYesterday} from '@utils/datetime';
import {makeStyleSheetFromTheme} from '@utils/theme';
import {typography} from '@utils/typography';
@@ -13,7 +14,6 @@ import {typography} from '@utils/typography';
type DateSeparatorProps = {
date: number | Date;
style?: StyleProp<ViewStyle>;
theme: Theme;
timezone?: string | null;
};
@@ -72,7 +72,8 @@ const RecentDate = (props: DateSeparatorProps) => {
};
const DateSeparator = (props: DateSeparatorProps) => {
const styles = getStyleSheet(props.theme);
const theme = useTheme();
const styles = getStyleSheet(theme);
return (
<View style={[styles.container, props.style]}>

View File

@@ -178,7 +178,6 @@ const Body = ({
location={location}
post={post}
isReplyPost={isReplyPost}
theme={theme}
/>
}
{hasReactions && showAddReaction &&

View File

@@ -229,7 +229,6 @@ const PostList = ({
return (
<DateSeparator
date={getDateForDateLine(item)}
theme={theme}
style={styles.scale}
timezone={isTimezoneEnabled ? currentTimezone : null}
/>

View File

@@ -145,7 +145,6 @@ const RecentMentionsScreen = ({mentions, currentTimezone, isTimezoneEnabled}: Pr
return (
<DateSeparator
date={getDateForDateLine(item)}
theme={theme}
timezone={isTimezoneEnabled ? currentTimezone : null}
/>
);

View File

@@ -146,7 +146,6 @@ function SavedMessages({posts, currentTimezone, isTimezoneEnabled}: Props) {
return (
<DateSeparator
date={getDateForDateLine(item)}
theme={theme}
timezone={isTimezoneEnabled ? currentTimezone : null}
/>
);

View File

@@ -161,7 +161,6 @@ const SearchResults = ({
return (
<DateSeparator
date={getDateForDateLine(item)}
theme={theme}
timezone={isTimezoneEnabled ? currentTimezone : null}
/>
);
@@ -202,7 +201,6 @@ const SearchResults = ({
index={filesForGalleryIndexes[item.id!] || 0}
onPress={handlePreviewPress}
onOptionsPress={handleOptionsPress}
theme={theme}
isSingleImage={isSingleImage}
showDate={true}
publicLinkEnabled={publicLinkEnabled}

View File

@@ -120,7 +120,6 @@ function SavedMessages({
return (
<DateSeparator
date={getDateForDateLine(item)}
theme={theme}
timezone={isTimezoneEnabled ? currentTimezone : null}
/>
);