Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
@react-native-masked-view/masked-view
Advanced tools
@react-native-masked-view/masked-view is a React Native component that allows you to create masked views. This means you can define a mask that determines which parts of a child view are visible, enabling you to create complex visual effects.
Basic Masked View
This example demonstrates a basic masked view where the text 'Masked Text' acts as the mask. The blue background is only visible through the text.
import React from 'react';
import { View, Text } from 'react-native';
import MaskedView from '@react-native-masked-view/masked-view';
const BasicMaskedView = () => (
<MaskedView
style={{ flex: 1 }}
maskElement={
<View
style={{
backgroundColor: 'transparent',
justifyContent: 'center',
alignItems: 'center',
}}
>
<Text
style={{
fontSize: 60,
color: 'black',
fontWeight: 'bold',
}}
>
Masked Text
</Text>
</View>
}
>
<View style={{ flex: 1, backgroundColor: 'blue' }} />
</MaskedView>
);
export default BasicMaskedView;
Gradient Mask
This example shows how to use a gradient as a mask. The red background is gradually revealed through the gradient mask.
import React from 'react';
import { View, Text } from 'react-native';
import MaskedView from '@react-native-masked-view/masked-view';
import LinearGradient from 'react-native-linear-gradient';
const GradientMaskedView = () => (
<MaskedView
style={{ flex: 1 }}
maskElement={
<LinearGradient
colors={['transparent', 'black']}
style={{ flex: 1 }}
/>
}
>
<View style={{ flex: 1, backgroundColor: 'red' }} />
</MaskedView>
);
export default GradientMaskedView;
react-native-svg provides SVG support to React Native. It allows you to create complex shapes and masks using SVG elements. Compared to @react-native-masked-view/masked-view, react-native-svg offers more flexibility and control over vector graphics but may require more effort to achieve similar masking effects.
react-native-linear-gradient allows you to create linear gradients in your React Native applications. While it doesn't provide masking capabilities directly, it can be used in conjunction with @react-native-masked-view/masked-view to create gradient masks. It is more specialized in creating gradient backgrounds and overlays.
React Native MaskedView for iOS and Android.
$ yarn add @react-native-masked-view/masked-view
or
$ npm install --save @react-native-masked-view/masked-view
Linking the package manually is not required anymore with Autolinking.
iOS Platform:
$ npx pod-install
You then need to link the native parts of the library for the platforms you are using. The easiest way to link the library is using the CLI tool by running this command from the root of your project:
$ react-native link @react-native-masked-view/masked-view
Import the MaskedView
component from @react-native-masked-view/masked-view
and use it like so:
import React from 'react';
import { Text, View } from 'react-native';
import MaskedView from '@react-native-masked-view/masked-view';
export default class App extends React.Component {
render() {
return (
<MaskedView
style={{ flex: 1, flexDirection: 'row', height: '100%' }}
maskElement={
<View
style={{
// Transparent background because mask is based off alpha channel.
backgroundColor: 'transparent',
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}
>
<Text
style={{
fontSize: 60,
color: 'black',
fontWeight: 'bold',
}}
>
Basic Mask
</Text>
</View>
}
>
{/* Shows behind the mask, you can put anything here, such as an image */}
<View style={{ flex: 1, height: '100%', backgroundColor: '#324376' }} />
<View style={{ flex: 1, height: '100%', backgroundColor: '#F5DD90' }} />
<View style={{ flex: 1, height: '100%', backgroundColor: '#F76C5E' }} />
<View style={{ flex: 1, height: '100%', backgroundColor: '#e1e1e1' }} />
</MaskedView>
);
}
}
The following image demonstrates that you can put almost anything behind the mask. The three examples shown are masked <View>
, <Text>
, and <Image>
.
maskElement
Type | Required |
---|---|
element | Yes |
FAQs
React Native MaskedView component
We found that @react-native-masked-view/masked-view demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.