1.0.12 • Published 1 year ago

react-native-hq-times v1.0.12

Weekly downloads
50
License
MIT
Repository
github
Last release
1 year ago

npm version Packagist

HQ Rentals Times

A React Native Timer Counter Add-ons

Install

  npm install --save react-native-hq-times

or

yarn add react-native-hq-times

Usage

import TimerCountdown from 'react-native-timer-countdown';

render() {
    return (
        <TimerCountdown
            initialSecondsRemaining={1000*60}
            onTick={secondsRemaining => console.log('tick', secondsRemaining)}
            onTimeElapsed={() => console.log('complete')}
            allowFontScaling={true}
            style={{ fontSize: 20 }}
        />
    )
}

Props

NameDescriptionTypeRequiredDefault Value
initialSecondsRemainingThe time remaining for the countdown (in ms)number
intervalThe time between timer ticks (in ms).number1000ms
allowFontScalingto allow font scalingboolfalse
styleThe custom styling which will be applied to the Text componentstyle
formatSecondsRemainingA function that formats the secondsRemainingfunc
onTickA function to call each tick. It returns the remaining seconds.func
onTimeElapsedA function to call when the countdown completesfunc

FAQ

Why does this timer restart whenever I click any button?

What's happening

buttons clicked -> state changes -> react rerenders -> timer restarts

How to not to restart the timer component

Provided the state changes only occur in component B, A component will not rerender. As a result, no more unintended timer restarts.

import React, { Component } from "react";
import { StyleSheet, Button, View } from "react-native";
import TimerCountdown from "./TimerCountdown";

const A = () => (
  <View style={styles.container}>
    <B />
    <Timer />
  </View>
);
export default A;

class B extends Component {
  state = { isPressed: false };
  render() {
    return (
      <View styles={{ flex: 1 }}>
        <Button
          title={`${this.state.isPressed ? "Button Pressed" : "Button"}`}
          onPress={() => {
            this.setState({ isPressed: true });
          }}
        />
      </View>
    );
  }
}

const Timer = () => (
  <TimerCountdown
    initialSecondsRemaining={1000 * 60}
    onTick={secondsRemaining => console.log("tick", secondsRemaining)}
    onTimeElapsed={() => console.log("complete")}
    allowFontScaling={true}
    style={{ fontSize: 20 }}
  />
);

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center"
  }
});

License

MIT

1.0.11

1 year ago

1.0.12

1 year ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.0

5 years ago