Skip to content

Commit 689f40d

Browse files
committed
refactor: fix the animation when the decrease button is pressed
1 parent acbf54d commit 689f40d

File tree

6 files changed

+30
-30
lines changed

6 files changed

+30
-30
lines changed

example/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import {SafeAreaView, View, Image, Text, StatusBar} from 'react-native';
33
import LinearGradient from 'react-native-linear-gradient';
44
// import CounterInput from 'react-native-counter-input';
5-
import CounterInput from './build/dist/CounterInput';
5+
import CounterInput from './lib/CounterInput';
66
const App = () => {
77
return (
88
<>

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,4 +626,4 @@ SPEC CHECKSUMS:
626626

627627
PODFILE CHECKSUM: 446419b91f3d523996e9ca2fa51242b50bd76552
628628

629-
COCOAPODS: 1.11.3
629+
COCOAPODS: 1.12.0

lib/CounterInput.style.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ViewStyle, ImageStyle, TextStyle, StyleSheet } from "react-native";
1+
import {ViewStyle, ImageStyle, TextStyle, StyleSheet} from 'react-native';
22

33
interface Style {
44
textInputStyle: TextStyle;
@@ -17,12 +17,12 @@ export const _container = (
1717
padding: horizontal ? 0 : 9,
1818
minHeight: horizontal ? 45 : 140,
1919
maxWidth: horizontal ? undefined : 70,
20-
flexDirection: horizontal ? "row" : "column",
21-
alignItems: "center",
22-
justifyContent: "space-evenly",
20+
flexDirection: horizontal ? 'row' : 'column',
21+
alignItems: 'center',
22+
justifyContent: 'space-evenly',
2323
shadowRadius: 8,
2424
shadowOpacity: 0.2,
25-
shadowColor: "#000",
25+
shadowColor: '#000',
2626
elevation: 2,
2727
shadowOffset: {
2828
width: 0,
@@ -37,12 +37,12 @@ export const _increaseButtonStyle = (
3737
width: 40,
3838
height: 40,
3939
borderRadius: 16,
40-
alignItems: "center",
41-
justifyContent: "center",
42-
backgroundColor: isPressed ? increaseButtonBackgroundColor : "transparent",
40+
alignItems: 'center',
41+
justifyContent: 'center',
42+
backgroundColor: isPressed ? increaseButtonBackgroundColor : 'transparent',
4343
shadowOpacity: isPressed ? 0.1 : 0,
4444
shadowRadius: 3,
45-
shadowColor: "#000",
45+
shadowColor: '#000',
4646
shadowOffset: {
4747
width: 0,
4848
height: 3,
@@ -56,12 +56,12 @@ export const _decreaseButtonStyle = (
5656
width: 40,
5757
height: 40,
5858
borderRadius: 16,
59-
alignItems: "center",
60-
justifyContent: "center",
61-
backgroundColor: isPressed ? "transparent" : decreaseButtonBackgroundColor,
59+
alignItems: 'center',
60+
justifyContent: 'center',
61+
backgroundColor: isPressed ? 'transparent' : decreaseButtonBackgroundColor,
6262
shadowOpacity: isPressed ? 0 : 0.1,
6363
shadowRadius: 3,
64-
shadowColor: "#000",
64+
shadowColor: '#000',
6565
shadowOffset: {
6666
width: 0,
6767
height: 3,
@@ -75,9 +75,9 @@ export default StyleSheet.create<Style>({
7575
fontSize: 24,
7676
marginTop: 12,
7777
marginBottom: 8,
78-
alignSelf: "center",
79-
fontWeight: "bold",
80-
textAlign: "center",
78+
alignSelf: 'center',
79+
fontWeight: 'bold',
80+
textAlign: 'center',
8181
},
8282
buttonImageStyle: {
8383
width: 15,

lib/CounterInput.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const CounterInput: React.FC<CounterInputProps> = ({
7878
setCounter(counter - 1, (newCounterValue: any) => {
7979
onChange?.(newCounterValue);
8080

81-
setPressed(true, () => {
81+
setPressed(false, () => {
8282
onDecreasePress && onDecreasePress(newCounterValue);
8383
});
8484
});
@@ -92,18 +92,18 @@ const CounterInput: React.FC<CounterInputProps> = ({
9292
(min !== undefined && input < min) ||
9393
(max !== undefined && input > max)
9494
) {
95-
setCounter(oldNumber, (newCounterValue: any) => {
96-
onChange?.(newCounterValue);
97-
98-
onChangeText && onChangeText(newCounterValue);
99-
setPressed(true);
95+
setCounter(0, () => {
96+
setPressed(false, () => {
97+
setCounter(oldNumber, (newCounterValue: any) => {
98+
onChangeText?.(newCounterValue);
99+
onChange?.(newCounterValue);
100+
});
101+
});
100102
});
101103
} else {
102104
setCounter(input, (newCounterValue: any) => {
105+
onChangeText?.(newCounterValue);
103106
onChange?.(newCounterValue);
104-
105-
onChangeText && onChangeText(newCounterValue);
106-
setPressed(true);
107107
});
108108
}
109109
};

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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-counter-input",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "Counter Input with fully customizable options for React Native",
55
"main": "./build/dist/CounterInput.js",
66
"repository": "[email protected]:WrathChaos/react-native-counter-input.git",

0 commit comments

Comments
 (0)