Skip to content

Commit 9d77fa0

Browse files
SudoPlzmastermoo
authored andcommitted
Package of fixes and new features (Read on): (#185)
* - Added access to shadow props via the prop shadowStyle. * The text container style is now overwriting the shadowStyle if needed. * Exposed the container view style property. * No longer allowing font scaling on the btn title text. * Fixed the TouchableNativeFeedback ripple off bounds bug on Android. - Added the fixNativeFeedbackRadius bool prop, set it to true otherwise nothing changes in the old code. - Added the nativeFeedbackRippleColor prop, to set the color of the ripple on TouchableNativeFeedback * Updated Readme.md - Also renamed props.style to props.shadowStyle - The shadowStyle prop now only works when hideShadow is inactive
1 parent ef55123 commit 9d77fa0

File tree

4 files changed

+62
-28
lines changed

4 files changed

+62
-28
lines changed

ActionButton.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default class ActionButton extends Component {
7676

7777
render() {
7878
return (
79-
<View pointerEvents="box-none" style={this.getOverlayStyles()}>
79+
<View pointerEvents="box-none" style={[this.getOverlayStyles(), this.props.style]}>
8080
<Animated.View pointerEvents="none" style={[this.getOverlayStyles(), {
8181
backgroundColor: this.props.bgColor,
8282
opacity: this.anim.interpolate({
@@ -133,18 +133,22 @@ export default class ActionButton extends Component {
133133
};
134134

135135
const Touchable = getTouchableComponent(this.props.useNativeFeedback);
136+
const parentStyle = Platform.OS === 'android' && this.props.fixNativeFeedbackRadius?
137+
{ right: this.props.offsetX, zIndex: this.props.zIndex, borderRadius: this.props.size / 2, width: this.props.size }
138+
:
139+
{ paddingHorizontal: this.props.offsetX, zIndex: this.props.zIndex }
136140

137141
return (
138-
<View style={{ paddingHorizontal: this.props.offsetX, zIndex: this.props.zIndex }}>
142+
<View style={parentStyle}>
139143
<Touchable
140-
background={touchableBackground}
144+
background={touchableBackground(this.props.nativeFeedbackRippleColor, this.props.fixNativeFeedbackRadius)}
141145
activeOpacity={this.props.activeOpacity}
142146
onLongPress={this.props.onLongPress}
143147
onPress={() => {
144148
this.props.onPress()
145149
if (this.props.children) this.animateButton()
146150
}}>
147-
<Animated.View style={[wrapperStyle, !this.props.hideShadow && shadowStyle]}>
151+
<Animated.View style={[wrapperStyle, !this.props.hideShadow && shadowStyle, !this.props.hideShadow && this.props.shadowStyle]}>
148152
<Animated.View style={[buttonStyle, animatedViewStyle]}>
149153
{this._renderButtonIcon()}
150154
</Animated.View>
@@ -261,6 +265,11 @@ ActionButton.propTypes = {
261265
zIndex: PropTypes.number,
262266

263267
hideShadow: PropTypes.bool,
268+
shadowStyle: React.PropTypes.oneOfType([
269+
React.PropTypes.object,
270+
React.PropTypes.array,
271+
React.PropTypes.number,
272+
]),
264273

265274
bgColor: PropTypes.string,
266275
bgOpacity: PropTypes.number,
@@ -281,8 +290,11 @@ ActionButton.propTypes = {
281290
degrees: PropTypes.number,
282291
verticalOrientation: PropTypes.oneOf(['up', 'down']),
283292
backgroundTappable: PropTypes.bool,
284-
useNativeFeedback: PropTypes.bool,
285293
activeOpacity: PropTypes.number,
294+
295+
useNativeFeedback: PropTypes.bool,
296+
fixNativeFeedbackRadius: PropTypes.bool,
297+
nativeFeedbackRippleColor: PropTypes.string,
286298
};
287299

288300
ActionButton.defaultProps = {
@@ -307,6 +319,8 @@ ActionButton.defaultProps = {
307319
backgroundTappable: false,
308320
useNativeFeedback: true,
309321
activeOpacity: DEFAULT_ACTIVE_OPACITY,
322+
fixNativeFeedbackRadius: false,
323+
nativeFeedbackRippleColor: 'rgba(255,255,255,0.75)',
310324
};
311325

312326
const styles = StyleSheet.create({

ActionButtonItem.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ export default class ActionButtonItem extends Component {
1616
spaceBetween: 15,
1717
useNativeFeedback: true,
1818
activeOpacity: DEFAULT_ACTIVE_OPACITY,
19+
fixNativeFeedbackRadius: true,
20+
nativeFeedbackRippleColor: 'rgba(255,255,255,0.75)',
1921
};
2022
}
2123

2224
static get propTypes() {
2325
return {
2426
active: PropTypes.bool,
2527
useNativeFeedback: PropTypes.bool,
28+
fixNativeFeedbackRadius: PropTypes.bool,
29+
nativeFeedbackRippleColor: PropTypes.string,
2630
activeOpacity: PropTypes.number,
2731
}
2832
}
@@ -33,9 +37,7 @@ export default class ActionButtonItem extends Component {
3337
if (!this.props.active) return null;
3438

3539
const animatedViewStyle = {
36-
height: size + SHADOW_SPACE + spacing,
3740
marginBottom: -SHADOW_SPACE,
38-
paddingHorizontal: this.props.offsetX,
3941
alignItems: alignItemsMap[position],
4042

4143
// backgroundColor: this.props.buttonColor,
@@ -63,18 +65,24 @@ export default class ActionButtonItem extends Component {
6365

6466
const Touchable = getTouchableComponent(this.props.useNativeFeedback);
6567

68+
const parentStyle = Platform.OS === 'android' && this.props.fixNativeFeedbackRadius ?
69+
{ height: size, marginBottom: spacing, right: this.props.offsetX, borderRadius: this.props.size / 2 }
70+
:
71+
{ paddingHorizontal: this.props.offsetX, height: size + SHADOW_SPACE + spacing };
6672
return (
67-
<Animated.View pointerEvents="box-none" style={animatedViewStyle}>
68-
<Touchable
69-
background={touchableBackground}
70-
activeOpacity={this.props.activeOpacity || DEFAULT_ACTIVE_OPACITY}
71-
onPress={this.props.onPress}>
72-
<View
73-
style={[buttonStyle, !hideShadow && shadowStyle, this.props.style]}
74-
>
75-
{this.props.children}
76-
</View>
77-
</Touchable>
73+
<Animated.View pointerEvents="box-none" style={[animatedViewStyle, parentStyle]}>
74+
<View style={{ width: this.props.size, height: this.props.size, borderRadius: size / 2 }} >
75+
<Touchable
76+
background={touchableBackground(this.props.nativeFeedbackRippleColor, this.props.fixNativeFeedbackRadius)}
77+
activeOpacity={this.props.activeOpacity || DEFAULT_ACTIVE_OPACITY}
78+
onPress={this.props.onPress}>
79+
<View
80+
style={[buttonStyle, !hideShadow && shadowStyle, !hideShadow && this.props.shadowStyle]}
81+
>
82+
{this.props.children}
83+
</View>
84+
</Touchable>
85+
</View>
7886
{this._renderTitle()}
7987
</Animated.View>
8088
);
@@ -94,15 +102,15 @@ export default class ActionButtonItem extends Component {
94102
positionStyles.right = WIDTH/2 + size/2 + spaceBetween;
95103
}
96104

97-
const textStyles = [styles.textContainer, positionStyles, textContainerStyle, !hideShadow && shadowStyle];
105+
const textStyles = [styles.textContainer, positionStyles, !hideShadow && shadowStyle, textContainerStyle];
98106

99107
return (
100108
<TextTouchable
101-
background={touchableBackground}
109+
background={touchableBackground(this.props.nativeFeedbackRippleColor, this.props.fixNativeFeedbackRadius)}
102110
activeOpacity={this.props.activeOpacity || DEFAULT_ACTIVE_OPACITY}
103111
onPress={this.props.onPress}>
104112
<View style={textStyles}>
105-
<Text style={[styles.text, this.props.textStyle]}>{this.props.title}</Text>
113+
<Text allowFontScaling={false} style={[styles.text, this.props.textStyle]}>{this.props.title}</Text>
106114
</View>
107115
</TextTouchable>
108116
);

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,12 @@ Take a look at [this gist](https://gist.github.com/mmazzarolo/cfd467436f9d110e94
111111
| onReset | function | null | use this to set the callback that will be called after the button reset's it's items
112112
| verticalOrientation | string | "up" | direction action buttons should expand. One of: `up` or `down`
113113
| backgroundTappable | boolean | false | make background tappable in active state of ActionButton
114-
| useNativeFeedback | boolean | true | whether to use TouchableNativeFeedback on Android
115114
| activeOpacity | number | 0.85 | activeOpacity props of TouchableOpacity
115+
| shadowStyle | style | null | The custom shadow style you want to pass in the action button
116+
| useNativeFeedback | boolean | true | Android: Whether to use a TouchableNativeFeedback
117+
| fixNativeFeedbackRadius | boolean | false | Android: Activate this to fix TouchableNativeFeedback Ripple UI problems
118+
| nativeFeedbackRippleColor | string | 'rgba(255,255,255,0.75)' | Android: Pass a color to the Ripple Effect of a TouchableNativeFeedback
119+
116120

117121
##### ActionButton.Item:
118122
| Property | Type | Default | Description |
@@ -125,6 +129,9 @@ Take a look at [this gist](https://gist.github.com/mmazzarolo/cfd467436f9d110e94
125129
| textContainerStyle | style | null | use this to set the textstyle of the button's item text container
126130
| textStyle | style | null | use this to set the textstyle of the button's item text
127131
| spaceBetween | number | 15 | use this to set the space between the Button and the text container
128-
| useNativeFeedback | boolean | true | whether to use TouchableNativeFeedback on Android
129132
| activeOpacity | number | 0.85 | activeOpacity props of TouchableOpacity
130133
| hideLabelShadow | boolean | same as hideShadow | use this to hide the button's label default elevation and boxShadow
134+
| shadowStyle | style | null | The custom shadow style you want to pass in the action button item
135+
| useNativeFeedback | boolean | true | Android: Whether to use a TouchableNativeFeedback
136+
| fixNativeFeedbackRadius | boolean | false | Android: Activate this to fix TouchableNativeFeedback Ripple UI problems
137+
| nativeFeedbackRippleColor | string | 'rgba(255,255,255,0.75)' | Android: Pass a color to the Ripple Effect of a TouchableNativeFeedback

shared.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,13 @@ export function getTouchableComponent(useNativeFeedback) {
2727
return TouchableOpacity;
2828
}
2929

30-
export const touchableBackground = isAndroid
31-
? Platform['Version'] >= 21
32-
? TouchableNativeFeedback.Ripple('rgba(255,255,255,0.75)', false)
33-
: TouchableNativeFeedback.SelectableBackground()
34-
: undefined;
30+
export function touchableBackground(color, fixRadius) {
31+
if (isAndroid) {
32+
if (Platform['Version'] >= 21) {
33+
return TouchableNativeFeedback.Ripple(color || 'rgba(255,255,255,0.75)', fixRadius)
34+
} else {
35+
TouchableNativeFeedback.SelectableBackground()
36+
}
37+
}
38+
return undefined;
39+
}

0 commit comments

Comments
 (0)