0

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

Muhammad Iqbal
  • 1,394
  • 1
  • 14
  • 34
  • 2
    React Native's styling capabilities are limited enough that the only way to achieve lighting effects like that might be to use an image – Kai Feb 06 '19 at 00:34
  • @kai can you recommend me any third party library that can provide such styling in react native. – Muhammad Iqbal Feb 06 '19 at 00:40
  • 3
    React Native don't offer gradient. There is library for you purpose. react-native-liner-gradient https://github.com/react-native-community/react-native-linear-gradient However, I recommend to use image too. – sonicmario Feb 06 '19 at 02:10

2 Answers2

1

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'
    }
});
Muhammad Iqbal
  • 1,394
  • 1
  • 14
  • 34
0

Use following style and use more gradient to set the colors matching the design and check the reflected changes

numericButton: {
  alignItems: 'center',
  margin: 10,
  padding: 10,
  backgroundColor: '#D3D3D3',
  borderColor: '#000',
  borderWidth: 2,
  //borderRadius:5,
  elevation: 5,
  shadowOffset: { width: 5, height: 5 },
  shadowColor: 'grey',
  shadowOpacity: 1,
  shadowRadius: 5,
},
numericButtonText: {
  fontSize: 24,
  fontWeight: 'bold',
  fontFamily: 'Cochin',
},

You're good to go!

Akshay Mulgavkar
  • 1,727
  • 9
  • 22