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 broken windows #8406

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
41 changes: 19 additions & 22 deletions app/screens/gallery/video_renderer/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,23 @@

import {Image} from 'expo-image';
import React, {type Dispatch, type SetStateAction, useCallback, useState} from 'react';
import {StyleSheet, Text, useWindowDimensions, View} from 'react-native';
import {RectButton, TouchableWithoutFeedback} from 'react-native-gesture-handler';
import {useIntl} from 'react-intl';
import {StyleSheet, Text, TouchableWithoutFeedback, useWindowDimensions, View} from 'react-native';
import Animated from 'react-native-reanimated';

import Button from '@components/button';
import CompassIcon from '@components/compass_icon';
import FormattedText from '@components/formatted_text';
import {Preferences} from '@constants';
import {buttonBackgroundStyle, buttonTextStyle} from '@utils/buttonStyles';
import {calculateDimensions} from '@utils/images';
import {changeOpacity} from '@utils/theme';
import {typography} from '@utils/typography';

const styles = StyleSheet.create({
container: {
alignItems: 'center',
justifyContent: 'center',
flex: 1,
maxWidth: 600,
},
filename: {
color: '#FFF',
Expand Down Expand Up @@ -59,10 +58,12 @@ type Props = {
const VideoError = ({filename, height, isDownloading, isRemote, onShouldHideControls, posterUri, setDownloading, width}: Props) => {
const [hasPoster, setHasPoster] = useState(false);
const [loadPosterError, setLoadPosterError] = useState(false);
const dimensions = useWindowDimensions();
const intl = useIntl();

const handleDownload = useCallback(() => {
setDownloading(true);
}, []);
}, [setDownloading]);

const handlePosterSet = useCallback(() => {
setHasPoster(true);
Expand All @@ -72,11 +73,9 @@ const VideoError = ({filename, height, isDownloading, isRemote, onShouldHideCont
setLoadPosterError(true);
}, []);

const dimensions = useWindowDimensions();
const imageDimensions = calculateDimensions(height, width, dimensions.width);

let poster;
if (posterUri && !loadPosterError) {
const imageDimensions = calculateDimensions(height, width, dimensions.width);
poster = (
<Image
source={{uri: posterUri}}
Expand All @@ -96,7 +95,10 @@ const VideoError = ({filename, height, isDownloading, isRemote, onShouldHideCont
}

return (
<TouchableWithoutFeedback onPress={onShouldHideControls}>
<TouchableWithoutFeedback
onPress={onShouldHideControls}
style={styles.container}
>
<Animated.View style={styles.container}>
{poster}
<Text
Expand All @@ -114,20 +116,15 @@ const VideoError = ({filename, height, isDownloading, isRemote, onShouldHideCont
style={styles.unsupported}
/>
</View>
<RectButton
enabled={!isDownloading}
exclusive={true}
<Button
disabled={isDownloading}
onPress={handleDownload}
rippleColor={changeOpacity('#fff', 0.16)}
>
<View style={buttonBackgroundStyle(Preferences.THEMES.onyx, 'lg', 'primary', isDownloading ? 'disabled' : 'default')}>
<FormattedText
defaultMessage='Download'
id='video.download'
style={buttonTextStyle(Preferences.THEMES.onyx, 'lg', 'primary', isDownloading ? 'disabled' : 'default')}
/>
</View>
</RectButton>
theme={Preferences.THEMES.onyx}
size={'lg'}
textStyle={buttonTextStyle(Preferences.THEMES.onyx, 'lg', 'primary', isDownloading ? 'disabled' : 'default')}
text={intl.formatMessage({id: 'video.download', defaultMessage: 'Download video'})}
backgroundStyle={buttonBackgroundStyle(Preferences.THEMES.onyx, 'lg', 'primary', isDownloading ? 'disabled' : 'default')}
/>
</View>
}
{!isRemote &&
Expand Down
8 changes: 2 additions & 6 deletions app/screens/gallery/video_renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,15 @@ const VideoRenderer = ({height, index, initialIndex, item, isPageActive, onShoul
const w = width;
const h = height - (VIDEO_INSET + GALLERY_FOOTER_HEIGHT + bottom);

if (hasError) {
return {height: 0, width: 0};
}

return {width: w, height: h};
}, [hasError, fullscreen.value, height, width]);
}, [width, height, bottom]);

const animatedStyle = useAnimatedStyle(() => {
return {
width: withTiming(dimensionsStyle.width, timingConfig),
height: withTiming(dimensionsStyle.height, timingConfig),
};
}, [dimensionsStyle, hasError]);
}, [dimensionsStyle]);

useEffect(() => {
if (initialIndex === index && videoReady) {
Expand Down
4 changes: 2 additions & 2 deletions app/screens/share_feedback/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ const ShareFeedback = ({
emphasis={'tertiary'}
onPress={onPressNo}
text={intl.formatMessage({id: 'share_feedback.button.no', defaultMessage: 'No, thanks'})}
backgroundStyle={styles.leftButton}
buttonContainerStyle={styles.leftButton}
/>
<Button
theme={theme}
size={'lg'}
onPress={onPressYes}
text={intl.formatMessage({id: 'share_feedback.button.yes', defaultMessage: 'Yes'})}
backgroundStyle={styles.rightButton}
buttonContainerStyle={styles.rightButton}
/>
</View>
</View>
Expand Down
10 changes: 4 additions & 6 deletions app/utils/images/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Dimensions} from 'react-native';
import RNUtils from '@mattermost/rnutils';

import {IMAGE_MAX_HEIGHT} from '@constants/image';

Expand All @@ -11,10 +11,8 @@ import {
isGifTooLarge,
} from './index';

jest.mock('react-native', () => ({
Dimensions: {
get: jest.fn(() => ({width: 800, height: 600})),
},
jest.mock('@mattermost/rnutils', () => ({
getWindowDimensions: jest.fn(() => ({width: 800, height: 600})),
}));

jest.mock('@constants/image', () => ({
Expand Down Expand Up @@ -100,7 +98,7 @@ describe('calculateDimensions', () => {

describe('getViewPortWidth', () => {
beforeEach(() => {
(Dimensions.get as jest.Mock).mockReturnValue({width: 800, height: 600});
(RNUtils.getWindowDimensions as jest.Mock).mockReturnValue({width: 800, height: 600});
});

it('should calculate viewport width for normal post', () => {
Expand Down
4 changes: 2 additions & 2 deletions app/utils/images/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {Dimensions} from 'react-native';
import RNUtils from '@mattermost/rnutils';

import {View} from '@constants';
import {
Expand Down Expand Up @@ -55,7 +55,7 @@ export const calculateDimensions = (height?: number, width?: number, viewPortWid
};

export function getViewPortWidth(isReplyPost: boolean, tabletOffset = false, imageAttachmentOffset = false) {
const {width, height} = Dimensions.get('window');
const {width, height} = RNUtils.getWindowDimensions();
let portraitPostWidth = Math.min(width, height) - VIEWPORT_IMAGE_OFFSET;

if (tabletOffset) {
Expand Down