react-native-smart-date-picker
v0.1.0
Published
A lightweight, customizable React Native wheel-style date and datetime picker with identical UI on iOS and Android.
Downloads
5
Maintainers
Readme
react-native-smart-date-picker
A lightweight, customizable React Native wheel-style date and datetime picker with a consistent UI on iOS and Android.
Features
- Wheel columns for day, month, year, hour, and minute
- Modes:
date,time,datetime(date then time) - Optional center selection overlay row
- Initial value support and min/max date clamping
- Theme and style customization via props
- Custom row height with
itemHeight
Installation
Install in your React Native project:
npm install react-native-smart-date-pickerPeer dependencies: react and react-native (see package.json).
Usage
Basic example (date then time flow):
import React, { useState } from 'react';
import SmartDatePicker from 'react-native-smart-date-picker';
function Example() {
const [pickerVisible, setPickerVisible] = useState(false);
const [selectedDate, setSelectedDate] = useState(new Date());
return (
<>
<Button title="Open" onPress={() => setPickerVisible(true)} />
<SmartDatePicker
visible={pickerVisible}
value={selectedDate}
mode="datetime" // "date" | "time" | "datetime"
onCancel={() => setPickerVisible(false)}
onConfirm={(date) => {
setSelectedDate(date);
setPickerVisible(false);
console.log('Selected Date:', date);
}}
/>
</>
);
}Time-only example
<SmartDatePicker visible={true} mode="time" onConfirm={...} onCancel={...} />Date-only example
<SmartDatePicker visible={true} mode="date" onConfirm={...} onCancel={...} />Theme example
<SmartDatePicker
visible={pickerVisible}
value={selectedDate}
mode="datetime"
theme={{
primaryColor: '#0f766e',
backgroundColor: '#f8fafc',
wheelBackgroundColor: '#ffffff',
textColor: '#111827',
buttonTextColor: '#0f766e',
}}
onCancel={() => setPickerVisible(false)}
onConfirm={(date) => {
setSelectedDate(date);
setPickerVisible(false);
}}
/>Behavior
- In
datetimemode, the picker shows the date wheels first and then transitions to time selection. - In
datemode, the picker renders day/month/year wheels only. - In
timemode, the picker renders hour/minute wheels only. valueis clamped tominimumDate/maximumDatebefore confirmation.showSelectionOverlaydefaults totrueand renders a centered highlight bar.- The modal slides up from the bottom using React Native
Modal.
Props
Required
visible: boolean— whether the picker is visibleonConfirm: (date: Date) => void— called when the user taps DoneonCancel: () => void— called when the user taps Cancel
Core picker props
mode?: 'date' | 'time' | 'datetime'— which wheel UI to show (default:datetime)value?: Date— initial selected date/time (defaults tonew Date())minimumDate?: Date— earliest selectable date/timemaximumDate?: Date— latest selectable date/timeshowSelectionOverlay?: boolean— display the center selection overlay row (default:true)itemHeight?: number— custom row height for wheel items
Theme and styling
theme?: Partial<SmartDatePickerTheme>— partial theme object for colorscustomTheme?: SmartDatePickerTheme— full theme object replacing default theme valuesminDateTheme?: Partial<SmartDatePickerTheme>— theme overrides when the selected date equalsminimumDatemaxDateTheme?: Partial<SmartDatePickerTheme>— theme overrides when the selected date equalsmaximumDateprimaryColor?: stringbackgroundColor?: stringtextColor?: stringbuttonTextColor?: stringoverlayBorderColor?: stringdisabledTextColor?: stringselectionOverlayColor?: stringheaderBackgroundColor?: stringwheelBackgroundColor?: string
Style overrides
containerStyle?: ViewStyle— style for the modal containerwheelStyle?: ViewStyle— style for the wheel columnsoverlayStyle?: ViewStyle— style for the picker panel / overlaytextStyle?: TextStyle— style for all wheel labelsselectedTextStyle?: TextStyle— style for the selected wheel label
See src/types/index.ts for the full TypeScript interface.
Development
Build the library locally:
npm install
npm run buildFor development with live compile:
npm run watchTypeScript / Editor notes
- If your editor shows "Cannot use JSX unless the '--jsx' flag is provided", ensure
tsconfig.jsoncontains"jsx": "react-jsx"and restart the TypeScript server in VS Code: Command Palette →TypeScript: Restart TS Server.
License
MIT
