Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Timer End Event #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-native-flip-countdown-timer",
"version": "0.0.3",
"description": "A Flip countdown timer implementation in React Native",
"name": "react-native-flip-countdown-timer-tl43",
"version": "0.0.4",
"description": "A Flip countdown timer implementation in React Native, modified by TL43",
"main": "dist/react-native-flip-countdown-timer.cjs.js",
"jsnext:main": "dist/react-native-flip-countdown-timer.esm.js",
"module": "dist/react-native-flip-countdown-timer.esm.js",
Expand Down
11 changes: 5 additions & 6 deletions src/components/countdown-timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { View } from 'react-native';
import PropTypes from 'prop-types';

import FlipNumber from './flip-number';
import Separator from './flip-number/separator';

import TransformUtils from '../utils';

Expand Down Expand Up @@ -60,11 +59,11 @@ class CountdownTimer extends React.Component {
const { hours, minutes, seconds } = this.state;
return (
<View style={[style.wrapper, wrapperStyle]}>
{!!hours && <FlipNumber number={hours} unit="hours" {...flipNumberProps} />}
<Separator />
{!!minutes && <FlipNumber number={minutes} unit="minutes" {...flipNumberProps} />}
<Separator />
{!!seconds && <FlipNumber number={seconds} unit="seconds" {...flipNumberProps} />}
{!!hours && <FlipNumber number={hours} min={minutes} sec={seconds} unit="hours" {...flipNumberProps} />}
{/* <Separator /> */}
{!!minutes && <FlipNumber number={minutes} min={minutes} sec={seconds} unit="minutes" {...flipNumberProps} />}
{/* <Separator /> */}
{!!seconds && <FlipNumber number={seconds} min={minutes} sec={seconds} unit="seconds" {...flipNumberProps} />}
</View>
);
}
Expand Down
29 changes: 24 additions & 5 deletions src/components/flip-number/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,30 @@ import style from '../style';

function FlipNumber({
number, unit, size, perspective, numberWrapperStyle, cardStyle, flipCardStyle, numberStyle,
min, sec,
}) {
number = parseInt(number);
let previousNumber = number - 1;
if (unit !== 'hours') {
previousNumber = previousNumber === -1 ? 59 : previousNumber;
} else {
previousNumber = previousNumber === -1 ? 23 : previousNumber;
min = parseInt(min);
sec = parseInt(sec);

let previousNumber = number;
if (unit === 'seconds') {
if (min === 0 && sec === 0) {
previousNumber = 0;
} else if (previousNumber === 0) {
previousNumber = 59;
} else {
previousNumber -= 1;
}
} else if (unit === 'minutes') {
if (sec === 0) {
previousNumber = 59;
}
} else { // hour
// eslint-disable-next-line no-lonely-if
if (min === 0 && number > 0) {
previousNumber -= 1;
}
}
number = number < 10 ? `0${number}` : number;
previousNumber = previousNumber < 10 ? `0${previousNumber}` : previousNumber;
Expand Down Expand Up @@ -64,6 +81,8 @@ FlipNumber.propTypes = {
cardStyle: PropTypes.object,
flipCardStyle: PropTypes.object,
numberStyle: PropTypes.object,
min: PropTypes.string,
sec: PropTypes.string,
};

export default FlipNumber;