Skip to content

Commit 9b7568e

Browse files
Merge pull request #43 from SimformSolutionsPvtLtd/feature/dev_master
Feature/dev master
2 parents 6d05e84 + 838703f commit 9b7568e

File tree

6 files changed

+230
-42
lines changed

6 files changed

+230
-42
lines changed

Example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"react-native-animatable": "^1.3.3",
2020
"react-native-gradients": "^1.1.1",
2121
"react-native-indicators": "^0.17.0",
22-
"react-native-spinner-button": "^1.0.5",
22+
"react-native-spinner-button": "^1.0.7",
2323
"react-native-svg": "^12.1.0"
2424
},
2525
"devDependencies": {

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,7 @@ Don't forget to set the state variable you have given to _isLoading_ prop false
5151
* Default button style
5252
```javascript
5353
defaultButtonStyle: {
54-
justifyContent: 'center',
55-
alignItems: 'center',
56-
height: 50,
57-
backgroundColor: '#25CAC6',
54+
height: 50
5855
}
5956
```
6057
3. **borderStyle**
@@ -152,7 +149,7 @@ Don't forget to set the state variable you have given to _isLoading_ prop false
152149
* The flag to identify network connection and based on flag set user iteration. _false_ will render button with disable mode and _true_ will render button with normal mode.
153150
* Default type: boolean
154151
* Default value: _true_
155-
27. **isDisable**
152+
27. **disabled**
156153
* The flag to identify button enable/disable. _true_ will render button with disable mode and _false_ will render button with normal mode.
157154
* Default type: boolean
158155
* Default value: _false_
@@ -166,6 +163,10 @@ Don't forget to set the state variable you have given to _isLoading_ prop false
166163
* Its default value is null | undefined.
167164
* This properties used whenever you want to need gradient but not pass __gradientColors__, __gradientColoroffset__ and __gradientColorAngle__ properties.
168165
* if you want to see color combination of [Sample gradient](https://fx-gradient-previewer.netlify.app/)
166+
30. **disableGradientColors**
167+
* This is how we pass the colors we want to be displayed when button disable, colors can be passed in a different format, name, rgba, hex etc.
168+
* The colors should be ordered the way we want them to be displayed.
169+
* Eg. colors={[ “purple”, “white” ]} the gradient will move from purple to white.
169170
170171
## Example
171172
A full working example project is here [Example](https://github.com/simformsolutions/react-native-spinner-button/tree/master/Example)

components/SpinnerButton.js

Lines changed: 219 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import React from 'react';
2-
import PropTypes from 'prop-types';
3-
import ChildrenView from './ChildrenView';
4-
import styles from './styles/SpinnerButtonStyle';
5-
import AnimatedView from './AnimatedView';
6-
import AnimatableView from './AnimatableView';
7-
import { useAnimatedValues, getSpinnerStyle } from './utils'
8-
import { Animated, View, TouchableOpacity } from 'react-native';
1+
import PropTypes from "prop-types";
2+
import React from "react";
3+
import { Animated, TouchableOpacity, View } from "react-native";
4+
import AnimatableView from "./AnimatableView";
5+
import AnimatedView from "./AnimatedView";
6+
import ChildrenView from "./ChildrenView";
7+
import styles from "./styles/SpinnerButtonStyle";
8+
import { getSpinnerStyle, useAnimatedValues } from "./utils";
99

10-
const AnimatedTouchablesOpacity = Animated.createAnimatedComponent(
11-
TouchableOpacity,
12-
);
10+
const AnimatedTouchablesOpacity =
11+
Animated.createAnimatedComponent(TouchableOpacity);
1312

1413
const SpinnerButton = ({
1514
animationType,
15+
buttonContainer,
1616
buttonStyle,
1717
borderStyle,
1818
spinnerColor,
@@ -41,34 +41,51 @@ const SpinnerButton = ({
4141
isLoading,
4242
isConnected = true,
4343
disabled = false,
44-
disableStyle
44+
disableStyle,
45+
disableGradientColors,
4546
}) => {
4647
const isDisable = disabled || !isConnected;
4748
const isAnimationType = animationType !== null && animationType !== undefined;
48-
const style = [styles.defaultButton, styles.centerAlign, buttonStyle, borderStyle, isDisable && disableStyle];
49+
const gradientColor = isDisable
50+
? disableGradientColors || gradientColors
51+
: gradientColors;
52+
const style = [
53+
styles.defaultButton,
54+
styles.centerAlign,
55+
buttonStyle,
56+
borderStyle,
57+
isDisable && disableStyle,
58+
];
4959
const { height } = getSpinnerStyle(style, styles.defaultButton);
50-
const { handleLayout, animatedStyles, animatedChildHideStyle, animatedChildShowStyle } = useAnimatedValues({
51-
isLoading,
52-
style,
53-
animatedDuration,
60+
const {
61+
handleLayout,
62+
animatedStyles,
63+
animatedChildHideStyle,
64+
animatedChildShowStyle,
65+
} = useAnimatedValues({
66+
isLoading,
67+
style,
68+
animatedDuration,
5469
animateWidth,
5570
animateHeight,
56-
animateRadius
71+
animateRadius,
5772
});
58-
73+
5974
return (
60-
<View style={[styles.buttonContainer, styles.centerAlign]}>
75+
<View
76+
style={[styles.buttonContainer, styles.centerAlign, buttonContainer]}
77+
onLayout={handleLayout}
78+
>
6179
<AnimatedTouchablesOpacity
6280
activeOpacity={1}
6381
style={[style, animatedStyles]}
6482
onPress={onPress}
6583
disabled={isDisable || isLoading}
66-
onLayout={handleLayout}
6784
>
6885
<ChildrenView
6986
animatedStyles={animatedStyles}
7087
gradientType={gradientType}
71-
gradientColors={gradientColors}
88+
gradientColors={gradientColor}
7289
gradientColoroffset={gradientColoroffset}
7390
gradientColorAngle={gradientColorAngle}
7491
gradientRadialRadius={gradientRadialRadius}
@@ -80,7 +97,7 @@ const SpinnerButton = ({
8097
gradientName={gradientName}
8198
children={
8299
<>
83-
{isAnimationType &&
100+
{isAnimationType && (
84101
<AnimatableView
85102
animationType={animationType}
86103
children={children}
@@ -94,8 +111,8 @@ const SpinnerButton = ({
94111
indicatorCount={indicatorCount}
95112
spinnerOptions={spinnerOptions}
96113
/>
97-
}
98-
{!isAnimationType &&
114+
)}
115+
{!isAnimationType && (
99116
<AnimatedView
100117
animatedChildHideStyle={animatedChildHideStyle}
101118
animatedChildShowStyle={animatedChildShowStyle}
@@ -108,9 +125,9 @@ const SpinnerButton = ({
108125
indicatorCount={indicatorCount}
109126
spinnerOptions={spinnerOptions}
110127
/>
111-
}
128+
)}
112129
</>
113-
}
130+
}
114131
/>
115132
</AnimatedTouchablesOpacity>
116133
</View>
@@ -119,6 +136,7 @@ const SpinnerButton = ({
119136

120137
SpinnerButton.propTypes = {
121138
animationType: PropTypes.string,
139+
buttonContainer: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
122140
buttonStyle: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
123141
borderStyle: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
124142
spinnerColor: PropTypes.string,
@@ -129,7 +147,7 @@ SpinnerButton.propTypes = {
129147
size: PropTypes.number,
130148
spinnerOptions: PropTypes.shape({
131149
waveFactor: PropTypes.number,
132-
waveMode: PropTypes.string
150+
waveMode: PropTypes.string,
133151
}),
134152
gradientType: PropTypes.string,
135153
gradientColors: PropTypes.array,
@@ -150,7 +168,177 @@ SpinnerButton.propTypes = {
150168
isLoading: PropTypes.bool,
151169
isConnected: PropTypes.bool,
152170
disableStyle: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
153-
gradientName: PropTypes.oneOf(["Warm Flame", "Night Fade", "Spring Warmth", "Juicy Peach", "Young Passion", "Lady Lips", "Sunny Morning", "Rainy Ashville", "Frozen Dreams", "Winter Neva", "Dusty Grass", "Tempting Azure", "Heavy Rain", "Amy Crisp", "Mean Fruit", "Deep Blue", "Ripe Malinka", "Cloudy Knoxville", "Malibu Beach", "New Life", "True Sunset", "Morpheus Den", "Rare Wind", "Near Moon", "Wild Apple", "Saint Petersburg", "Plum Plate", "Everlasting Sky", "Happy Fisher", "Blessing", "Sharpeye Eagle", "Ladoga Bottom", "Lemon Gate", "Itmeo Branding", "Zeus Miracle", "Old Hat", "Star Wine", "Happy Acid", "Awesome Pine", "New York", "Shy Rainbow", "Mixed Hopes", "Fly High", "Strong Bliss", "Fresh Milk", "Snow Again", "February Ink", "Kind Steel", "Soft Grass", "Grown Early", "Sharp Blues", "Shady Water", "Dirty Beauty", "Great Whale", "Teen Notebook", "Polite Rumors", "Sweet Period", "Wide Matrix", "Soft Cherish", "Red Salvation", "Burning Spring", "Night Party", "Sky Glider", "Heaven Peach", "Purple Division", "Aqua Splash", "Spiky Naga", "Love Kiss", "Clean Mirror", "Premium Dark", "Cold Evening", "Cochiti Lake", "Summer Games", "Passionate Bed", "Mountain Rock", "Desert Hump", "Jungle Day", "Phoenix Start", "October Silence", "Faraway River", "Alchemist Lab", "Over Sun", "Premium White", "Mars Party", "Eternal Constance", "Japan Blush", "Smiling Rain", "Cloudy Apple", "Big Mango", "Healthy Water", "Amour Amour", "Risky Concrete", "Strong Stick", "Vicious Stance", "Palo Alto", "Happy Memories", "Midnight Bloom", "Crystalline", "Party Bliss", "Confident Cloud", "Le Cocktail", "River City", "Frozen Berry", "Child Care", "Flying Lemon", "New Retrowave", "Hidden Jaguar", "Above The Sky", "Nega", "Dense Water", "Seashore", "Marble Wall", "Cheerful Caramel", "Night Sky", "Magic Lake", "Young Grass", "Colorful Peach", "Gentle Care", "Plum Bath", "Happy Unicorn", "African Field", "Solid Stone", "Orange Juice", "Glass Water", "North Miracle", "Fruit Blend", "Millennium Pine", "High Flight", "Mole Hall", "Space Shift", "Forest Inei", "Royal Garden", "Rich Metal", "Juicy Cake", "Smart Indigo", "Sand Strike", "Norse Beauty", "Aqua Guidance", "Sun Veggie", "Sea Lord", "Black Sea", "Grass Shampoo", "Landing Aircraft", "Witch Dance", "Sleepless Night", "Angel Care", "Crystal River", "Soft Lipstick", "Salt Mountain", "Perfect White", "Fresh Oasis", "Strict November", "Morning Salad", "Deep Relief", "Sea Strike", "Night Call", "Supreme Sky", "Light Blue", "Mind Crawl", "Lily Meadow", "Sugar Lollipop", "Sweet Dessert", "Magic Ray", "Teen Party", "Frozen Heat", "Gagarin View", "Fabled Sunset", "Perfect Blue"])
154-
}
171+
disableGradientColors: PropTypes.array,
172+
gradientName: PropTypes.oneOf([
173+
"Warm Flame",
174+
"Night Fade",
175+
"Spring Warmth",
176+
"Juicy Peach",
177+
"Young Passion",
178+
"Lady Lips",
179+
"Sunny Morning",
180+
"Rainy Ashville",
181+
"Frozen Dreams",
182+
"Winter Neva",
183+
"Dusty Grass",
184+
"Tempting Azure",
185+
"Heavy Rain",
186+
"Amy Crisp",
187+
"Mean Fruit",
188+
"Deep Blue",
189+
"Ripe Malinka",
190+
"Cloudy Knoxville",
191+
"Malibu Beach",
192+
"New Life",
193+
"True Sunset",
194+
"Morpheus Den",
195+
"Rare Wind",
196+
"Near Moon",
197+
"Wild Apple",
198+
"Saint Petersburg",
199+
"Plum Plate",
200+
"Everlasting Sky",
201+
"Happy Fisher",
202+
"Blessing",
203+
"Sharpeye Eagle",
204+
"Ladoga Bottom",
205+
"Lemon Gate",
206+
"Itmeo Branding",
207+
"Zeus Miracle",
208+
"Old Hat",
209+
"Star Wine",
210+
"Happy Acid",
211+
"Awesome Pine",
212+
"New York",
213+
"Shy Rainbow",
214+
"Mixed Hopes",
215+
"Fly High",
216+
"Strong Bliss",
217+
"Fresh Milk",
218+
"Snow Again",
219+
"February Ink",
220+
"Kind Steel",
221+
"Soft Grass",
222+
"Grown Early",
223+
"Sharp Blues",
224+
"Shady Water",
225+
"Dirty Beauty",
226+
"Great Whale",
227+
"Teen Notebook",
228+
"Polite Rumors",
229+
"Sweet Period",
230+
"Wide Matrix",
231+
"Soft Cherish",
232+
"Red Salvation",
233+
"Burning Spring",
234+
"Night Party",
235+
"Sky Glider",
236+
"Heaven Peach",
237+
"Purple Division",
238+
"Aqua Splash",
239+
"Spiky Naga",
240+
"Love Kiss",
241+
"Clean Mirror",
242+
"Premium Dark",
243+
"Cold Evening",
244+
"Cochiti Lake",
245+
"Summer Games",
246+
"Passionate Bed",
247+
"Mountain Rock",
248+
"Desert Hump",
249+
"Jungle Day",
250+
"Phoenix Start",
251+
"October Silence",
252+
"Faraway River",
253+
"Alchemist Lab",
254+
"Over Sun",
255+
"Premium White",
256+
"Mars Party",
257+
"Eternal Constance",
258+
"Japan Blush",
259+
"Smiling Rain",
260+
"Cloudy Apple",
261+
"Big Mango",
262+
"Healthy Water",
263+
"Amour Amour",
264+
"Risky Concrete",
265+
"Strong Stick",
266+
"Vicious Stance",
267+
"Palo Alto",
268+
"Happy Memories",
269+
"Midnight Bloom",
270+
"Crystalline",
271+
"Party Bliss",
272+
"Confident Cloud",
273+
"Le Cocktail",
274+
"River City",
275+
"Frozen Berry",
276+
"Child Care",
277+
"Flying Lemon",
278+
"New Retrowave",
279+
"Hidden Jaguar",
280+
"Above The Sky",
281+
"Nega",
282+
"Dense Water",
283+
"Seashore",
284+
"Marble Wall",
285+
"Cheerful Caramel",
286+
"Night Sky",
287+
"Magic Lake",
288+
"Young Grass",
289+
"Colorful Peach",
290+
"Gentle Care",
291+
"Plum Bath",
292+
"Happy Unicorn",
293+
"African Field",
294+
"Solid Stone",
295+
"Orange Juice",
296+
"Glass Water",
297+
"North Miracle",
298+
"Fruit Blend",
299+
"Millennium Pine",
300+
"High Flight",
301+
"Mole Hall",
302+
"Space Shift",
303+
"Forest Inei",
304+
"Royal Garden",
305+
"Rich Metal",
306+
"Juicy Cake",
307+
"Smart Indigo",
308+
"Sand Strike",
309+
"Norse Beauty",
310+
"Aqua Guidance",
311+
"Sun Veggie",
312+
"Sea Lord",
313+
"Black Sea",
314+
"Grass Shampoo",
315+
"Landing Aircraft",
316+
"Witch Dance",
317+
"Sleepless Night",
318+
"Angel Care",
319+
"Crystal River",
320+
"Soft Lipstick",
321+
"Salt Mountain",
322+
"Perfect White",
323+
"Fresh Oasis",
324+
"Strict November",
325+
"Morning Salad",
326+
"Deep Relief",
327+
"Sea Strike",
328+
"Night Call",
329+
"Supreme Sky",
330+
"Light Blue",
331+
"Mind Crawl",
332+
"Lily Meadow",
333+
"Sugar Lollipop",
334+
"Sweet Dessert",
335+
"Magic Ray",
336+
"Teen Party",
337+
"Frozen Heat",
338+
"Gagarin View",
339+
"Fabled Sunset",
340+
"Perfect Blue",
341+
]),
342+
};
155343

156-
export default SpinnerButton;
344+
export default SpinnerButton;

components/styles/SpinnerButtonStyle.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ export default StyleSheet.create({
99
alignItems: 'center'
1010
},
1111
defaultButton: {
12-
height: 50,
13-
backgroundColor: '#25CAC6',
12+
height: 50
1413
},
1514
absoluteView: {
1615
...StyleSheet.absoluteFillObject

components/utils/useAnimatedValues.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ const useAnimatedValues = ({
1313
const [size, setSize] = useState(null);
1414
const defaultStyle = StyleSheet.flatten(style);
1515
const margin = defaultStyle.margin || defaultStyle.marginLeft || defaultStyle.marginRight || defaultStyle.marginHorizontal || 0;
16-
const defaultWidth = (size?.width || defaulButtonWidth) - (margin * 2);
16+
const defaultWidth = (defaultStyle.width || size?.width || defaulButtonWidth) - (margin * 2);
1717
const defaultRadius = defaultStyle.borderRadius || 0;
18-
const defaultHeight = size?.height || defaulButtonHeight;
18+
const defaultHeight = defaultStyle.height || size?.height || defaulButtonHeight;
1919
const animatedHeight = animateHeight || Math.min(defaultWidth, defaultHeight);
2020
const animatedWidth = animateWidth || Math.min(defaultWidth, defaultHeight);
2121
const animatedRadius = animateRadius || (Math.min(defaultWidth, defaultHeight)/2);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-spinner-button",
3-
"version": "1.0.5",
3+
"version": "1.0.9",
44
"description": "This is a react-native button component with a spinner. You can load a spinner or a button from the same component depending on a flag. for eg, you have a button. And on press of that button you are doing something and wants the user to show a spinner, all you have to do is use this component. You can pass along a boolean flag. The component will render a spinner if the flag is true and button if the flag is false.",
55
"author": "Rupal Patel <[email protected]>",
66
"main": "index.js",

0 commit comments

Comments
 (0)