0.3.1 • Published 5 years ago

react-native-clipped v0.3.1

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

react-native-clipped

Work in progress - Go away

Clipping effects and animations for react-native 🍠🥒🍕

Try it with Expo

MagicMoveGif

Usage

Installation

$ yarn add react-native-clipped
import * as Clipped from 'react-native-clipped';

// Show a component using a cliping effect
<Clipped.View animation='clipLeft'>
  <Text>Hi there</Text>
</Clipped.View>

// Hide a component using a slide effect
<Clipped.View animation='slideUp' hide>
  <Text>Aloha</Text>
</Clipped.View>

// Clip a view to display only the right 50% of the content
<Clipped.View left={0.5}>
  <Text>Hi there</Text>
</Clipped.View>

Documentation

Clipped.View

The Clipped.View is the top-level interface for most of your clipping needs. It wraps a single child and applies clipping effects or show/hide animations. Under the hood, it uses one or more Fragments to display its content.

Clipping Props

The clipping props can be used to clip one or more sides of the view. E.g. to show only the right 50% of the view, set the left prop to 0.5. These props also accept an Animated.Value, so that it's possible to build larger compound clipping effects or bind it to gestures.

PropertyTypeDefaultDescription
leftnumber | Animated.Value0Clips the left part of the view (0..1)
rightnumber | Animated.Value0Clips the right part of the view (0..1)
topnumber | Animated.Value0Clips the top part of the view (0..1)
bottomnumber | Animated.Value0Clips the bottom part of the view (0..1)
debugbooleanEnables debug mode and displays the underlying clipping layers

Animation Props

The animation props make it possible to easily show or hide contents using a clipping animation. By setting the animation prop, the content will be shown using an animation upon mount, or when changing the animation prop. By setting the hide prop to true, the animation will be reversed and the content will be hidden.

PropertyTypeDefaultDescription
animationstringAnimation (see Animations). When specified causes the content to be shown using this animation, or hidden when hide it set to true.
hidebooleanfalseSet to true to hide the content (reverses the animation)
durationnumber1000Length of the animation (milliseconds)
delaynumber0Amount of msec to wait before starting the animation
easingfunctionEasing function to define the curve
useNativeDriverbooleantrueUse the native-driver. All clipping effects naturally support the native-driver, so there is no need to disable this prop.fadebooleanfalseApplies an additional fade in/out effect
animValueAnimated.ValueOptional animated value to control the animation. Useful for linking the animation to gestures or making the animation part of a larger compound animation. The value should animate from 0 to 1
onAnimationEndfunctionCallback that is called whenever a show or hide transition has occured

Clipped.Transition

Clipped.Transition shows new content with an animation, when a new child with a different key is provided. This causes the new content to be shown using the new animation, and the old content will be hidden with a reversed animation. Under the hood, transition uses one or more Clipped.View components to perform its animations.

Props

PropertyTypeDefaultDescription
animationstringAnimation (see Animations). When specified causes the content to be shown using this animation, or hidden when hide it set to true.
durationnumber1000Length of the animation (milliseconds)
delaynumber0Amount of msec to wait before starting the animation
easingfunctionEasing function to define the curve
useNativeDriverbooleantrueUse the native-driver. All clipping effects naturally support the native-driver, so there is no need to disable this prop.fadebooleanfalseApplies an additional fade in/out effect
onTransitionEndfunctionCallback that is called whenever a show or hide transition has occured
debugbooleanEnables debug mode and displays the underlying clipping layers

Clipped.Fragment

The Clipped.Fragment is the core building block for creating clipping effects. Fragments can be nested to combine multiple clipping effects. See examples for more details.

Props

PropertyTypeDescription
originalWidthnumberOriginal width of the content
originalHeightnumberOriginal height of the content
widthnumberClipped width of the fragment
heightnumberClipped height of the fragment
leftnumberX-offset at which the clipped content is displayed
topnumberY-offset at which the clipped content is displayed
translateXnumber | Animated.ValueTranslate the content over the x-axis
translateYnumber | Animated.ValueTranslate the content over the y-axis
movebooleanWhen set to true, moves the translated content, rather than keeping it in the same place and clipping it
scaleXnumber | Animated.ValueX-scale
scaleYnumber | Animated.ValueY-scale
rotateXnumber | Animated.Valuex-rotation
rotateYnumber | Animated.ValueY-rotation
rotateZnumber | Animated.ValueZ-rotation
opacitynumber | Animated.ValueOpacity
perspectivenumber | Animated.ValuePerspective
debugbooleanEnables debug mode and displays the underlying clipping layers

Animations

The following animations are available out of the box.

ClipSlide
clipLeftslideLeft
clipRightslideRight
clipUpslideUp
clipDownslideDown
clipLeftUpslideLeftUp
clipLeftDownslideLeftDown
clipRightUpslideRightUp
clipRightDownslideRightDown
clipInsideOutslideInsideOut
clipInsideOutXslideInsideOutX
clipInsideOutYslideInsideOutY
clipOutsideIn
clipOutsideInX
clipOutsideInY

The list of animations is also accessible as an array of strings:

import * as Clipped from 'react-native-clipped';
console.log(Clipped.Animations); // ['clipLeft', 'clipRight', ...

License

MIT

Cool?

Do you think this cool and useful? Consider buying me a morning coffee!