Coder Social home page Coder Social logo

masked-view's Introduction

React Native MaskedView

Build Status Version MIT License Lean Core Badge

Provides a React component that renders a masked view.

Platforms Supported

  • iOS
  • Android
  • Web

Getting Started

yarn add @react-native-masked-view/masked-view

or

npm install --save @react-native-masked-view/masked-view

Using React Native >= 0.60

Linking the package manually is not required anymore with Autolinking.

Remember to install the pod with:

npx pod-install

Using React Native < 0.60

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

Usage

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';

const App = () => {
  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>
  );
}

export default App

The following image demonstrates that you can put almost anything behind the mask. The three examples shown are masked <View>, <Text>, and <Image>.

Props

Reference

maskElement

Type Required
element Yes

androidRenderingMode

By default hardware rendering mode will be used for best performance, however if you need to animate your maskElement then you’ll need to switch to software to get your mask to update. This prop only affects Android.

Type Required Default
software, hardware No hardware

masked-view's People

Contributors

fondorn avatar dependabot[bot] avatar naturalclar avatar ngocle2497 avatar cpojer avatar xzilja avatar iljadaderko avatar aleksandrchernyavenko avatar dulmandakh avatar johgusta avatar lrnz09 avatar reime005 avatar matt-oakes avatar alpha0010 avatar andresribeiro avatar simek avatar campbellmg avatar evanbacon avatar gabrieldonadel avatar someonewithpc avatar keshavkaul avatar k-ibr avatar levibuzolic avatar fetten avatar matteodanelli avatar hexadecy avatar tdekoning avatar tobiasehlert avatar tkow avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.