Skip to content

Instantly share code, notes, and snippets.

@florindumitru
Last active October 24, 2020 10:52
Show Gist options
  • Select an option

  • Save florindumitru/0839388333ecfba9d90f8cac4ac002b4 to your computer and use it in GitHub Desktop.

Select an option

Save florindumitru/0839388333ecfba9d90f8cac4ac002b4 to your computer and use it in GitHub Desktop.
Simple React native buttons (Flat and Raised)
Simple React Native Buttons
- Flat buttons
- Raised buttons
- Outline buttons
- Rounded buttons
Just copy qbuttons.js in your project !
import * as React from 'react';
import { Text, View, StyleSheet } from 'react-native';
import Constants from 'expo-constants';
import {QFlatButton,QRaisedButton} from './components/qbuttons';
export default function App() {
return (
<View style={styles.container}>
<Text
style={{textAlign: "center", marginBottom: 20, fontWeight: "bold"}}
> QFlatButton & QRaisedButton </Text>
<QFlatButton
onPress={()=>null}
rounded
title="Rounded Flat Button"
backgroundColor="orange"
titleColor="white"
/>
<QRaisedButton
onPress={()=>null}
title="Normal Raised Button"
backgroundColor={"green"}
titleColor={"white"}
/>
<QFlatButton
onPress={()=>null}
rounded
outline
borderColor="blue"
title="Outline Rounded Button"
titleColor="blue"
/>
<QRaisedButton
onPress={()=>null}
title="Outline Raised Button"
outline
borderColor="#fc4903"
titleColor={"red"}
/>
<QFlatButton
onPress={()=>null}
rounded
// outline
borderColor="red"
title="Custom title & button style"
backgroundColor="white"
titleColor="green"
titleStyle={{fontSize: 12}}
style={{padding: 30}}
/>
<Text
style={{textAlign: "center", marginTop: 20,}}
> </Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
paddingTop: Constants.statusBarHeight,
backgroundColor: '#ecf0f1',
padding: 8,
},
paragraph: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
});
import * as React from 'react';
import { Text, TouchableOpacity } from 'react-native';
export class QFlatButton extends React.Component {
normal = () => {
return(
{
backgroundColor: this.props.backgroundColor,
justifyContent: "center",
alignContent: "center",
alignSelf: "center",
alignItems: "center",
padding: 15,
margin: 10,
borderRadius: this.props.rounded ? 10 : 3,
...this.props.style
}
)
}
outline = () => {
return(
{
borderColor: "orange",
borderWidth: 1,
borderColor: this.props.borderColor,
justifyContent: "center",
alignContent: "center",
alignSelf: "center",
alignItems: "center",
padding: 15,
margin: 10,
borderRadius: this.props.rounded ? 10 : 3,
...this.props.style
}
)
}
render(){
return (
<TouchableOpacity
onPress={this.props.onPress}
style={(this.props.outline) ? this.outline() : this.normal()}
>
<Text
style={{
color: this.props.titleColor,
textAlign: "center",
fontSize: 16,
...this.props.titleStyle
}}
>
{this.props.title}
</Text>
</TouchableOpacity>
);
}
}
export class QRaisedButton extends React.Component {
normal = () => {
return(
{
backgroundColor: this.props.backgroundColor,
justifyContent: "center",
alignContent: "center",
alignSelf: "center",
alignItems: "center",
padding: 15,
margin: 10,
borderRadius: this.props.rounded ? 10 : 3,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: 0.27,
shadowRadius: 4.65,
elevation: 6,
...this.props.style
}
)
}
outline = () => {
return(
{
borderColor: "orange",
borderWidth: 1,
borderColor: this.props.borderColor,
justifyContent: "center",
alignContent: "center",
alignSelf: "center",
alignItems: "center",
padding: 15,
margin: 10,
borderRadius: this.props.rounded ? 10 : 3,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 3,
},
shadowOpacity: 0.27,
shadowRadius: 4.65,
elevation: 6,
...this.props.style
}
)
}
render(){
return (
<TouchableOpacity
onPress={this.props.onPress}
style={(this.props.outline) ? this.outline() : this.normal()}
>
<Text
style={{
color: this.props.titleColor,
textAlign: "center",
fontSize: 16,
...this.props.titleStyle
}}
>
{this.props.title}
</Text>
</TouchableOpacity>
);
}
}
@florindumitru
Copy link
Author

Screenshot 2020-10-24 at 13 42 15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment