Skip to content

Commit

Permalink
GlitchImage added and some modifications in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
maaxg committed Feb 23, 2021
1 parent c970785 commit 1fd8e05
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 18 deletions.
143 changes: 143 additions & 0 deletions GlitchImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
import React, {useRef, useEffect, useImperativeHandle, forwardRef} from 'react';
import {View, Animated, Image, Platform} from 'react-native';
import {styles} from './styles';
const SHADOW_COLOR = '#add8e6';
const MAIN_COLOR = '#144f66';
const ANIMATION_DURATION = 3000;
const GLITCH_AMPLITUDE = 10;
const REPEAT_DELAY = 1000;
const GlitchImage = (
{
glitchHeight = 200,
glitchAmplitude = GLITCH_AMPLITUDE,
glitchDuration = ANIMATION_DURATION,
repeatDelay = REPEAT_DELAY,
shadowColor = SHADOW_COLOR,
mainColor = MAIN_COLOR,
heightInputRange = [0, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110],
positionYInputRange = [0, 10, 20, 30, 60, 65, 70, 80, 90, 100],
disableAutoAnimation = false,
source = null,
imageStyle,
},
ref,
) => {
console.log(shadowColor);
console.log(mainColor);
console.log(source);
const mainAnimatedValue = useRef(new Animated.Value(0)).current;
const animatedX = useRef(new Animated.Value(0)).current;

const runAnimation = () => {
Animated.loop(
Animated.sequence([
Animated.spring(animatedX, {
toValue: -glitchAmplitude,
useNativeDriver: false,
speed: 1000,
bounciness: 1000,
}),
Animated.spring(animatedX, {
toValue: glitchAmplitude,
useNativeDriver: false,
speed: 1000,
bounciness: 1000,
}),
]),
).start();

Animated.timing(mainAnimatedValue, {
toValue: 100,
duration: glitchDuration,
useNativeDriver: false,
}).start(() => {
mainAnimatedValue.setValue(0);
if (!disableAutoAnimation) {
setTimeout(() => runAnimation(), repeatDelay);
}
});
};

useEffect(() => {
if (!disableAutoAnimation) {
runAnimation();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useImperativeHandle(ref, () => ({
animate: runAnimation,
}));

const height = mainAnimatedValue.interpolate({
inputRange: heightInputRange,
outputRange: [
0.01,
glitchHeight / 8,
glitchHeight / 8,
glitchHeight / 2.5,
glitchHeight / 2.5,
glitchHeight / 2.5,
glitchHeight / 5.5,
glitchHeight / 4,
glitchHeight / 10,
glitchHeight / 8,
glitchHeight / 4,
],
});

const positionY = mainAnimatedValue.interpolate({
inputRange: positionYInputRange,
outputRange: [
glitchHeight / 2.5,
glitchHeight / 2,
glitchHeight / 4,
glitchHeight / 1.3,
glitchHeight / 1.3,
glitchHeight / 8,
glitchHeight / 16,
0,
0,
glitchHeight / 4,
],
});
function renderImage(isCover = false) {
return (
<View
style={[
{backgroundColor: mainColor},
isCover ? [styles.glitchImage, {shadowColor: shadowColor}] : null,
]}>
<Image source={source} style={[styles.image, imageStyle]} />
</View>
);
}
return (
<View style={[styles.row]}>
{renderImage()}
<Animated.View
style={[
styles.row,
styles.coverContainer,
{height},
{transform: [{translateX: animatedX}, {translateY: positionY}]},
]}>
<Animated.View
style={[
styles.row,
{
transform: [
{
translateY: Animated.multiply(positionY, -1),
},
],
height: glitchHeight,
},
]}>
{renderImage(true)}
</Animated.View>
</Animated.View>
</View>
);
};
export default forwardRef(GlitchImage);
60 changes: 57 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,20 @@

# Welcome to Glitch Effect :wave:

![glitch(1)](https://user-images.githubusercontent.com/49838612/108607576-f4dc3a80-739f-11eb-80bc-13863f83bdaf.gif) ![glitch-button](https://user-images.githubusercontent.com/49838612/108607413-14bf2e80-739f-11eb-80cd-916449e94b6d.gif)
![glitch(1)](https://user-images.githubusercontent.com/49838612/108607576-f4dc3a80-739f-11eb-80bc-13863f83bdaf.gif) ![glitch-button](https://user-images.githubusercontent.com/49838612/108607413-14bf2e80-739f-11eb-80cd-916449e94b6d.gif) !
[image-glitch](https://user-images.githubusercontent.com/49838612/108854996-3d297180-75c7-11eb-8db5-ed190c63aa41.gif)


## What is React native Glitch Effect?

- Is a simple way to use attribute a glitch effect to your text
- Is a simple way to glitch your text and images.

## Instalation

```javascript
npm i rn-glitch-effect
```
# Properties
# Properties - Glitch
| props | description | default value | |
| ------------------- | ------------------- | ------------------- | ------------------- |
| text | Your text label that's going to be displayed. | empty | <b>String</b>|
Expand All @@ -29,6 +30,22 @@
| outOfTextRange | Will make your effect get out of the range from your text | false | <b>Boolean</b>|
| disableAutoAnimation | enable or disabled your animation | false | <b>Boolean</b>|


# Properties - GlitchImage
| props | description | default value | |
| ------------------- | ------------------- | ------------------- | ------------------- |
| glitchHeight | The height that you want your glitch effect will have. | 200 | <b>Integer</b>|
| glitchAmplitude | The amplitude of your glitch. In other words, how far your effect will be from the main text. | 5 | <b>Integer</b>|
| glitchDuration | The duration of your glitch effect. | 1500 | <b>Milisseconds</b>|
| repeatDelay | How long time your effect will wait, to start another turn of effect. | 2000 | <b>Milisseconds</b>|
| shadowColor | The shadow color of your effect. | #add8e6 | <b>rgb</b>|
| imageStyle | The style that you want to give to your text. | {width: 400,height: 200} | <b>Object</b>|
| heightInputRange | The input range to the interpolation of main animation. With this you can control each part of your effect height. | [0, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110] | <b>array</b>|
| positionYInputRange | The input range to the interpolation of main animation. With this you can control each part of your effect position. | [0, 10, 20, 30, 60, 65, 70, 80, 90, 100] | <b>array</b>|
| disableAutoAnimation | enable or disabled your animation | false | <b>Boolean</b>|
| source | Your image path. | false | <b>String</b>|


# Usage

Basic Glitch
Expand Down Expand Up @@ -90,6 +107,43 @@ export default App;

```

```javascript
import React from 'react';
import {StyleSheet, View} from 'react-native';
import {Glitch, GlitchImage} from 'rn-glitch-effect';
import Gator from './assets/images/gator.jpeg';
const App = () => {
return (
<View style={[styles.container]}>
<View style={styles.containerWithBg}>
<Glitch
text={'GLITCH'}
mainColor={'black'}
shadowColor={'green'}
outOfTextRange={false}
/>
<GlitchImage shadowColor={'red'} mainColor={'black'} source={Gator} />
</View>
</View>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: 'white',
},
containerWithBg: {backgroundColor: 'red', marginBottom: '5%'},
image: {
width: 400,
height: 200,
},
});
export default App;

```

# End of the line :)

If you have any ideia to contribute with this project, please make your self home.
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export {default as Glitch} from './Glitch';
export {default as Glitch} from './Glitch';
export {default as GlitchImage} from './GlitchImage';
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"url": "git+https://github.com/maaxg/rn-glitch-effect.git"
},
"keywords": [
"react-native",
"React native",
"react native",
"glitch effect",
"react-native-glitch-effect",
"rn-glitch-effect",
"glitch-effect",
"glitch"
Expand Down
22 changes: 8 additions & 14 deletions styles.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import {StyleSheet} from 'react-native';

export const styles = StyleSheet.create({
image: {
width: 400,
height: 200,
},
row: {
flexDirection: 'row',
},
leftCorner: {
width: 0,
height: 0,
backgroundColor: 'transparent',
borderStyle: 'solid',
borderRightColor: 'transparent',
transform: [{rotate: '90deg'}],
},
rightSide: {
borderRightWidth: 2,
alignItems: 'center',
justifyContent: 'center',
},
rightSideCover: {
borderTopWidth: 2,
},
leftSideCover: {
borderLeftWidth: 2,
},
coverContainer: {
position: 'absolute',
overflow: 'hidden',
Expand All @@ -38,4 +28,8 @@ export const styles = StyleSheet.create({
textShadowOffset: {width: 3, height: 2},
textShadowRadius: 1,
},
glitchImage: {
shadowOffset: {width: 3, height: 2},
shadowRadius: 1,
},
});

0 comments on commit 1fd8e05

Please sign in to comment.