0.0.9 • Published 6 years ago

react-native-swipetimepicker v0.0.9

Weekly downloads
4
License
MIT
Repository
github
Last release
6 years ago

react-native-swipetimepicker

A simple swipe time picker component. Allows to be fully customizable.

alt text

Installation

React Native >= 0.49

yarn add react-native-swipetimepicker

Attributes

PropDescriptionDefault
string backgroundColorSpecifies the background color of the component#828186
string borderColorSpecifies the border color of the componentundefined
number borderWidthSpecifies the border width of the componentundefined
number borderRadiusSpecifies the border radius of the component3
string textColorThe text color used when strings are rendered#ffffff
number fontSizeThe font size of the textauto
string fontFamilyThe font family for the textundefined
object styleA standard style object that is applied to the main viewundefined
object styleHoursA standard style object that is applied to the hours boxundefined
object styleMinutesA standard style object that is applied to the minutes boxundefined
object styleAMPMA standard style object that is applied to the AMPM boxundefined
number sizeThe size of the hour and minute box.100
number sizeAMPMThe size of the AMPM box.60%
array customHoursAn array containing custom hours definitions.120
array customMinutesAn array containing custom minute definitions.120
bool is24Indicates 24h or 12h time formatfalse
number spacingSpacing between each box5
number minuteMultiplierThe multiplier to be used for minutes. Refer to the examples below.1
any timeA Date Object or String indicating the to be used initial time.undefined

Events

PropDescription
onChangeExecuted when the time was changed.

The onChange event returns the following data structure:

{
  "hour": (integer) the value of the hour,
  "minute": (integer) the value of the minute,
  "ampm": (boolean) TRUE for PM and FALSE for AM,
  "text": (string) A prepared time string, e.g. 12:15AM or 17:30
  "time": (date) A JavaScript date object containing the time,
  "timevalue": (timestamp) The timestamp value of the time
}

Using the Minute Multiplier

The Minute Multiplier is a powerful number allowing to set various minute abstractions.

Examples:

A minuteMultiplier of 1 is displaying minutes from 0 - 59.

A minuteMultiplier of 15 is displaying each quarter minute (15, 30, 45)

A minuteMultiplier of 5 is displaying the minutes every 5 minute (5, 10, 15, 20, ...)

Examples

Import the component:

import SwipeTimePicker from 'react-native-swipetimepicker';

Simple Example

<SwipeTimePicker
    onChange={(time) => console.log(time, time.text)}
/>

Initial Time

<SwipeTimePicker
    time={new Date()}
    onChange={(time) => console.log(time, time.text)}
/>
<SwipeTimePicker
    time={'17:30'}
    is24={true}
    onChange={(time) => console.log(time, time.text)}
/>

Minute Multiplier

<SwipeTimePicker
    minuteMultiplier={15}
    onChange={(time) => console.log(time, time.text)}
/>

Rounded

alt text

<SwipeTimePicker
    size={120}
    borderRadius={120}
    backgroundColor={'#5cb85c'}
    onChange={(time) => console.log(time, time.text)}
/>

Advanced Example

<SwipeTimePicker
    minuteMultiplier={5}
    size={80}
    sizeAMPM={40}
    backgroundColor={'red'}
    borderColor={'black'}
    borderWidth={3}
    styleAMPM={{backgroundColor: 'green'}}
    spacing: 10,
    onChange={(time) => console.log(time, time.text)}
/>