Skip to content

Instantly share code, notes, and snippets.

@suhanlee
Last active April 17, 2018 03:19
Show Gist options
  • Save suhanlee/ab23ec88ef0b40a1865c10c34a5829a1 to your computer and use it in GitHub Desktop.
Save suhanlee/ab23ec88ef0b40a1865c10c34a5829a1 to your computer and use it in GitHub Desktop.
react-native-ui-components
import React from 'react'
import { Dimensions, View, Text, TouchableOpacity } from 'react-native'
import PropTypes from 'prop-types'
const FloatingActionButton = ({
width,
height,
top,
children,
bottom,
right,
backgroundColor,
onPress,
}) => {
const defaultTopOffset = 180
return (
<View style={{
position: 'absolute',
borderRadius: width / 2,
width: width,
height: height,
top: top || (Dimensions.get('window').height - defaultTopOffset),
bottom: bottom,
right: right,
backgroundColor: backgroundColor,
flex: 1,
justifyContent: 'center',
alignItems: 'center',
}}>
<TouchableOpacity onPress={onPress}>
<View style={{justifyContent: 'center', alignItems: 'center', width, height}}>
{children || <Text style={{
color: 'white',
fontSize: 20,
}}>
+
</Text>}
</View>
</TouchableOpacity>
</View>
)
}
FloatingActionButton.propTypes = {
top: PropTypes.number,
width: PropTypes.number,
height: PropTypes.number,
bottom: PropTypes.number,
right: PropTypes.number,
children: PropTypes.node,
backgroundColor: PropTypes.string,
onPress: PropTypes.func,
}
FloatingActionButton.defaultProps = {
top: undefined,
width: 50,
height: 50,
bottom: 100,
right: 10,
children: null,
backgroundColor: 'black',
onPress: () => {},
}
export default FloatingActionButton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment