Search code examples
react-nativereact-native-stylesheet

React Native custom button styling issue


I am designing custom button in react native through TouchableOpacity. So far I have tried different styling approaches but didn't get like required design. below mentioned is my attempt to solve.

<TouchableOpacity style={styles.numericButton}>
      <View>
          <Text style={styles.numericButtonText}>1</Text>
      </View>
</TouchableOpacity>


const styles = StyleSheet.create({

    numericButton: {
        margin:10,
        padding:10,
        backgroundColor:'#D3D3D3',
        borderColor:'#000',
        borderWidth:2,
        borderRadius:5,
        elevation:10,
        shadowOffset: { width: 5, height: 5 },
        shadowColor: "black",
        shadowOpacity: 1,
        shadowRadius: 5,

    },
    numericButtonText:{
        fontSize:24,
        fontWeight:'bold',
        fontFamily:'Cochin'
    }
});

result:

output Image

I want to style my react native button like this

enter image description here


Solution

  • We can achieve same type of button with react-native-linear-gradient

    enter image description here

    👆🏽was achieved with:

                <TouchableOpacity>
                    <LinearGradient
                        // start={{x: 0.5, y: .5}} end={{x: 1, y: 1.0}}
                        style={styles.button}
                        locations={[0.3, 0, 0]}
                        colors={['#A8AFB5', 'white', 'white']}
                    >
                         <Text style={styles.buttonText}>{props.data}</Text>
                    </LinearGradient>
                </TouchableOpacity>
    
    
    
    
     const styles = StyleSheet.create({
    
        button: { flex: 1, flexDirection: 'row', justifyContent: 'center', alignItems: 'center', borderRadius: 5, width: null, height: 81,marginTop:5, borderWidth: 1 },
        buttonText: {
            //textAlign:'center',
            fontSize: 24,
            fontWeight: 'bold',
            fontFamily: 'Cochin',
            color: 'black'
        }
    });