question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding example of using native view with Mask

See original GitHub issue

Feature Request

Hi @msand

I just see the new release, Thanks for that. I just wanted to try the new feature, but I didn’t succeed so I should misusing it.

It would be great if you add an example to Mask section in ReadMe.md file.

Why it is needed

It helps users to understand how it should be used, like the other examples.

Code sample

here is what I tried

https://snack.expo.io/@saeedzhiany/using-native-view-with-mask

import React from 'react';
import {View, Image, Text} from 'react-native';
import {
  Svg,
  G,
  Circle,
  Defs,
  LinearGradient,
  Mask,
  Rect,
  Stop,
} from 'react-native-svg';

export default () => {
  return (
    <View style={{flex: 1, justifyContent: 'center'}}>
      <Svg height="50%">
        <Defs>
          <LinearGradient
            id="Gradient"
            gradientUnits="userSpaceOnUse"
            x1="0"
            y1="0"
            x2="800"
            y2="0">
            <Stop offset="0" stopColor="white" stopOpacity="0" />
            <Stop offset="1" stopColor="white" stopOpacity="1" />
          </LinearGradient>
          <Mask
            id="Mask"
            maskUnits="userSpaceOnUse"
            x='0'
            y='0'
            width="800"
            height="300">
            <Rect x="0" y="0" width="800" height="300" fill="url(#Gradient)" />
          </Mask>
        </Defs>
        <G mask="url(#Mask)">
          <Circle x={50} y={70} r={65} />
          <G transform="translate(200, 100)">
            <Text>Some Text</Text>
          </G>
        </G>
      </Svg>
    </View>
  );
};

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:17 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
SaeedZhianycommented, Jan 5, 2020

Oh, I wonder what makes that happen, I guess it calls render on the element more than once, or then react-native / the os calls render on it independently of the code here.

What about Android’s result? it seems the nested Text within SVG is disappeared (or even not rendered) however, I’ll test it on my project tomorrow, maybe it because of the library’s version on expo as you said.

Also, Thanks for your guidance.

1reaction
msandcommented, Jan 6, 2020

Ah, yeah that’s correct

Read more comments on GitHub >

github_iconTop Results From Across the Web

The 5 Minute React Native Masked View - YouTube
In this video, we are building an angular gradient in React Native using a masked view.Hope you enjoy it Wanna learn the fundamentals...
Read more >
React Native Masked View Library - GitHub
The following image demonstrates that you can put almost anything behind the mask. The three examples shown are masked <View> , <Text> ,...
Read more >
Mask UI Elements in React Native With React ... - Egghead.io
A masked view is view which only displays the pixels that overlap with the view rendered in its mask element. This can be...
Read more >
Using input masks in React Native - LogRocket Blog
Implement input masks in React Native to develop user-friendly input constraints such as entering data according to a pre-defined format.
Read more >
MaskedView - Expo Documentation
@react-native-masked-view/masked-view provides a masked view which only displays the pixels that overlap with the view rendered in its mask element.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found