Skip to content

Commit 58813ea

Browse files
authored
Merge pull request #1 from fwaadahmad1/fahmad/master
Added support for passing style props
2 parents fc39828 + b304fda commit 58813ea

File tree

3 files changed

+42
-15
lines changed

3 files changed

+42
-15
lines changed

index.d.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Type definitions for react-native-floating-action
22

3+
import { ImageStyle, TextStyle, ViewStyle } from "react-native";
4+
35
declare module "react-native-floating-action" {
46
import { Component } from "react";
57

@@ -22,6 +24,11 @@ declare module "react-native-floating-action" {
2224
icon?: JSX.Element;
2325
name: string;
2426
text?: string;
27+
style?: ViewStyle;
28+
textStyle?: TextStyle;
29+
textContainerStyle?: ViewStyle;
30+
imageStyle?: ImageStyle;
31+
imageContainerStyle?: ViewStyle;
2532
textBackground?: string;
2633
textColor?: string;
2734
textElevation?: number;
@@ -34,6 +41,9 @@ declare module "react-native-floating-action" {
3441
}
3542

3643
export interface IFloatingActionProps {
44+
style?: ViewStyle;
45+
iconStyle?: ViewStyle;
46+
itemStyle?: itemStyle;
3747
tintColor?: string;
3848
actions?: IActionProps[];
3949
color?: string;

src/FloatingAction.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ class FloatingAction extends Component {
182182
iconWidth,
183183
iconHeight,
184184
iconColor,
185+
iconStyle
185186
} = this.props;
186187

187188
if (overrideWithAction) {
@@ -191,7 +192,7 @@ class FloatingAction extends Component {
191192
return icon;
192193
}
193194
return (
194-
<Image style={{ width: iconWidth, height: iconHeight }} source={icon} />
195+
<Image style={[{ width: iconWidth, height: iconHeight }, iconStyle]} source={icon} />
195196
);
196197
}
197198

@@ -202,13 +203,13 @@ class FloatingAction extends Component {
202203

203204
return (
204205
<Image
205-
style={{ width: iconWidth, height: iconHeight }}
206+
style={[{ width: iconWidth, height: iconHeight }, iconStyle]}
206207
source={floatingIcon}
207208
/>
208209
);
209210
}
210211

211-
return <AddIcon width={iconWidth} height={iconHeight} backgroundColor={iconColor} />;
212+
return <AddIcon width={iconStyle?.width || iconWidth} height={iconStyle?.height || iconHeight} backgroundColor={iconStyle?.backgroundColor || iconColor} />;
212213
};
213214

214215
reset = () => {
@@ -333,7 +334,8 @@ class FloatingAction extends Component {
333334
color,
334335
position,
335336
overrideWithAction,
336-
animated
337+
animated,
338+
style,
337339
} = this.props;
338340
const { active } = this.state;
339341

@@ -414,9 +416,9 @@ class FloatingAction extends Component {
414416
}
415417

416418
const sizeStyle = {
417-
width: buttonSize,
418-
height: buttonSize,
419-
borderRadius: buttonSize / 2
419+
width: style?.width || buttonSize,
420+
height: style?.height || buttonSize,
421+
borderRadius: (style?.width || buttonSize) / 2
420422
};
421423

422424
return (
@@ -427,7 +429,8 @@ class FloatingAction extends Component {
427429
styles[`${position}Button`],
428430
propStyles,
429431
animatedVisibleView,
430-
this.getShadow()
432+
this.getShadow(),
433+
style
431434
]}
432435
accessible={false}
433436
>
@@ -459,6 +462,7 @@ class FloatingAction extends Component {
459462
actionsPaddingTopBottom,
460463
animated,
461464
tintColor,
465+
itemStyle
462466
} = this.props;
463467
const { active } = this.state;
464468

@@ -520,6 +524,11 @@ class FloatingAction extends Component {
520524
active={active}
521525
onPress={this.handlePressItem}
522526
animated={animated}
527+
style={{...itemStyle, ...action?.style}}
528+
imageStyle={action?.imageStyle}
529+
imageContainerStyle={action?.imageContainerStyle}
530+
textStyle={action?.textStyle}
531+
textContainerStyle={action.textContainerStyle}
523532
/>
524533
);
525534
})}
@@ -528,13 +537,13 @@ class FloatingAction extends Component {
528537
}
529538

530539
renderTappableBackground() {
531-
const { overlayColor } = this.props;
540+
const { overlayColor, backdropStyle } = this.props;
532541

533542
// TouchableOpacity don't require a child
534543
return (
535544
<TouchableOpacity
536545
activeOpacity={1}
537-
style={[styles.overlay, { backgroundColor: overlayColor }]}
546+
style={[styles.overlay, { backgroundColor: overlayColor }, backdropStyle]}
538547
onPress={this.handlePressBackdrop}
539548
/>
540549
);
@@ -558,7 +567,10 @@ class FloatingAction extends Component {
558567
}
559568

560569
FloatingAction.propTypes = {
570+
style: PropTypes.object,
561571
tintColor: PropTypes.string,
572+
iconStyle: PropTypes.object,
573+
itemStyle: PropTypes.object,
562574
actions: PropTypes.arrayOf(
563575
PropTypes.shape({
564576
color: PropTypes.string,

src/FloatingActionItem.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ class FloatingActionItem extends Component {
100100
}
101101

102102
renderButton() {
103-
const { buttonSize, icon, color, shadow, tintColor } = this.props;
103+
const { buttonSize, icon, color, shadow, tintColor, imageContainerStyle, imageStyle } = this.props;
104104

105105
let iconStyle;
106106

@@ -121,12 +121,12 @@ class FloatingActionItem extends Component {
121121
return (
122122
<View
123123
key="button"
124-
style={[styles.button, propStyles, shadow]}
124+
style={[styles.button, propStyles, shadow, imageContainerStyle]}
125125
>
126126
{React.isValidElement(icon) ? (
127127
icon
128128
) : (
129-
<Image style={[iconStyle, {tintColor: tintColor}]} source={icon} />
129+
<Image style={[iconStyle, {tintColor: tintColor}, imageStyle]} source={icon} />
130130
)}
131131
</View>
132132
);
@@ -139,7 +139,8 @@ class FloatingActionItem extends Component {
139139
render,
140140
margin,
141141
name,
142-
animated
142+
animated,
143+
style
143144
} = this.props;
144145

145146
const Touchable = getTouchableComponent(false);
@@ -197,7 +198,8 @@ class FloatingActionItem extends Component {
197198
{
198199
paddingTop: paddingTopBottom,
199200
paddingBottom: paddingTopBottom
200-
}
201+
},
202+
style
201203
]}
202204
>
203205
{components}
@@ -216,6 +218,9 @@ FloatingActionItem.propTypes = {
216218
textContainerStyle: PropTypes.object,
217219
text: PropTypes.string,
218220
textStyle: PropTypes.object,
221+
style: PropTypes.object,
222+
imageStyle: PropTypes.object,
223+
imageContainerStyle: PropTypes.object,
219224
textProps: PropTypes.object,
220225
textBackground: PropTypes.string,
221226
textColor: PropTypes.string,

0 commit comments

Comments
 (0)