Git Product home page Git Product logo

react-native-clock-analog's Introduction

React Native: react-native-clock-analog

GitHub package version github home platforms github home npm

github issues github closed issues Issue Stats github license

clock.mov

๐Ÿ“– Getting started

$ npm install react-native-clock-analog --save

๐Ÿ’ป Usage

import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, ImageBackground } from 'react-native';
import AnalogClock from 'react-native-clock-analog';

const nowDate = () => {
  const d = new Date();
  let second = d.getSeconds();
  let minute = d.getMinutes();
  let hour = d.getHours();
  return { second, minute, hour };
};

const nowTimer = () => {
  const { second, minute, hour } = nowDate();
  const [state, setState] = useState({
    second,
    minute,
    hour,
  });

  useEffect(() => {
    setInterval(() => {
      const { second, minute, hour } = nowDate();
      setState({ second, minute, hour });
    }, 1000);
  }, [useState]);
  return state;
};

export default function App() {
  const { second, minute, hour } = nowTimer();
  return (
    <View style={styles.container}>
      <ImageBackground
        source={{
          uri: 'https://i.pinimg.com/originals/62/6f/84/626f84c40696c1308a77fd8331e12b3e.jpg',
        }}
        style={{
          alignItems: 'center',
          justifyContent: 'center',
          height: 500,
          width: 500,
        }}>
        <AnalogClock size={100} />
        <View style={{ marginBottom: 5 }} />
        <AnalogClock
          colorClock="#2196F3"
          colorNumber="#000000"
          colorCenter="#00BCD4"
          colorHour="#FF8F00"
          colorMinutes="#FFC400"
          hour={hour}
          minutes={minute}
          seconds={second}
          showSeconds
        />
      </ImageBackground>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
});

๐Ÿ’ป AutoStart Mode

import React from 'react';
import { StyleSheet, Text, View, ImageBackground } from 'react-native';
import AnalogClock from 'react-native-clock-analog';

export default function App() {
  return (
    <View style={styles.container}>
      <ImageBackground
        source={{
          uri: 'https://i.pinimg.com/originals/62/6f/84/626f84c40696c1308a77fd8331e12b3e.jpg',
        }}
        style={{
          alignItems: 'center',
          justifyContent: 'center',
          height: 500,
          width: 500,
        }}>
        <AnalogClock size={100} />
        <View style={{ marginBottom: 5 }} />
        <AnalogClock
          colorClock="#2196F3"
          colorNumber="#000000"
          colorCenter="#00BCD4"
          colorHour="#FF8F00"
          colorMinutes="#FFC400"
          autostart={true}
          showSeconds
        />
      </ImageBackground>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
    backgroundColor: '#ecf0f1',
    padding: 8,
  },
});

๐Ÿ’ก Props

Prop Type Default Note
size number 180 Clock size.
showSeconds bool false Show the seconds.
autostart bool false Autostart, no need external timer
colorClock string rgba(255,255,255,0.8) Clock color.
colorNumber string #000000 Color of the clock numbers.
colorCenter string #000000 Clock center color.
colorHour string #000000 Clock hour hand color.
colorMinutes string rgba(255,255,255,0.7) Clock minute hand color.
colorSeconds string red Clock second hand color.
hour number Hour.
minutes number Minutes.
seconds number Seconds.

๐Ÿ“œ License

This library is provided under the Apache License.

react-native-clock-analog's People

Contributors

danielriera avatar gaetanozappi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-native-clock-analog's Issues

Add an npm start script

Currently there is no npm start script, so it's unclear how the project is supposed to be run locally.

Warning: Each child in a list should have a unique "key" prop ...

{[...Array(12).keys()].map((i,k) => {
let a = -60 + 30 * i;
let b = 60 - 30 * i;
return (
<View
key={k} //please update this code. getting error on this key.
style={{
position: 'absolute',
transform: [
{ rotate: a + 'deg' },
{ translateX: size / 2 - 15 },
],
}}>
<Text
style={{
color: colorNumber,
fontSize: size / 9,
fontWeight: 'bold',
transform: [{ rotate: b + 'deg' }],
}}>
{i + 1}


);
})}

Missing `key` property in AnalogClock.js

Hi! ๐Ÿ‘‹

Firstly, thanks for your work on this project! ๐Ÿ™‚

Today I used patch-package to patch [email protected] for the project I'm working on.

The render code was missing a key property on a View.

Here is the diff that solved my problem:

diff --git a/node_modules/react-native-clock-analog/AnalogClock.js b/node_modules/react-native-clock-analog/AnalogClock.js
index 8044139..f461400 100644
--- a/node_modules/react-native-clock-analog/AnalogClock.js
+++ b/node_modules/react-native-clock-analog/AnalogClock.js
@@ -84,7 +84,7 @@ export default class AnalogClock extends React.Component {
           let a = -60 + 30 * i;
           let b = 60 - 30 * i;
           return (
-            <View
+            <View key={i}
               style={{
                 position: 'absolute',
                 transform: [

This issue body was partially generated by patch-package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.