Skip to content

Commit 3df65e2

Browse files
committed
fix: initialize height and width to zero if undefined
closes facebook#6789
1 parent 5c4afc5 commit 3df65e2

File tree

3 files changed

+30
-20
lines changed

3 files changed

+30
-20
lines changed

packages/bottom-tabs/src/views/BottomTabBar.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,12 @@ export default function BottomTabBar({
5151
}: Props) {
5252
const { colors } = useTheme();
5353

54-
const [dimensions, setDimensions] = React.useState(Dimensions.get('window'));
54+
const [dimensions, setDimensions] = React.useState(() => {
55+
const { height = 0, width = 0 } = Dimensions.get('window');
56+
57+
return { height, width };
58+
});
59+
5560
const [layout, setLayout] = React.useState({
5661
height: 0,
5762
width: dimensions.width,

packages/drawer/src/views/DrawerView.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ export default function DrawerView({
8989
sceneContainerStyle,
9090
}: Props) {
9191
const [loaded, setLoaded] = React.useState([state.index]);
92-
const [drawerWidth, setDrawerWidth] = React.useState(() =>
93-
getDefaultDrawerWidth(Dimensions.get('window'))
94-
);
92+
const [drawerWidth, setDrawerWidth] = React.useState(() => {
93+
const { height = 0, width = 0 } = Dimensions.get('window');
94+
95+
return getDefaultDrawerWidth({ height, width });
96+
});
9597

9698
const drawerGestureRef = React.useRef<PanGestureHandler>(null);
9799

packages/stack/src/views/Stack/CardStack.tsx

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,6 @@ type State = {
7575

7676
const EPSILON = 0.01;
7777

78-
const dimensions = Dimensions.get('window');
79-
const layout = { width: dimensions.width, height: dimensions.height };
80-
8178
const MaybeScreenContainer = ({
8279
enabled,
8380
...rest
@@ -299,19 +296,25 @@ export default class CardStack extends React.Component<Props, State> {
299296
};
300297
}
301298

302-
state: State = {
303-
routes: [],
304-
scenes: [],
305-
gestures: {},
306-
layout,
307-
descriptors: this.props.descriptors,
308-
// Used when card's header is null and mode is float to make transition
309-
// between screens with headers and those without headers smooth.
310-
// This is not a great heuristic here. We don't know synchronously
311-
// on mount what the header height is so we have just used the most
312-
// common cases here.
313-
headerHeights: {},
314-
};
299+
constructor(props: Props) {
300+
super(props);
301+
302+
const { height = 0, width = 0 } = Dimensions.get('window');
303+
304+
this.state = {
305+
routes: [],
306+
scenes: [],
307+
gestures: {},
308+
layout: { height, width },
309+
descriptors: this.props.descriptors,
310+
// Used when card's header is null and mode is float to make transition
311+
// between screens with headers and those without headers smooth.
312+
// This is not a great heuristic here. We don't know synchronously
313+
// on mount what the header height is so we have just used the most
314+
// common cases here.
315+
headerHeights: {},
316+
};
317+
}
315318

316319
private handleLayout = (e: LayoutChangeEvent) => {
317320
const { height, width } = e.nativeEvent.layout;

0 commit comments

Comments
 (0)