Skip to content
This repository was archived by the owner on Feb 4, 2021. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions lib/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default class Button extends Component {
overrides: PropTypes.shape({
textColor: PropTypes.string,
backgroundColor: PropTypes.string,
rippleColor: PropTypes.string
rippleColor: PropTypes.string,
height: PropTypes.number,
}),
disabled: PropTypes.bool,
raised: PropTypes.bool,
Expand All @@ -24,7 +25,7 @@ export default class Button extends Component {
theme: 'light',
primary: PRIMARY,
disabled: false,
raised: false
raised: false,
};

constructor(props) {
Expand Down Expand Up @@ -152,15 +153,19 @@ export default class Button extends Component {
})();

const buttonStyle = (() => {
const heightStyle = (overrides && overrides.height) ? { height: overrides.height } : null;

if (raised) {
buttonStyleMap[shape][theme][type] = Object.assign(buttonStyleMap[shape][theme][type], heightStyle);

if (disabled || !(overrides && overrides.backgroundColor)) {
return buttonStyleMap[shape][theme][type];
}

return Object.assign(buttonStyleMap[shape][theme][type], { backgroundColor: getColor(overrides.backgroundColor) });
return Object.assign(buttonStyleMap[shape][theme][type], { backgroundColor: getColor(overrides.backgroundColor), height: overrides.height });
}

return null;
return heightStyle;
})();

const rippleColor = (() => {
Expand All @@ -177,7 +182,8 @@ export default class Button extends Component {
style={[
styles.button,
buttonStyle, {
backgroundColor: buttonStyle && buttonStyle.backgroundColor
backgroundColor: buttonStyle && buttonStyle.backgroundColor,
height: buttonStyle && buttonStyle.height,
}
]}
>
Expand All @@ -199,6 +205,7 @@ export default class Button extends Component {
styles.button,
buttonStyle, {
backgroundColor: buttonStyle && buttonStyle.backgroundColor,
height: buttonStyle && buttonStyle.height,
}, raised && !isCompatible('elevation') && {
borderWidth: 1,
borderColor: 'rgba(0,0,0,.12)'
Expand All @@ -224,6 +231,7 @@ export default class Button extends Component {
styles.button,
buttonStyle, {
backgroundColor: buttonStyle && buttonStyle.backgroundColor,
height: buttonStyle && buttonStyle.height,
elevation: raised ? elevation : 0
}]}
>
Expand All @@ -250,4 +258,4 @@ const styles = {
position: 'relative',
top: 2
}
};
};
67 changes: 67 additions & 0 deletions lib/FloatingActionButton.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { Component, PropTypes, View, TouchableNativeFeedback } from 'react-native';
import { PRIMARY, PRIMARY_COLORS } from './config';
import Icon from './Icon';
import { getColor } from './helpers';

export default class FloatingActionButton extends Component {

static propTypes = {
primary: PropTypes.oneOf(PRIMARY_COLORS),
onPress: PropTypes.func,
onLongPress: PropTypes.func,
mini: PropTypes.bool,
iconName: PropTypes.string,
iconColor: PropTypes.oneOf(PRIMARY_COLORS),
iconStyles: PropTypes.object,
};

static defaultProps = {
primary: PRIMARY,
mini: false,
iconStyles: {},
};

render() {
const { primary, onPress, onLongPress, mini, iconName, iconColor, iconStyles } = this.props;

const buttonBackground = { backgroundColor: getColor(primary) };
const outerStyles = mini ? { borderRadius: 20, width: 40, height: 40 } : { borderRadius: 28, width: 56, height: 56 };

return (
<View style={styles.wrapper}>
<TouchableNativeFeedback
background={TouchableNativeFeedback.Ripple()}
onPress={onPress}
onLongPress={onLongPress}
>
<View style={[
styles.initialStyles,
outerStyles,
buttonBackground,
]}
elevation={5} >
<Icon
name={iconName}
color={iconColor}
style={iconStyles}
/>
</View>
</TouchableNativeFeedback>
</View>
);
};
}

const styles = {
wrapper: {
position: 'absolute',
bottom: 16,
right: 16,
},
initialStyles: {
flex:1,
flexDirection:'row',
alignItems:'center',
justifyContent:'center'
}
};
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export { default as RadioButton } from './RadioButton';
export { default as Ripple } from './Ripple';
export { default as RadioButtonGroup } from './RadioButtonGroup';
export { default as Subheader } from './Subheader';
export { default as Toolbar } from './Toolbar';
export { default as Toolbar } from './Toolbar';
export { default as FloatingActionButton } from './FloatingActionButton';