Skip to content
Open
Changes from 1 commit
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
51 changes: 26 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import {
View,
Text,
TouchableOpacity,
AppState
AppState,
I18nManager
} from 'react-native';
import _ from 'lodash';
import {sprintf} from 'sprintf-js';
import { sprintf } from 'sprintf-js';

const DEFAULT_DIGIT_STYLE = {backgroundColor: '#FAB913'};
const DEFAULT_DIGIT_TXT_STYLE = {color: '#000'};
const DEFAULT_TIME_LABEL_STYLE = {color: '#000'};
const DEFAULT_SEPARATOR_STYLE = {color: '#000'};
const DEFAULT_DIGIT_STYLE = { backgroundColor: '#FAB913' };
const DEFAULT_DIGIT_TXT_STYLE = { color: '#000' };
const DEFAULT_TIME_LABEL_STYLE = { color: '#000' };
const DEFAULT_SEPARATOR_STYLE = { color: '#000' };
const DEFAULT_TIME_TO_SHOW = ['D', 'H', 'M', 'S'];
const DEFAULT_TIME_LABELS = {
d: 'Days',
Expand Down Expand Up @@ -68,7 +69,7 @@ class CountDown extends React.Component {
}

_handleAppStateChange = currentAppState => {
const {until, wentBackgroundAt} = this.state;
const { until, wentBackgroundAt } = this.state;
if (currentAppState === 'active' && wentBackgroundAt && this.props.running) {
const diff = (Date.now() - wentBackgroundAt) / 1000.0;
this.setState({
Expand All @@ -77,12 +78,12 @@ class CountDown extends React.Component {
});
}
if (currentAppState === 'background') {
this.setState({wentBackgroundAt: Date.now()});
this.setState({ wentBackgroundAt: Date.now() });
}
}

getTimeLeft = () => {
const {until} = this.state;
const { until } = this.state;
return {
seconds: until % 60,
minutes: parseInt(until / 60, 10) % 60,
Expand All @@ -92,7 +93,7 @@ class CountDown extends React.Component {
};

updateTimer = () => {
const {lastUntil, until} = this.state;
const { lastUntil, until } = this.state;

if (lastUntil === until || !this.props.running) {
return;
Expand All @@ -107,26 +108,26 @@ class CountDown extends React.Component {
}

if (until === 0) {
this.setState({lastUntil: 0, until: 0});
this.setState({ lastUntil: 0, until: 0 });
} else {
if (this.props.onChange) {
this.props.onChange();
}
this.setState({lastUntil: until, until: until - 1});
this.setState({ lastUntil: until, until: until - 1 });
}
};

renderDigit = (d) => {
const {digitStyle, digitTxtStyle, size} = this.props;
const { digitStyle, digitTxtStyle, size } = this.props;
return (
<View style={[
styles.digitCont,
digitStyle,
{width: size * 2.3, height: size * 2.6},
{ width: size * 2.3, height: size * 2.6 },
]}>
<Text style={[
styles.digitTxt,
{fontSize: size},
{ fontSize: size },
digitTxtStyle,
]}>
{d}
Expand All @@ -136,12 +137,12 @@ class CountDown extends React.Component {
};

renderLabel = label => {
const {timeLabelStyle, size} = this.props;
const { timeLabelStyle, size } = this.props;
if (label) {
return (
<Text style={[
styles.timeTxt,
{fontSize: size / 1.8},
{ fontSize: size / 1.8 },
timeLabelStyle,
]}>
{label}
Expand All @@ -162,12 +163,12 @@ class CountDown extends React.Component {
};

renderSeparator = () => {
const {separatorStyle, size} = this.props;
const { separatorStyle, size } = this.props;
return (
<View style={{justifyContent: 'center', alignItems: 'center'}}>
<View style={{ justifyContent: 'center', alignItems: 'center' }}>
<Text style={[
styles.separatorTxt,
{fontSize: size * 1.2},
{ fontSize: size * 1.2 },
separatorStyle,
]}>
{':'}
Expand All @@ -177,9 +178,9 @@ class CountDown extends React.Component {
};

renderCountDown = () => {
const {timeToShow, timeLabels, showSeparator} = this.props;
const {until} = this.state;
const {days, hours, minutes, seconds} = this.getTimeLeft();
const { timeToShow, timeLabels, showSeparator } = this.props;
const { until } = this.state;
const { days, hours, minutes, seconds } = this.getTimeLeft();
const newTime = sprintf('%02d:%02d:%02d:%02d', days, hours, minutes, seconds).split(':');
const Component = this.props.onPress ? TouchableOpacity : View;

Expand Down Expand Up @@ -223,7 +224,7 @@ CountDown.defaultProps = {

const styles = StyleSheet.create({
timeCont: {
flexDirection: 'row',
flexDirection: (I18nManager.isRTL) ? 'row-reverse' : 'row',
justifyContent: 'center',
},
timeTxt: {
Expand All @@ -232,7 +233,7 @@ const styles = StyleSheet.create({
backgroundColor: 'transparent',
},
timeInnerCont: {
flexDirection: 'row',
flexDirection: (I18nManager.isRTL) ? 'row-reverse' : 'row',
justifyContent: 'center',
alignItems: 'center',
},
Expand Down