在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):web-ridge/react-native-paper-dates开源软件地址(OpenSource Url):https://github.com/web-ridge/react-native-paper-dates开源编程语言(OpenSource Language):TypeScript 96.2%开源软件介绍(OpenSource Introduction):react-native-paper-dates
View video in better frame on YouTube Web demo: reactnativepaperdates.com About usWe want developers to be able to build software faster using modern tools like GraphQL, Golang and React Native. Give us a follow on Twitter: RichardLindhout, web_ridge DonatePlease contribute or donate so we can spend more time on this library Getting startedFirst install and follow the guides at react-native-paper Yarn
npm
Import some localized stringsIdeally you do this somewhere in your // e.g in your index.js
import {
// en,
// nl,
// de,
// pl,
// pt,
enGB,
registerTranslation,
} from 'react-native-paper-dates'
// registerTranslation('en', en)
// registerTranslation('nl', nl)
// registerTranslation('pl', pl)
// registerTranslation('pt', pt)
// registerTranslation('de', de)
registerTranslation('en-GB', enGB) or register your ownPlease send a PR with your language to make sure all locales are there next time import {
registerTranslation,
} from 'react-native-paper-dates'
registerTranslation("pl", {
save: 'Save',
selectSingle: 'Select date',
selectMultiple: 'Select dates',
selectRange: 'Select period',
notAccordingToDateFormat: (inputFormat) =>
`Date format must be ${inputFormat}`,
mustBeHigherThan: (date) => `Must be later then ${date}`,
mustBeLowerThan: (date) => `Must be earlier then ${date}`,
mustBeBetween: (startDate, endDate) =>
`Must be between ${startDate} - ${endDate}`,
dateIsDisabled: 'Day is not allowed',
previous: 'Previous',
next: 'Next',
typeInDate: 'Type in date',
pickDateFromCalendar: 'Pick date from calendar',
close: 'Close',
}) UsageSingle date Picker (modal)import * as React from 'react';
import { Button } from 'react-native-paper';
import { DatePickerModal } from 'react-native-paper-dates';
export default function ReadMeExampleSingle() {
const [date, setDate] = React.useState<Date | undefined>(undefined);
const [open, setOpen] = React.useState(false);
const onDismissSingle = React.useCallback(() => {
setOpen(false);
}, [setOpen]);
const onConfirmSingle = React.useCallback(
(params) => {
setOpen(false);
setDate(params.date);
},
[setOpen, setDate]
);
return (
<>
<Button onPress={() => setOpen(true)} uppercase={false} mode="outlined">
Pick single date
</Button>
<DatePickerModal
locale="en"
mode="single"
visible={open}
onDismiss={onDismissSingle}
date={date}
onConfirm={onConfirmSingle}
// validRange={{
// startDate: new Date(2021, 1, 2), // optional
// endDate: new Date(), // optional
// disabledDates: [new Date()] // optional
// }}
// onChange={} // same props as onConfirm but triggered without confirmed by user
// saveLabel="Save" // optional
// uppercase={false} // optional, default is true
// label="Select date" // optional
// animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
/>
</>
);
} Range picker (modal)import * as React from 'react';
import { Button } from 'react-native-paper';
import { DatePickerModal } from 'react-native-paper-dates';
export default function ReadMeExampleRange() {
const [range, setRange] = React.useState<{
startDate: Date | undefined;
endDate: Date | undefined;
}>({ startDate: undefined, endDate: undefined });
const [open, setOpen] = React.useState(false);
const onDismiss = React.useCallback(() => {
setOpen(false);
}, [setOpen]);
const onConfirm = React.useCallback(
({ startDate, endDate }) => {
setOpen(false);
setRange({ startDate, endDate });
},
[setOpen, setRange]
);
return (
<>
<Button onPress={() => setOpen(true)} uppercase={false} mode="outlined">
Pick range
</Button>
<DatePickerModal
locale="en"
mode="range"
visible={open}
onDismiss={onDismiss}
startDate={range.startDate}
endDate={range.endDate}
onConfirm={onConfirm}
// validRange={{
// startDate: new Date(2021, 1, 2), // optional
// endDate: new Date(), // optional
// disabledDates: [new Date()] // optional
// }}
// onChange={} // same props as onConfirm but triggered without confirmed by user
// saveLabel="Save" // optional
// uppercase={false} // optional, default is true
// label="Select period" // optional
// startLabel="From" // optional
// endLabel="To" // optional
// animationType="slide" // optional, default is slide on ios/android and none on web
/>
</>
);
} Multiple dates pickerimport * as React from 'react';
import { Button } from 'react-native-paper';
import { DatePickerModal } from 'react-native-paper-dates';
export default function ReadMeExampleMultiple() {
const [dates, setDates] = React.useState<Date[] | undefined>();
const [open, setOpen] = React.useState(false);
const onDismiss = React.useCallback(() => {
setOpen(false);
}, [setOpen]);
const onConfirm = React.useCallback((params) => {
setOpen(false);
setDates(params.dates);
console.log('[on-change-multi]', params);
}, []);
return (
<>
<Button onPress={() => setOpen(true)} uppercase={false} mode="outlined">
Pick multiple dates
</Button>
<DatePickerModal
locale="en"
mode="multiple"
visible={open}
onDismiss={onDismiss}
dates={dates}
onConfirm={onConfirm}
// moreLabel="More"
// validRange={{
// startDate: new Date(2021, 1, 2), // optional
// endDate: new Date(), // optional
// disabledDates: [new Date()] // optional
// }}
// saveLabel="Save" // optional
// uppercase={false} // optional, default is true
// label="Select period" // optional
// startLabel="From" // optional
// endLabel="To" // optional
// animationType="slide" // optional, default is slide on ios/android and none on web
/>
</>
);
} Input date with modal buttonexport default function ReadMeExampleDatePickerInput() {
const [inputDate, setInputDate] = React.useState<Date | undefined>(undefined)
return (
<>
<DatePickerInput
locale="en"
label="Birthdate"
value={inputDate}
onChange={(d) => setInputDate(d)}
inputMode="start"
// mode="outlined" (see react-native-paper docs)
// other react native TextInput props
/>
</>
)
} Time pickerimport * as React from 'react'
import { Button } from 'react-native-paper'
import { TimePickerModal } from 'react-native-paper-dates'
export default function TimePickerPage() {
const [visible, setVisible] = React.useState(false)
const onDismiss = React.useCallback(() => {
setVisible(false)
}, [setVisible])
const onConfirm = React.useCallback(
({ hours, minutes }) => {
setVisible(false);
console.log({ hours, minutes });
},
[setVisible]
);
return (
<>
<TimePickerModal
visible={visible}
onDismiss={onDismiss}
onConfirm={onConfirm}
hours={12} // default: current hours
minutes={14} // default: current minutes
label="Select time" // optional, default 'Select time'
uppercase={false} // optional, default is true
cancelLabel="Cancel" // optional, default: 'Cancel'
confirmLabel="Ok" // optional, default: 'Ok'
animationType="fade" // optional, default is 'none'
locale="en" // optional, default is automically detected by your system
/>
<Button onPress={()=> setVisible(true)}>
Pick time
</Button>
</>
)
} RoadmapThings on our roadmap have labels with Tips & Tricks
keyboardDismissMode="on-drag"
keyboardShouldPersistTaps="handled"
contentInsetAdjustmentBehavior="always" This is to prevent the need to press 2 times before save or close button in modal works (1 press for closing keyboard, 1 press for confirm/close) React Native Issue: #10138 Android CaveatsWe recommend Hermes with React Native >= 0.66 you won't need these polyfills at all! Below React Native 0.66You will need to add a polyfill for the Intl API on Android if:
Install polyfills with Yarn
or npm
If using Expo, omit In your app starting entrypoint e.g. 全部评论
专题导读
热门推荐
热门话题
阅读排行榜
|
请发表评论