From 07c41cd8e378eb6bbf3a1cc4c63dec6108b3dffb Mon Sep 17 00:00:00 2001 From: Eunseo Jang Date: Fri, 13 Mar 2020 17:32:00 +0900 Subject: [PATCH] =?UTF-8?q?=ED=8C=A8=ED=82=A4=EC=A7=80=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD/=EC=88=98=EC=A0=95=EC=82=AC=ED=95=AD=20=EC=A0=81?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 6 +++--- src/components/countdown-timer.js | 11 +++++------ src/components/flip-number/index.js | 29 ++++++++++++++++++++++++----- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/package.json b/package.json index 368f10f..7b9c506 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/countdown-timer.js b/src/components/countdown-timer.js index dbc214a..cab37a6 100644 --- a/src/components/countdown-timer.js +++ b/src/components/countdown-timer.js @@ -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'; @@ -60,11 +59,11 @@ class CountdownTimer extends React.Component { const { hours, minutes, seconds } = this.state; return ( - {!!hours && } - - {!!minutes && } - - {!!seconds && } + {!!hours && } + {/* */} + {!!minutes && } + {/* */} + {!!seconds && } ); } diff --git a/src/components/flip-number/index.js b/src/components/flip-number/index.js index 0a47225..bd10abf 100644 --- a/src/components/flip-number/index.js +++ b/src/components/flip-number/index.js @@ -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; @@ -64,6 +81,8 @@ FlipNumber.propTypes = { cardStyle: PropTypes.object, flipCardStyle: PropTypes.object, numberStyle: PropTypes.object, + min: PropTypes.string, + sec: PropTypes.string, }; export default FlipNumber;