Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
fix: add fallbacks for non-web modules
Browse files Browse the repository at this point in the history
closes #95, #96
  • Loading branch information
Ryan Stelly authored and satya164 committed Sep 17, 2019
1 parent 98f0de0 commit b4bbf9b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
9 changes: 9 additions & 0 deletions packages/stack/src/utils/getStatusBarHeight.tsx
Original file line number Diff line number Diff line change
@@ -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;
9 changes: 2 additions & 7 deletions packages/stack/src/views/Header/HeaderBackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 { HeaderLeftButtonProps } from '../../types';

const isMaskedViewAvailable =
// @ts-ignore
UIManager.getViewManagerConfig('RNCMaskedView') != null;

type Props = HeaderLeftButtonProps & {
tintColor: string;
};
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/stack/src/views/Header/HeaderSegment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import {
ViewStyle,
} from 'react-native';
import Animated from 'react-native-reanimated';
import { getStatusBarHeight } from 'react-native-safe-area-view';
import { Route } from '@react-navigation/core';
import HeaderBackButton from './HeaderBackButton';
import HeaderBackground from './HeaderBackground';
import getStatusBarHeight from '../../utils/getStatusBarHeight';
import memoize from '../../utils/memoize';
import {
Layout,
Expand Down
19 changes: 19 additions & 0 deletions packages/stack/src/views/MaskedView.tsx
Original file line number Diff line number Diff line change
@@ -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 changes: 7 additions & 0 deletions packages/stack/src/views/MaskedView.web.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
type Props = {
children: React.ReactElement;
};

export default function MaskedView({ children }: Props) {
return children;
}

0 comments on commit b4bbf9b

Please sign in to comment.