Skip to content

Commit 699b266

Browse files
therealgillesmastermoo
authored andcommitted
Fix for down vertical orientation (mastermoo#113)
1 parent 6ee6acd commit 699b266

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

ActionButton.js

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export default class ActionButton extends Component {
3333
//////////////////////
3434

3535
getContainerStyles() {
36-
return [styles.overlay, this.getOrientation(), this.getOffsetXY()];
36+
return [this.getOverlayStyles(), this.getOrientation(), this.getOffsetXY()];
3737
}
3838

3939
getActionButtonStyles() {
@@ -56,7 +56,8 @@ export default class ActionButton extends Component {
5656
getOffsetXY() {
5757
return {
5858
paddingHorizontal: this.props.offsetX - 8,
59-
paddingBottom: this.props.offsetY
59+
paddingBottom: this.props.verticalOrientation === 'up' ? this.props.offsetY : 0,
60+
paddingTop: this.props.verticalOrientation === 'down' ? this.props.offsetY : 0
6061
};
6162
}
6263

@@ -65,22 +66,30 @@ export default class ActionButton extends Component {
6566
styles.actionsVertical,
6667
this.getOrientation(),
6768
{
68-
flexDirection: this.props.verticalOrientation === 'down' ?
69-
'column-reverse' :
70-
'column',
69+
flexDirection: 'column',
70+
justifyContent: this.props.verticalOrientation === 'up' ? 'flex-end' : 'flex-start'
7171
},
7272
];
7373
}
7474

75+
getOverlayStyles() {
76+
return [
77+
styles.overlay,
78+
{
79+
justifyContent: this.props.verticalOrientation === 'up' ? 'flex-end' : 'flex-start'
80+
}
81+
]
82+
}
83+
7584

7685
//////////////////////
7786
// RENDER METHODS
7887
//////////////////////
7988

8089
render() {
8190
return (
82-
<View pointerEvents="box-none" style={styles.overlay}>
83-
<Animated.View pointerEvents="none" style={[styles.overlay, {
91+
<View pointerEvents="box-none" style={this.getOverlayStyles()}>
92+
<Animated.View pointerEvents="none" style={[this.getOverlayStyles(), {
8493
backgroundColor: this.props.bgColor,
8594
opacity: this.anim
8695
}]}>
@@ -207,7 +216,7 @@ export default class ActionButton extends Component {
207216
return (
208217
<TouchableOpacity
209218
activeOpacity={1}
210-
style={styles.overlay}
219+
style={this.getOverlayStyles()}
211220
onPress={this.reset.bind(this)}
212221
/>
213222
);
@@ -298,7 +307,6 @@ const styles = StyleSheet.create({
298307
right: 0,
299308
top: 0,
300309
backgroundColor: 'transparent',
301-
justifyContent: 'flex-end',
302310
},
303311
actionBarItem: {
304312
alignItems: 'center',
@@ -327,6 +335,5 @@ const styles = StyleSheet.create({
327335
},
328336
actionsVertical: {
329337
flex: 1,
330-
justifyContent: 'flex-end',
331-
},
338+
}
332339
});

ActionButtonItem.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export default class ActionButtonItem extends Component {
3838
style={[styles.actionButtonWrap, {
3939
height: this.props.size + margin + 12,
4040
alignItems: this.state.alignItems,
41-
marginBottom: this.props.verticalOrientation === 'up' ? margin : 0,
42-
marginTop: this.props.verticalOrientation === 'down' ? margin : 0,
41+
marginBottom: this.props.verticalOrientation === 'up' ? margin : 0, // does not seem necessary
42+
marginTop: this.props.verticalOrientation === 'down' ? margin : 0, // does not seem necessary
4343
marginHorizontal: 8,
4444
opacity: this.props.anim,
4545
transform: [
@@ -69,8 +69,8 @@ export default class ActionButtonItem extends Component {
6969
borderRadius: this.props.size / 2,
7070
backgroundColor: this.props.buttonColor || this.props.btnColor,
7171
marginHorizontal: 8,
72-
marginBottom: this.props.verticalOrientation === 'up' ? 12 : 0,
73-
marginTop: this.props.verticalOrientation === 'down' ? 12 : 0,
72+
marginBottom: this.props.verticalOrientation === 'up' ? 12 : 0, // does not seem necessary
73+
marginTop: this.props.verticalOrientation === 'down' ? -12 : 0,
7474
}]}
7575
>
7676
{this.props.children}
@@ -94,7 +94,8 @@ export default class ActionButtonItem extends Component {
9494
getTextStyles() {
9595
// to align the center of the label with the center of the button,
9696
// offset = (half the size of the btn) - (half the size of the label)
97-
let offsetTop = this.props.size >= 28 ? (this.props.size / 2) - 14 : 0;
97+
let directionOffset = this.props.verticalOrientation === 'down' ? -12 : 0
98+
let offsetTop = this.props.size >= 28 ? (this.props.size / 2) - 14 + directionOffset : 0;
9899

99100
let positionStyles = {
100101
right: this.props.size + this.state.spaceBetween + 8,

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ Take a look at [this gist](https://gist.github.com/mmazzarolo/cfd467436f9d110e94
9393
| bgColor | string | "transparent" | background color when ActionButtons are visible
9494
| buttonColor | string | "rgba(0,0,0,1)" | background color of the +Button **(must be rgba value!)**
9595
| spacing | number | 20 | spacing between the `ActionButton.Item`s
96-
| offsetX | number | 10 / 30 | offset to the sides of the screen
97-
| offsetY | number | 4 / 30 | offset to the bottom of the screen
96+
| offsetX | number | 10 / 30 | offset from the left/right side of the screen for `left`/`right` position respectively
97+
| offsetY | number | 4 / 30 | offset from the bottom/top of the screen for `up`/`down` verticalOrientation respectively
9898
| btnOutRange | string | props.buttonColor | button background color to animate to
9999
| outRangeScale | number | 1 | changes size of button during animation
100100
| onPress | function | null | fires, when ActionButton is tapped

0 commit comments

Comments
 (0)