mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-26 23:06:03 +08:00
fix: drop usage of Dimensions in favor of metrics from safe-area-context
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import * as React from 'react';
|
||||
import { Platform } from 'react-native';
|
||||
import { Dimensions, Platform } from 'react-native';
|
||||
import {
|
||||
SafeAreaProvider,
|
||||
SafeAreaInsetsContext,
|
||||
@@ -10,13 +10,15 @@ type Props = {
|
||||
children: React.ReactNode;
|
||||
};
|
||||
|
||||
const frame = Dimensions.get('window');
|
||||
|
||||
// To support SSR on web, we need to have empty insets for initial values
|
||||
// Otherwise there can be mismatch between SSR and client output
|
||||
// We also need to specify empty values to support tests environments
|
||||
const initialMetrics =
|
||||
export const initialMetrics =
|
||||
Platform.OS === 'web' || initialWindowMetrics == null
|
||||
? {
|
||||
frame: { x: 0, y: 0, width: 0, height: 0 },
|
||||
frame: { x: 0, y: 0, width: frame.width, height: frame.height },
|
||||
insets: { top: 0, left: 0, right: 0, bottom: 0 },
|
||||
}
|
||||
: initialWindowMetrics;
|
||||
|
||||
@@ -3,7 +3,6 @@ import {
|
||||
Animated,
|
||||
StyleSheet,
|
||||
LayoutChangeEvent,
|
||||
Dimensions,
|
||||
Platform,
|
||||
} from 'react-native';
|
||||
import type { EdgeInsets } from 'react-native-safe-area-context';
|
||||
@@ -18,6 +17,7 @@ import {
|
||||
MaybeScreen,
|
||||
shouldUseActivityState,
|
||||
} from '../Screens';
|
||||
import { initialMetrics } from '../SafeAreaProviderCompat';
|
||||
import { getDefaultHeaderHeight } from '../Header/HeaderSegment';
|
||||
import type { Props as HeaderContainerProps } from '../Header/HeaderContainer';
|
||||
import CardContainer from './CardContainer';
|
||||
@@ -286,13 +286,11 @@ export default class CardStack extends React.Component<Props, State> {
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
|
||||
const { height = 0, width = 0 } = Dimensions.get('window');
|
||||
|
||||
this.state = {
|
||||
routes: [],
|
||||
scenes: [],
|
||||
gestures: {},
|
||||
layout: { height, width },
|
||||
layout: initialMetrics.frame,
|
||||
descriptors: this.props.descriptors,
|
||||
// Used when card's header is null and mode is float to make transition
|
||||
// between screens with headers and those without headers smooth.
|
||||
|
||||
Reference in New Issue
Block a user