Created
June 26, 2019 18:38
-
-
Save cyb3rsalih/964e6c3dafba83e410fd3052ae7d1aef to your computer and use it in GitHub Desktop.
Simple Circle React Native Component
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| import PropTypes from "prop-types"; | |
| import { | |
| View, | |
| StyleSheet, | |
| TouchableHighlight, | |
| Text, | |
| Dimensions | |
| } from "react-native"; | |
| const screen = Dimensions.get("screen"); | |
| handlePress = text => { | |
| alert(text + " Clicked"); | |
| }; | |
| const Circle = props => { | |
| return ( | |
| <View style={styles.circle}> | |
| <TouchableHighlight | |
| underlayColor={"#fcf"} | |
| style={styles.innerCircle} | |
| onPress={() => this.handlePress(props.text)} | |
| > | |
| <Text style={styles.text}> {props.text} </Text> | |
| </TouchableHighlight> | |
| </View> | |
| ); | |
| }; | |
| Circle.propTypes = { | |
| text: PropTypes.string.isRequired | |
| }; | |
| Circle.defaultProps = { | |
| text: "Default" | |
| }; | |
| export default Circle; | |
| const styles = StyleSheet.create({ | |
| circle: { | |
| width: screen.width / 7, | |
| height: screen.width / 7, | |
| borderRadius: screen.width / 14, | |
| borderColor: "#ccc", | |
| padding: 5, | |
| borderWidth: 1, | |
| margin: 10 | |
| }, | |
| innerCircle: { | |
| flex: 1, | |
| borderRadius: screen.width / 14, | |
| justifyContent: "center", | |
| alignItems: "center" | |
| }, | |
| text: { | |
| fontSize: 10 | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment