mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-03-27 22:56:07 +08:00
fix: add fallbacks for non-web modules
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { I18nManager } from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
import getStatusBarHeight from '../utils/getStatusBarHeight';
|
||||
import { CardInterpolationProps, CardInterpolatedStyle } from '../types';
|
||||
import { getStatusBarHeight } from 'react-native-safe-area-view';
|
||||
|
||||
const { cond, add, multiply, interpolate } = Animated;
|
||||
|
||||
|
||||
9
packages/stack/src/utils/getStatusBarHeight.tsx
Normal file
9
packages/stack/src/utils/getStatusBarHeight.tsx
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Platform } from 'react-native';
|
||||
import { getStatusBarHeight as getStatusBarHeightNative } from 'react-native-safe-area-view';
|
||||
|
||||
const getStatusBarHeight = Platform.select({
|
||||
default: getStatusBarHeightNative,
|
||||
web: () => 0,
|
||||
});
|
||||
|
||||
export default getStatusBarHeight;
|
||||
@@ -6,17 +6,12 @@ import {
|
||||
Platform,
|
||||
StyleSheet,
|
||||
LayoutChangeEvent,
|
||||
UIManager,
|
||||
} from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
import MaskedView from '@react-native-community/masked-view';
|
||||
import MaskedView from '../MaskedView';
|
||||
import TouchableItem from '../TouchableItem';
|
||||
import { HeaderBackButtonProps } from '../../types';
|
||||
|
||||
const isMaskedViewAvailable =
|
||||
// @ts-ignore
|
||||
UIManager.getViewManagerConfig('RNCMaskedView') != null;
|
||||
|
||||
type Props = HeaderBackButtonProps & {
|
||||
tintColor: string;
|
||||
};
|
||||
@@ -129,7 +124,7 @@ class HeaderBackButton extends React.Component<Props, State> {
|
||||
</View>
|
||||
);
|
||||
|
||||
if (!isMaskedViewAvailable || backImage || Platform.OS !== 'ios') {
|
||||
if (backImage || Platform.OS !== 'ios') {
|
||||
// When a custom backimage is specified, we can't mask the label
|
||||
// Otherwise there might be weird effect due to our mask not being the same as the image
|
||||
return labelElement;
|
||||
|
||||
@@ -7,9 +7,9 @@ import {
|
||||
ViewStyle,
|
||||
} from 'react-native';
|
||||
import Animated from 'react-native-reanimated';
|
||||
import { getStatusBarHeight } from 'react-native-safe-area-view';
|
||||
import HeaderBackButton from './HeaderBackButton';
|
||||
import HeaderBackground from './HeaderBackground';
|
||||
import getStatusBarHeight from '../../utils/getStatusBarHeight';
|
||||
import memoize from '../../utils/memoize';
|
||||
import {
|
||||
Layout,
|
||||
|
||||
19
packages/stack/src/views/MaskedView.tsx
Normal file
19
packages/stack/src/views/MaskedView.tsx
Normal file
@@ -0,0 +1,19 @@
|
||||
import * as React from 'react';
|
||||
import { UIManager } from 'react-native';
|
||||
import RNCMaskedView from '@react-native-community/masked-view';
|
||||
|
||||
type Props = React.ComponentProps<typeof RNCMaskedView> & {
|
||||
children: React.ReactElement;
|
||||
};
|
||||
|
||||
const isMaskedViewAvailable =
|
||||
// @ts-ignore
|
||||
UIManager.getViewManagerConfig('RNCMaskedView') != null;
|
||||
|
||||
export default function MaskedView({ children, ...rest }: Props) {
|
||||
if (isMaskedViewAvailable) {
|
||||
return <RNCMaskedView {...rest}>{children}</RNCMaskedView>;
|
||||
}
|
||||
|
||||
return children;
|
||||
}
|
||||
7
packages/stack/src/views/MaskedView.web.tsx
Normal file
7
packages/stack/src/views/MaskedView.web.tsx
Normal file
@@ -0,0 +1,7 @@
|
||||
type Props = {
|
||||
children: React.ReactElement;
|
||||
};
|
||||
|
||||
export default function MaskedView({ children }: Props) {
|
||||
return children;
|
||||
}
|
||||
Reference in New Issue
Block a user