|
1 | 1 | ## react-native-paper-dates |
2 | 2 |
|
3 | | -- Smooth and fast cross platform Material Design date picker for React Native Paper |
| 3 | +- Smooth and fast cross platform Material Design **date** picker and **time** picker for React Native Paper |
4 | 4 | - Tested on Android, iOS and the web platform! |
5 | 5 | - Uses the native Date.Intl API's which work out of the box on the web / iOS |
6 | 6 | - Simple API |
7 | 7 | - Typesafe |
8 | 8 | - Endless scrolling |
9 | 9 | - Performant |
| 10 | +- Great react-native-web support |
10 | 11 |
|
11 | 12 | Older demo of this library |
12 | 13 | <img src="https://user-images.githubusercontent.com/6492229/90681177-4970f280-e263-11ea-8257-6810c5166f92.gif"/> |
@@ -117,11 +118,69 @@ export default function RangeDatePage() { |
117 | 118 | ``` |
118 | 119 |
|
119 | 120 |
|
| 121 | +### Time picker |
| 122 | +```tsx |
| 123 | +import * as React from 'react' |
| 124 | +import { Button } from 'react-native-paper' |
| 125 | +import { TimePickerModal } from 'react-native-paper-dates' |
| 126 | + |
| 127 | +export default function RangeDatePage() { |
| 128 | + const [visible, setVisible] = React.useState(false) |
| 129 | + const onDismiss = React.useCallback(() => { |
| 130 | + setVisible(false) |
| 131 | + }, [setVisible]) |
| 132 | + |
| 133 | + const onConfirm = React.useCallback( |
| 134 | + ({ hours, minutes }) => { |
| 135 | + setVisible(false); |
| 136 | + console.log({ hours, minutes }); |
| 137 | + }, |
| 138 | + [setVisible] |
| 139 | + ); |
| 140 | + |
| 141 | + |
| 142 | + return ( |
| 143 | + <> |
| 144 | + <TimePickerModal |
| 145 | + visible={visible} |
| 146 | + onDismiss={onDismiss} |
| 147 | + onConfirm={onConfirm} |
| 148 | + label={'Select time'} // optional, default 'Select time' |
| 149 | + cancelLabel="Cancel" // optional, default: 'Cancel' |
| 150 | + confirmLabel="Ok" // optional, default: 'Ok' |
| 151 | + hours={12} // optional, default: current hours |
| 152 | + minutes={14} // optional, default: current minutes |
| 153 | + /> |
| 154 | + <Button onPress={()=> setVisible(true)}> |
| 155 | + Pick time |
| 156 | + </Button> |
| 157 | + </> |
| 158 | + ) |
| 159 | +} |
| 160 | +``` |
| 161 | + |
| 162 | + |
| 163 | + |
| 164 | + |
| 165 | + |
120 | 166 |
|
121 | 167 | ## Roadmap |
122 | | -Things on our roadmap are labeled with enhancement. |
| 168 | +Things on our roadmap have labels with `enhancement`. |
123 | 169 | https://github.com/web-ridge/react-native-paper-dates/issues |
124 | 170 |
|
| 171 | +## Tips & Tricks |
| 172 | +- Use 0.14+ version of React-Native-Web |
| 173 | +- Try to avoid putting the pickers inside of a scrollView |
| 174 | +If that is **not possible** use the following props on the surrounding ScrollViews/Flatlists |
| 175 | + |
| 176 | +```javascript |
| 177 | + keyboardDismissMode="on-drag" |
| 178 | + keyboardShouldPersistTaps="handled" |
| 179 | + contentInsetAdjustmentBehavior="always" |
| 180 | +``` |
| 181 | +This is to prevent the need to press 2 times before save works (1 press for closing keyboard, 1 press for confirm/close) |
| 182 | +(https://github.com/facebook/react-native/issues/10138) |
| 183 | + |
125 | 184 | ## Android Caveats |
126 | 185 |
|
127 | 186 | You will need to add a polyfill for the Intl API on Android if: |
|
0 commit comments