Skip to content

Commit 9f1afb6

Browse files
chrisbobbegnprice
authored andcommitted
Lightbox: Use 100% width/height instead of window dimensions
In theory this could help prevent jank, if it ever takes a frame or two for the orientation-change event to come over the React Native bridge. The idea came from work on the offline notice's new layout: #5491 (comment) …Ah, in theory, but also in practice, too! See Greg's report of observing some actual jank on Android that this fixes: #5566 (review) Greg also points out a theoretical bug that would be worse, and that's fixed by taking Redux and RN's Dimensions API out of the picture: with the old code, it would seem possible to get into a persistent state where the layout is confused between portrait and landscape dimensions: #5566 (comment)
1 parent 1d50173 commit 9f1afb6

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

src/lightbox/Lightbox.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import React, { useState, useCallback } from 'react';
44
import type { Node } from 'react';
5-
import { View, Dimensions, LayoutAnimation } from 'react-native';
5+
import { View, LayoutAnimation } from 'react-native';
66
// $FlowFixMe[untyped-import]
77
import PhotoView from 'react-native-photo-view';
88
// $FlowFixMe[untyped-import]
99
import { useActionSheet } from '@expo/react-native-action-sheet';
1010

1111
import type { Message } from '../types';
12-
import { useGlobalSelector, useSelector } from '../react-redux';
12+
import { useSelector } from '../react-redux';
1313
import type { ShowActionSheetWithOptions } from '../action-sheets';
14-
import { getAuth, getGlobalSession } from '../selectors';
14+
import { getAuth } from '../selectors';
1515
import { isUrlOnRealm } from '../utils/url';
1616
import LightboxHeader from './LightboxHeader';
1717
import LightboxFooter from './LightboxFooter';
@@ -51,12 +51,6 @@ export default function Lightbox(props: Props): Node {
5151
? `Shared in #${streamNameOfStreamMessage(message)}`
5252
: 'Shared with you';
5353

54-
// Since we're using `Dimensions.get` (below), we'll want a rerender
55-
// when the orientation changes. No need to store the value.
56-
useGlobalSelector(state => getGlobalSession(state).orientation);
57-
58-
const { width: windowWidth, height: windowHeight } = Dimensions.get('window');
59-
6054
const styles = React.useMemo(
6155
() =>
6256
createStyleSheet({
@@ -68,23 +62,23 @@ export default function Lightbox(props: Props): Node {
6862
backgroundColor: 'black',
6963
opacity: 0.8,
7064
position: 'absolute',
71-
width: windowWidth,
72-
...(headerFooterVisible ? { top: 0 } : { bottom: windowHeight }),
65+
width: '100%',
66+
...(headerFooterVisible ? { top: 0 } : { bottom: '100%' }),
7367
},
7468
footer: {
7569
backgroundColor: 'black',
7670
opacity: 0.8,
7771
position: 'absolute',
78-
width: windowWidth,
79-
...(headerFooterVisible ? { bottom: 0 } : { top: windowHeight }),
72+
width: '100%',
73+
...(headerFooterVisible ? { bottom: 0 } : { top: '100%' }),
8074
},
8175
container: {
8276
flex: 1,
8377
justifyContent: 'space-between',
8478
alignItems: 'center',
8579
},
8680
}),
87-
[headerFooterVisible, windowWidth, windowHeight],
81+
[headerFooterVisible],
8882
);
8983

9084
return (
@@ -98,7 +92,7 @@ export default function Lightbox(props: Props): Node {
9892
? { uri: src.toString(), headers: getAuthHeaders(auth) }
9993
: { uri: src.toString() }
10094
}
101-
style={[styles.img, { width: windowWidth }]}
95+
style={[styles.img, { width: '100%' }]}
10296
// Doesn't seem to do anything on iOS:
10397
// https://github.com/alwx/react-native-photo-view/issues/62
10498
// https://github.com/alwx/react-native-photo-view/issues/98

0 commit comments

Comments
 (0)