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

Added types definition, custom timer labels and an option to have them above #78

Open
wants to merge 4 commits 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
49 changes: 49 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {StyleProp, ViewStyle} from 'react-native';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import {StyleProp, ViewStyle, TextStyle} from 'react-native';

import * as React from 'react';

declare module 'react-native-countdown-component'{

export interface TimeLabels {
d: string;
h: string;
m: string;
s: string;
}

interface Time {
seconds: number;
minutes: number;
hours: number;
days: number;
}

export interface CountdownPropTypes {
id?: string,
digitStyle?: StyleProp<ViewStyle>,
digitTxtStyle?: StyleProp<ViewStyle>,
timeLabelStyle?: StyleProp<ViewStyle>,
separatorStyle?: StyleProp<ViewStyle>,
Comment on lines +23 to +25

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

digitStyle?: StyleProp<TextStyle>,
timeLabelStyle?: StyleProp<TextStyle>,
separatorStyle?: StyleProp<TextStyle>,

timeToShow?: string[],
showSeparator?: boolean,
size?: number,
until: number,
onChange?: () => void,
onPress?: () => void,
onFinish?: () => void,
timeLabels?: TimeLabels,
upperLabels?: boolean
}

export default class CountdownComponent extends React.Component<CountdownPropTypes> {
private _handleAppStateChange(): void;
getTimeLeft(): Time;
updateTimer(): void;
renderDigit(d: number): JSX.Element;
renderLabel(label: string): JSX.Element;
renderDoubleDigits(label: string, digits: number, upperLabels: boolean): JSX.Element;
renderSeparator(): JSX.Element;
renderCountdown(): JSX.Element;
render(): JSX.Element;
}

}
17 changes: 10 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class CountDown extends React.Component {
onChange: PropTypes.func,
onPress: PropTypes.func,
onFinish: PropTypes.func,
timeLabels: PropTypes.object,
upperLabels: PropTypes.bool
};

state = {
Expand Down Expand Up @@ -164,13 +166,14 @@ class CountDown extends React.Component {
}
};

renderDoubleDigits = (label, digits) => {
renderDoubleDigits = (label, digits, upperLabels) => {
return (
<View style={styles.doubleDigitCont}>
{upperLabels && this.renderLabel(label)}
<View style={styles.timeInnerCont}>
{this.renderDigit(digits)}
</View>
{this.renderLabel(label)}
{!upperLabels && this.renderLabel(label)}
</View>
);
};
Expand All @@ -191,7 +194,7 @@ class CountDown extends React.Component {
};

renderCountDown = () => {
const {timeToShow, timeLabels, showSeparator} = this.props;
const {timeToShow, timeLabels, showSeparator, upperLabels} = 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(':');
Expand All @@ -202,13 +205,13 @@ class CountDown extends React.Component {
style={styles.timeCont}
onPress={this.props.onPress}
>
{timeToShow.includes('D') ? this.renderDoubleDigits(timeLabels.d, newTime[0]) : null}
{timeToShow.includes('D') ? this.renderDoubleDigits(timeLabels.d, newTime[0], upperLabels) : null}
{showSeparator && timeToShow.includes('D') && timeToShow.includes('H') ? this.renderSeparator() : null}
{timeToShow.includes('H') ? this.renderDoubleDigits(timeLabels.h, newTime[1]) : null}
{timeToShow.includes('H') ? this.renderDoubleDigits(timeLabels.h, newTime[1], upperLabels) : null}
{showSeparator && timeToShow.includes('H') && timeToShow.includes('M') ? this.renderSeparator() : null}
{timeToShow.includes('M') ? this.renderDoubleDigits(timeLabels.m, newTime[2]) : null}
{timeToShow.includes('M') ? this.renderDoubleDigits(timeLabels.m, newTime[2], upperLabels) : null}
{showSeparator && timeToShow.includes('M') && timeToShow.includes('S') ? this.renderSeparator() : null}
{timeToShow.includes('S') ? this.renderDoubleDigits(timeLabels.s, newTime[3]) : null}
{timeToShow.includes('S') ? this.renderDoubleDigits(timeLabels.s, newTime[3], upperLabels) : null}
</Component>
);
};
Expand Down
Loading