I am trying to add Instagram type filter to add some effect to my image using React-native? - react-native

I am creating an Image Editing Application & I have to put put image effect filters to change brightness, hue, saturation, etc with the help of Range Slider?Is there any possibilities to do it with Css properties?
I need something like Instagram Filters.
import React from 'react';
import { StyleSheet,
Text,
View,
Image,
SafeAreaView,
ScrollView } from 'react-native';
import {Asset } from 'expo-asset';
export default class App extends React.Component {
state={
ready: false,
image: null,
value: 0,
angle: 0,
deg: 'deg',
Vflipangle: 0,
Hflipangle:0,
positivevalue: 0,
};
//--- this function brings the contains the image locaiton to show inside <Image/>----------
//---------------This function runs automatically on mounting----------------------------
componentDidMount(){
const image = Asset.fromModule(require('./assets/girl.jpg'));
this.setState({
ready: true,
image,
});
}
//------------------------------------------------------------------------------
//Function to Render Image to show on Application Screen---------------------------
_renderImage =()=> {
return(
// <View style = {{margin: 20, alignItems: 'center',backgroundColor: 'black', overflow: 'hidden'}}>
// </View>
<Image source= {{uri: this.state.image.localUri || this.state.image.uri}}
style={{width:300+this.state.positivevalue,height:400+this.state.positivevalue, resizeMode:'cover',
transform: [{ rotate: this.state.value+this.state.deg}]
}}
/>
)
}
filteredImage =()=> {
return(
<Image source={{uri: this.state.image.localUri || this.state.image.uri}}
style={{flex: 1,
width: null,
height: null,
resizeMode: 'cover',}}/>
)
}
render(){
return (
<SafeAreaView style={styles.container}>
<View style={{alignItems: 'center',
justifyContent: 'center',
flex: 2}}>
<View style={{transform: [{ rotate: this.state.angle+this.state.deg},
{rotateY: this.state.Vflipangle + this.state.deg},
{rotateX: this.state.Hflipangle + this.state.deg}],
overflow: 'hidden',
width: 300,
height: 400,
alignItems: 'flex-end',
justifyContent: 'center',
//
}}>
{this.state.ready && this._renderImage()}
</View>
</View>
<ScrollView scrollEventThrottle= {16} style={{flex: 1}}>
<View style={{height: 150, marginTop: 20}}>
<ScrollView horizontal={true}>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex:0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Reset</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Brightness</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Contrast</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Exposure</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5,alignItems: 'center'}}>
<Text style={{color: '#ffffff'}}>Saturation</Text>
</View>
</View>
<View style={{height: 150, width: 100, marginLeft: 20, borderWidth: 0.5,
borderColor: '#dddddd'}}>
<View style={{flex:4,}}>
{this.state.ready && this.filteredImage()}
</View>
<View style={{flex: 0.5, alignItems: 'center',height:10}}>
<Text style={{color: '#ffffff'}}>Temperature</Text>
</View>
</View>
</ScrollView>
</View>
</ScrollView>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#000000',
// alignItems: 'center',
//justifyContent: 'center',
},
})
;
Here my code looks like , i will add slider later in it

You can achieve these effects using this library: gl-react-native-v2
It's a little more complicated than CSS effects, but you just can't use CSS in React Native. So this is most likely the best option.

Related

Make Image Fit Inside a View React native

there's a gap above the Image inside the View. Im trying to make it fit the Image inside my View
My Output
What i want to achieve
Here is my code
import React from 'react';
import {View, Text, StyleSheet, Image, TouchableOpacity} from 'react-native';
import THEME from '../../constants/theme.constants';
import SmallButton from './SmallButton';
import default_pp from '../../assets/default_pp.png';
import thumbnail_post from '../../assets/thumbnail_post.png';
function PostServiceProvider({user, ratings, rate, description}) {
return (
<View style={styles.container}>
<View style={styles.headerPost}>
<Image source={default_pp} style={styles.profilePicContainer} />
<TouchableOpacity style={{marginLeft: 10}}>
<Text style={styles.priceText}>{user}</Text>
</TouchableOpacity>
<View style={{position: 'absolute', right: 5}}>
<Text>{ratings}</Text>
</View>
</View>
<View style={styles.cardContainer}>
<Image source={thumbnail_post} style={styles.thumbnailImg} />
<View style={styles.rateContainer}>
<Text style={styles.text}>Daily Rate: </Text>
<Text style={styles.priceText}>Php 400</Text>
<View style={styles.buttonContainer}>
<SmallButton label="Hire" />
</View>
</View>
<View style={styles.br} />
<View style={{padding: 20}}>
<Text numberOfLines={2} style={styles.text}>
{description}
</Text>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
width: '100%',
borderRadius: 50,
borderColor: 'transparent',
marginTop: 20,
},
headerPost: {flexDirection: 'row', alignItems: 'center'},
profilePicContainer: {
height: 40,
width: 40,
borderRadius: 50,
borderWidth: 1,
},
cardContainer: {
width: '100%',
flex: 1,
borderColor: 'rgba(0,0,0,0.2)',
borderRadius: 10,
borderWidth: 0.5,
marginTop: 10,
alignItems: 'center',
},
thumbnailImg: {width: '100%', height: 300},
rateContainer: {
flexDirection: 'row',
alignItems: 'center',
width: '100%',
padding: 20,
},
buttonContainer: {width: '22%', position: 'absolute', right: 15},
br: {height: 1, width: '90%', backgroundColor: 'rgba(0,0,0,0.1)'},
text: {color: THEME.FONT_FADE},
priceText: {fontWeight: 'bold', fontSize: 17},
});
export default PostServiceProvider;
Add resizeMode="cover" props in your image component like this :
... your previous code
<View style={styles.cardContainer}>
<Image source={thumbnail_post} style={styles.thumbnailImg} resizeMode="cover" />
... your rest of code

Touchables in react native

I am trying to add some space in the middle of two touchable components wrapped in a view
How do i go about doing that, I will include my style sheet
return (
<>enter code here
<View style={styles.container}>
<View style={styles.scrollContainer}>
<ScrollView
horizontal
pagingEnabled
showsHorizontalScrollIndicator={false}
>
{images.map((image) => (
<Image key={image} style={styles.image} source={image} />
))}
</ScrollView>
</View>
<View style={styles.btn}>
`enter code here`<LinearGradient
colors={["#0A5640", "#0A5640"]}
style={{ alignItems: "center", borderRadius: 10 }}
>
<TouchableOpacity onPress={() => navigation.navigate("SignIn")}>
<Text style={styles.btnAuth}>Sign In</Text>
</TouchableOpacity>
</LinearGradient>
<LinearGradient
colors={["#FFC72A", "#FFC72A"]}
style={{ alignItems: "center", borderRadius: 10 }}
>
<TouchableOpacity
onPress={() => navigation.navigate("CreateAccount")}
>
<Text style={styles.btnAuth}>Sign Up</Text>
</TouchableOpacity>
</LinearGradient>
</View>
</View>
</>
);
};
const styles = StyleSheet.create({
container: {
backgroundColor: "#0A5640",
},
scrollContainer: {
height: "100%",
},
image: {
width,
height: "100%",
},
btnAuth: {
fontSize: 18,
fontWeight: "bold",
paddingHorizontal: 60,
paddingVertical: 10,
color: "#fff",
marginLeft: 10,
},
btn: {
color: "#fff",
marginTop: 70,
flexDirection: "row",
alignItems: "center",
justifyContent: "space-around",
alignContent: "space-between",
zIndex: 200,
paddingRight: 10,
paddingLeft: 10,
bottom: 3,
position: "absolute",
},
});
Did you mean the space between SignIn and SignUp button? You can use flex or width to define the touchableOpacity width. Is this something that you tried to achieve?
import * as React from 'react';
import {Text,View,StyleSheet,TouchableOpacity,}from 'react-native';
export default function App() { return (
<View style={styles.container}>
<View style={styles.btn}>
<TouchableOpacity style={styles.btnAuth}>
<Text style={{color:'#000', fontSize:18}}>Sign In</Text>
</TouchableOpacity>
<TouchableOpacity style={styles.btnAuth}>
<Text style={{color:'#000', fontSize:18}}>Sign Up</Text>
</TouchableOpacity>
</View>
</View> ); }
const styles = StyleSheet.create({ container: { backgroundColor: '#0A5640', flex:1 }, btnAuth: {
padding: 20,
width : '45%',
alignItems:'center',
backgroundColor:'yellow' }, btn: {
color: '#fff',
width: '100%',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-around',
bottom: 3,
position: 'absolute', }, });

react native text horizontal cutting, need full text in one line how to do that?

react-native version: "0.62.0", I tried this code
ui coming like this:
React Native
</View>
<View style={{flex:8}}>
<View style={{padding: 20, height: 200, backgroundColor: 'red'}}>
<Text style={fonts.bold}>View 1</Text>
</View>
<View style={{padding: 20, height: 200, backgroundColor: 'red'}}>
<Text style={fonts.bold}>View 1</Text>
</View>
<View style={{padding: 20, height: 200, backgroundColor: 'yellow'}}>
<Text>View 1</Text>
</View>
<View style={{padding: 20, height: 200, backgroundColor: 'green'}}>
<Text>View 1</Text>
</View>
</View>
</View>
How to do it?
give Text width greater than space occupied by characters with some padding
It looks like you did not provide the code for intended green view. The green view in your code is different. It is under yellow view.
Tip: For intended view try to remove height and width properties.
Created a sample according to your problem
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<View style={styles.wrapperStyle}>
<View style={styles.leftStyle}>
<Text style={styles.textStyle}>Trending</Text>
</View>
<View style={styles.rightStyle}>
<Text>View 1</Text>
</View>
</View>
<View style={styles.wrapperStyle}>
<View style={[styles.leftStyle, { backgroundColor: 'green' }]}>
<Text style={styles.textStyle}>Top_games</Text>
</View>
<View style={[styles.rightStyle, { backgroundColor: 'yellow' }]}>
<Text>View 2</Text>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: 20,
},
wrapperStyle: {
height: 200,
flexDirection: 'row'
},
leftStyle: {
flex: 2,
backgroundColor: 'gray',
alignItems: 'center',
justifyContent: 'center'
},
rightStyle: {
flex: 8,
backgroundColor: 'red',
alignItems: 'center',
justifyContent: 'center'
},
textStyle: {
transform: [{ rotate: '-90deg' }]
}
});
Somtetimes you have to change flex value according to your requirements.
Hope this helps you. Feel free for doubts.

ScrollView not scrolling all components properly

I have cards written like this, they scroll horizontal but the last card, whenever I scroll it's not shown, below, is the image of the current code.
They are price cards that scroll horizontally, kindly help me fix this. I have banged my head around it and it seems I have failed
Please help me guys am in need of real help
class Pricing extends React.Component {
state = {
...
};
render() {
return (
<ScrollView
showsHorizontalScrollIndicator={false}
horizontal={true}
scrollEnabled
pagingEnabled
scrollEnabled
showsHorizontalScrollIndicator={false}
scrollEventThrottle={16}
snapToAlignment="center"
>
{this.state.FlatListItems.map(item => (
<View style={styles.subContainer} key={item.id}>
<View style={{
justifyContent: "center",
alignItems: "center",
}}>
<View>
<Image
source={item.image}
/></View>
<View>
<Text style={styles.subType}>{item.subType}</Text>
<Text style={styles.textSub}>{item.textSub}</Text>
</View>
<View>
<Text style={styles.currency}>{item.amount}<Text style={styles.currencyText}> Month</Text></Text>
</View>
</View>
<TouchableOpacity style={styles.button}>
<Text style={styles.buttonText}>Subscribe</Text>
</TouchableOpacity>
</View>
))}
</ScrollView>
);
}
}
const styles = StyleSheet.create({
subContainer: {
justifyContent: "center",
alignItems: "center",
backgroundColor: "transparent",
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 0,
},
shadowOpacity: 0.22,
shadowRadius: 10,
elevation: 1,
borderRadius: 10,
padding: 15,
marginTop: 20,
width: '50%'
},
})
Pricing.navigationOptions = {
header: null
}
export default withNavigation(Pricing);

First show the profile clicked then swipe between profiles react native

Hi how can I first show the user that I've clicked on and then display a swiper ? I can't find a logic for that. I have a list of users and when I click on one, it should open a new component where we will find more infos about that user. Then I want to swipe between the list of users on the same component of the description ?
Here are my user profile component and the flatlist :
render () {
var colorConnected;
if (this.props.navigation.getParam('Statut') === "ON") {
colorConnected = "#1fbc26";
}
else if (this.props.navigation.getParam('Statut') === "OFF") {
colorConnected = "#ff0303";
}
else {
colorConnected = "#ffd200";
}
return (
<Swiper showsPagination={false}>
{this.state.items.map((item, key) => {
return (
<ScrollView style = {styles.view_container}>
<View style={styles.photo}>
<ImageBackground source={{uri:this.props.navigation.getParam('Photo')}} style={{ width: '100%', height: '100%' }}>
<View style={styles.photo_content}>
<LinearGradient colors={['transparent', 'rgba(0,0,0,0.5)']} style={{ position: 'absolute', left: 0, right: 0, bottom: 0, height: 80 }} />
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
<View>
<Text style={{ fontSize: 40, color:'white' }}>{this.props.navigation.getParam('Age')}</Text>
</View>
<View style={{ marginRight: 7, marginLeft: 7, backgroundColor: '#ffffff', width: 1, height: 39 }}></View>
<View style={{ flexDirection: 'column', flex:1 }}>
<View style={{ flexDirection: 'row' }}>
<View style={[styles.bulle_presence, { backgroundColor: colorConnected } ]}></View>
<Text style={{ fontSize: 18, fontWeight: '600', color:'white' }}>{this.props.navigation.getParam('Pseudo')}</Text>
</View>
<View style={{ flexDirection: 'row', justifyContent: 'space-between'}}>
<Text style={{ fontSize: 15, color:'white' }}>{this.props.navigation.getParam('Distance')}</Text>
<Text style={{ fontSize: 15, color:'white'}}>{this.props.navigation.getParam('Genre')}</Text>
</View>
</View>
</View>
</View>
</ImageBackgroud>
</View>
</ScrollView>
)
})}
</Swiper>
)}
}
render() {
GLOBAL.data = this.state.dataSource;
//console.log(GLOBAL.data);
return (
<SafeAreaView style={{ flex:1 }}>
<View style={styles.main_container}>
<FlatList style={styles.flatList}
data={this.state.dataSource}
extraData = {this.state}
keyExtractor={(item, index) => item.MembreId}
renderItem={(item) => <UserItem user={item} displayDetailForUser={this._displayDetailForUser} />}
numColumns={numColumns}
refreshing={this.state.refreshing}
onRefresh={this.handleRefresh} />
</View>
</SafeAreaView>
)
}
With this code, I'm only able to swipe on the user where I've clicked. The others user are not showing.
You can open a modal then use a carousel like react-native-snap-carousel in full screen mode to generate your use case