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

Commit 8a4d44e

Browse files
committed
fix: use MaskedView from @react-native-community/masked-view
1 parent 04421cd commit 8a4d44e

File tree

6 files changed

+50
-30
lines changed

6 files changed

+50
-30
lines changed

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"ios": "expo start --ios"
1010
},
1111
"dependencies": {
12+
"@react-native-community/masked-view": "^0.1.1",
1213
"@react-navigation/core": "3.4.2",
1314
"@react-navigation/native": "^3.4.1",
1415
"expo": "^33.0.7",

example/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,11 @@
894894
xcode "^2.0.0"
895895
xmldoc "^0.4.0"
896896

897+
"@react-native-community/masked-view@^0.1.1":
898+
version "0.1.1"
899+
resolved "https://registry.yarnpkg.com/@react-native-community/masked-view/-/masked-view-0.1.1.tgz#dbcfc5ec08efbb02d4142dd9426c8d7a396829d7"
900+
integrity sha512-EyJVSbarZkOPYq+zCZLx9apMcpwkX9HvH6R+6CeVL29q88kEFemnLO/IhmE4YX/0MfalsduI8eTi7fuQh/5VeA==
901+
897902
"@react-native-community/netinfo@2.0.10":
898903
version "2.0.10"
899904
resolved "https://registry.yarnpkg.com/@react-native-community/netinfo/-/netinfo-2.0.10.tgz#d28a446352e75754b78509557988359133cdbcca"

jest-setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/* eslint-env jest */
22

3+
jest.mock('@react-native-community/masked-view', () => () => null);
4+
35
jest.mock('react-native-gesture-handler', () => ({
46
PanGestureHandler: 'PanGestureHandler',
57
BaseButton: 'BaseButton',

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@commitlint/config-conventional": "^8.0.0",
5050
"@expo/vector-icons": "^10.0.3",
5151
"@react-native-community/bob": "^0.6.1",
52+
"@react-native-community/masked-view": "^0.1.1",
5253
"@react-navigation/core": "^3.4.2",
5354
"@react-navigation/native": "^3.5.0",
5455
"@release-it/conventional-changelog": "^1.1.0",
@@ -75,6 +76,7 @@
7576
"typescript": "^3.5.2"
7677
},
7778
"peerDependencies": {
79+
"@react-native-community/masked-view": "^0.1.1",
7880
"@react-navigation/core": "^3.0.0",
7981
"react": "*",
8082
"react-native": "*",

src/views/Header/HeaderBackButton.tsx

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ import {
66
Platform,
77
StyleSheet,
88
LayoutChangeEvent,
9-
MaskedViewIOS,
9+
UIManager,
1010
} from 'react-native';
1111
import Animated from 'react-native-reanimated';
12+
import MaskedView from '@react-native-community/masked-view';
1213
import TouchableItem from '../TouchableItem';
1314
import { HeaderBackButtonProps } from '../../types';
1415

16+
const isMaskedViewAvailable =
17+
// @ts-ignore
18+
UIManager.getViewManagerConfig('RNCMaskedView') != null;
19+
1520
type Props = HeaderBackButtonProps & {
1621
tintColor: string;
1722
};
@@ -95,33 +100,43 @@ class HeaderBackButton extends React.Component<Props, State> {
95100
}
96101

97102
const labelElement = (
98-
<Animated.Text
99-
accessible={false}
100-
onLayout={
101-
// This measurement is used to determine if we should truncate the label when it doesn't fit
102-
// Only measure it when label is not truncated because we want the measurement of full label
103-
leftLabelText === label ? this.handleLabelLayout : undefined
103+
<View
104+
style={
105+
screenLayout
106+
? // We make the button extend till the middle of the screen
107+
// Otherwise it appears to cut off when translating
108+
[styles.labelWrapper, { minWidth: screenLayout.width / 2 - 27 }]
109+
: null
104110
}
105-
style={[
106-
styles.label,
107-
tintColor ? { color: tintColor } : null,
108-
labelStyle,
109-
]}
110-
numberOfLines={1}
111-
allowFontScaling={!!allowFontScaling}
112111
>
113-
{leftLabelText}
114-
</Animated.Text>
112+
<Animated.Text
113+
accessible={false}
114+
onLayout={
115+
// This measurement is used to determine if we should truncate the label when it doesn't fit
116+
// Only measure it when label is not truncated because we want the measurement of full label
117+
leftLabelText === label ? this.handleLabelLayout : undefined
118+
}
119+
style={[
120+
styles.label,
121+
tintColor ? { color: tintColor } : null,
122+
labelStyle,
123+
]}
124+
numberOfLines={1}
125+
allowFontScaling={!!allowFontScaling}
126+
>
127+
{leftLabelText}
128+
</Animated.Text>
129+
</View>
115130
);
116131

117-
if (backImage || Platform.OS !== 'ios') {
132+
if (!isMaskedViewAvailable || backImage || Platform.OS !== 'ios') {
118133
// When a custom backimage is specified, we can't mask the label
119134
// Otherwise there might be weird effect due to our mask not being the same as the image
120135
return labelElement;
121136
}
122137

123138
return (
124-
<MaskedViewIOS
139+
<MaskedView
125140
maskElement={
126141
<View style={styles.iconMaskContainer}>
127142
<Image
@@ -132,18 +147,8 @@ class HeaderBackButton extends React.Component<Props, State> {
132147
</View>
133148
}
134149
>
135-
<View
136-
style={
137-
screenLayout
138-
? // We make the button extend till the middle of the screen
139-
// Otherwise it appears to cut off when translating
140-
[styles.labelWrapper, { minWidth: screenLayout.width / 2 - 27 }]
141-
: null
142-
}
143-
>
144-
{labelElement}
145-
</View>
146-
</MaskedViewIOS>
150+
{labelElement}
151+
</MaskedView>
147152
);
148153
}
149154

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,6 +1150,11 @@
11501150
xcode "^2.0.0"
11511151
xmldoc "^0.4.0"
11521152

1153+
"@react-native-community/masked-view@^0.1.1":
1154+
version "0.1.1"
1155+
resolved "https://registry.yarnpkg.com/@react-native-community/masked-view/-/masked-view-0.1.1.tgz#dbcfc5ec08efbb02d4142dd9426c8d7a396829d7"
1156+
integrity sha512-EyJVSbarZkOPYq+zCZLx9apMcpwkX9HvH6R+6CeVL29q88kEFemnLO/IhmE4YX/0MfalsduI8eTi7fuQh/5VeA==
1157+
11531158
"@react-navigation/core@^3.4.2":
11541159
version "3.4.2"
11551160
resolved "https://registry.yarnpkg.com/@react-navigation/core/-/core-3.4.2.tgz#bec563e94fde40fbab3730cdc97f22afbb2a1498"

0 commit comments

Comments
 (0)