MaskedView
Reveal children through the alpha channel of a mask.
App.tsx
<MaskedView maskElement={ <Text fontSize={44}> Alps </Text> }> <Image image={landscape} layout={{ flex: 1 }} /></MaskedView>Postcard
Alps
Pass the mask as maskElement and place the content you want to reveal inside MaskedView. In this example the word “Spring” takes its color from the green view behind it.
import { MaskedView, Text, View } from 'react-nitro-renderer'
export function SpringTitle() {
return (
<MaskedView layout={{ width: 160, height: 48 }} maskElement={<Text fontSize={32}>Spring</Text>}>
<View layout={{ flex: 1 }} style={{ background: 0x34753aff }} />
</MaskedView>
)
}The mask fills the container independently of the content's layout. Transparent pixels hide the content, opaque pixels reveal it, and intermediate alpha values reveal it partially. A black mask and a white mask with the same opacity reveal the same pixels. An empty mask hides all the content.
The wrapper positions the mask above the content and disables touch handling on the mask layer. To supply those layers directly, use NativeMaskedView.
Reveal an image through text
Give the container dimensions so the image and the text mask occupy the same area.
import { Image, MaskedView, Text } from 'react-nitro-renderer'
import crocus from './assets/crocus.jpg'
export function PhotoTitle() {
return (
<MaskedView
layout={{ width: 220, height: 60 }}
maskElement={<Text fontSize={44} fontWeight="bold">Spring</Text>}
>
<Image image={crocus} resizeMode="cover" layout={{ flex: 1 }} />
</MaskedView>
)
}