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

Commit

Permalink
fix: use MaskedView from @react-native-community/masked-view
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Aug 18, 2019
1 parent 6e9d05b commit 7772ac5
Showing 1 changed file with 35 additions and 30 deletions.
65 changes: 35 additions & 30 deletions packages/stack/src/views/Header/HeaderBackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,17 @@ import {
Platform,
StyleSheet,
LayoutChangeEvent,
MaskedViewIOS,
UIManager,
} from 'react-native';
import Animated from 'react-native-reanimated';
import MaskedView from '@react-native-community/masked-view';
import TouchableItem from '../TouchableItem';
import { HeaderBackButtonProps } from '../../types';

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

type Props = HeaderBackButtonProps & {
tintColor: string;
};
Expand Down Expand Up @@ -95,33 +100,43 @@ class HeaderBackButton extends React.Component<Props, State> {
}

const labelElement = (
<Animated.Text
accessible={false}
onLayout={
// This measurement is used to determine if we should truncate the label when it doesn't fit
// Only measure it when label is not truncated because we want the measurement of full label
leftLabelText === label ? this.handleLabelLayout : undefined
<View
style={
screenLayout
? // We make the button extend till the middle of the screen
// Otherwise it appears to cut off when translating
[styles.labelWrapper, { minWidth: screenLayout.width / 2 - 27 }]
: null
}
style={[
styles.label,
tintColor ? { color: tintColor } : null,
labelStyle,
]}
numberOfLines={1}
allowFontScaling={!!allowFontScaling}
>
{leftLabelText}
</Animated.Text>
<Animated.Text
accessible={false}
onLayout={
// This measurement is used to determine if we should truncate the label when it doesn't fit
// Only measure it when label is not truncated because we want the measurement of full label
leftLabelText === label ? this.handleLabelLayout : undefined
}
style={[
styles.label,
tintColor ? { color: tintColor } : null,
labelStyle,
]}
numberOfLines={1}
allowFontScaling={!!allowFontScaling}
>
{leftLabelText}
</Animated.Text>
</View>
);

if (backImage || Platform.OS !== 'ios') {
if (!isMaskedViewAvailable || 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;
}

return (
<MaskedViewIOS
<MaskedView
maskElement={
<View style={styles.iconMaskContainer}>
<Image
Expand All @@ -132,18 +147,8 @@ class HeaderBackButton extends React.Component<Props, State> {
</View>
}
>
<View
style={
screenLayout
? // We make the button extend till the middle of the screen
// Otherwise it appears to cut off when translating
[styles.labelWrapper, { minWidth: screenLayout.width / 2 - 27 }]
: null
}
>
{labelElement}
</View>
</MaskedViewIOS>
{labelElement}
</MaskedView>
);
}

Expand Down

0 comments on commit 7772ac5

Please sign in to comment.