I’ve been digging into the react native world. Totally new to this area.
And was trying to create a button component. Where the button is kind of circular, and have a specific color, title that will be send to it by parameters.
The complex thing I’m trying to do is trying to achieve a type of inside linear effect to the button, where as into the attached image, it looks like a thin inside circle.
Please find attached image as an example of what I’m trying to achieve:
I’ve tried the following code:
import React from 'react';
import { TouchableOpacity, Text, StyleSheet } from 'react-native';
const HomeButton = ({ title, color }) => {
return (
<TouchableOpacity style={[styles.button, { backgroundColor: color }]}>
<Text style={styles.title}>{title}</Text>
</TouchableOpacity>
);
};
const styles = StyleSheet.create({
button: {
width: 100,
height: 100,
borderRadius: 100,
justifyContent: 'center',
alignItems: 'center',
elevation: 5,
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.5,
},
title: {
fontSize: 20,
color: '#fff',
textAlign: 'center',
},
});
export default HomeButton;
This actually do create a circular button, but with very static color.
Tried also to install and use the following just to break the one color issue, but still didn’t work:
npm install react-native-linear-gradient
Where the code became something like this:
const HomeButton = ({ title, colors }) => {
return (
<TouchableOpacity style={styles.button}>
<LinearGradient
colors={colors}
style={styles.gradient}
>
<View style={styles.innerCircle} />
<Text style={styles.title}>{title}</Text>
</LinearGradient>
</TouchableOpacity>
);
};
Is the design actually doable? Any help please?
2
Answers
If you have a severely tricky component like in the example you provided you can try to download it as an image and create a button in the following way:
Gif how does work example from the code snippet
You can use react native svg. I started by creating a circle component
Now you can draw your circles and decide where shadows should appear:
Usage:
demo