custom button class import React, {Component} from 'react'; import {Platform, StyleSheet, Text, View, Button,TouchableOpacity} from 'react-native';
export default class FlatButton extends Component { state={ backgroundColor : '#f01d71', backgroundColor2: '#f01d71', pressed: false, };
changeColor(){ if(!this.state.pressed){ this.setState({ pressed: true,backgroundColor: 'rgb(60,32,140)', backgroundColor2: '#f01d71'}); } else { this.setState({ pressed: false,backgroundColor: '#f01d71', backgroundColor2: '#f01d71'}); } } render() { return ( <View style={{
justifyContent: 'center',
alignItems: 'center',
}}>
<TouchableOpacity
style={{
backgroundColor:this.state.backgroundColor,
borderRadius: 10,
padding: 10,
shadowColor: '#000000',
shadowOffset: {
width: 0,
height: 3
},
shadowRadius: 5,
shadowOpacity: 1.0
}}
onPress={()=>this.changeColor()}
>
<Text style={styles.buttonText}>{this.props.text}</Text>
</TouchableOpacity>
</View>
);
} }
const styles = StyleSheet.create({ text:{ color:'white' }, buttonText: { color : 'white', fontWeight : 'bold', fontSize : 16, justifyContent: 'center', }, });
Second component where i am rendering import React , {useState, useEffect} from 'react'; import {Text, View , StyleSheet,Button, Dimensions} from 'react-native'; import FlatButton from '../shared/FlatButton' const CustomizationView=()=>{ return(
</View>
<View style= {styles.btnflex}>
<FlatButton text="Crop" />
<FlatButton text="Crop" />
<FlatButton text="Crop" />
</View>
</View>
);
};
const styles=StyleSheet.create({ container : { flex :1, // borderWidth : 5, // borderColor : 'black', paddingHorizontal : 10,
},
btnflex : {
flexDirection :'row',
marginTop: 5,
padding : 5,
justifyContent : 'space-between',
borderWidth : 5,
borderColor : 'red'
},
});
export default CustomizationView;
output is out put is this