Skip to content

Commit 9e48b21

Browse files
Bugfixes + documentation
2 parents 71afa3a + be995a4 commit 9e48b21

File tree

4 files changed

+46
-30
lines changed

4 files changed

+46
-30
lines changed

README.md

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,9 @@ function SingleDatePage() {
6666
onDismiss={onDismiss}
6767
date={date}
6868
onConfirm={onChange}
69-
saveLabel={'Save'} // optional
70-
label={'Select period'} // optional
69+
saveLabel="Save" // optional
70+
label="Select date" // optional
71+
animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
7172
/>
7273
<Button onPress={()=> setVisible(true)}>
7374
Pick date
@@ -98,16 +99,17 @@ export default function RangeDatePage() {
9899
return (
99100
<>
100101
<DatePickerModal
101-
mode="range"
102-
visible={visible}
103-
onDismiss={onDismiss}
104-
startDate={undefined}
105-
endDate={undefined}
106-
onConfirm={onChange}
107-
saveLabel={'Save'} // optional
108-
label={'Select period'} // optional
109-
startLabel={'From'} // optional
110-
endLabel={'To'} // optional
102+
mode="range"
103+
visible={visible}
104+
onDismiss={onDismiss}
105+
startDate={undefined}
106+
endDate={undefined}
107+
onConfirm={onChange}
108+
saveLabel="Save" // optional
109+
label="Select period" // optional
110+
startLabel="From" // optional
111+
endLabel="To" // optional
112+
animationType="slide" // optional, default is slide on ios/android and none on web
111113
/>
112114
<Button onPress={()=> setVisible(true)}>
113115
Pick range
@@ -124,7 +126,7 @@ import * as React from 'react'
124126
import { Button } from 'react-native-paper'
125127
import { TimePickerModal } from 'react-native-paper-dates'
126128

127-
export default function RangeDatePage() {
129+
export default function TimePickerPage() {
128130
const [visible, setVisible] = React.useState(false)
129131
const onDismiss = React.useCallback(() => {
130132
setVisible(false)
@@ -145,11 +147,12 @@ export default function RangeDatePage() {
145147
visible={visible}
146148
onDismiss={onDismiss}
147149
onConfirm={onConfirm}
148-
label={'Select time'} // optional, default 'Select time'
150+
hours={12} // default: current hours
151+
minutes={14} // default: current minutes
152+
label="Select time" // optional, default 'Select time'
149153
cancelLabel="Cancel" // optional, default: 'Cancel'
150154
confirmLabel="Ok" // optional, default: 'Ok'
151-
hours={12} // optional, default: current hours
152-
minutes={14} // optional, default: current minutes
155+
animationType="fade" // optional, default is 'none'
153156
/>
154157
<Button onPress={()=> setVisible(true)}>
155158
Pick time
@@ -169,7 +172,7 @@ Things on our roadmap have labels with `enhancement`.
169172
https://github.com/web-ridge/react-native-paper-dates/issues
170173

171174
## Tips & Tricks
172-
- Use 0.14+ version of React-Native-Web
175+
- Use 0.14+ version of React-Native-Web (Modal and better number input)
173176
- Try to avoid putting the pickers inside of a scrollView
174177
If that is **not possible** use the following props on the surrounding ScrollViews/Flatlists
175178

example/src/App.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,30 +179,33 @@ function App({
179179
startDate={undefined}
180180
endDate={undefined}
181181
onConfirm={onChangeRange}
182-
saveLabel={'Save'} // optional
183-
label={'Select period'} // optional
184-
startLabel={'From'} // optional
185-
endLabel={'To'} // optional
182+
saveLabel="Save" // optional
183+
label="Select period" // optional
184+
startLabel="From" // optional
185+
endLabel="To" // optional
186+
animationType="slide" // optional, default is slide on ios/android and none on web
186187
/>
187188
<DatePickerModal
188189
mode="single"
189190
visible={singleOpen}
190191
onDismiss={onDismissSingle}
191192
date={undefined}
192193
onConfirm={onChangeSingle}
193-
saveLabel={'Save'} // optional
194-
label={'Select date'} // optional
194+
saveLabel="Save" // optional
195+
label="Select date" // optional
196+
animationType="slide" // optional, default is 'slide' on ios/android and 'none' on web
195197
/>
196198

197199
<TimePickerModal
198-
label={'Select time'} // optional, default 'Select time'
199-
cancelLabel="Cancel" // optional, default: 'Cancel'
200-
confirmLabel="Ok" // optional, default: 'Ok'
201-
hours={time.hours} // optional, default: current hours
202-
minutes={time.minutes} // optional, default: current minutes
203200
visible={timeOpen}
204201
onDismiss={onDismissTime}
205202
onConfirm={onConfirmTime}
203+
hours={time.hours} // optional, default: current hours
204+
minutes={time.minutes} // optional, default: current minutes
205+
label="Select time" // optional, default 'Select time'
206+
cancelLabel="Cancel" // optional, default: 'Cancel'
207+
confirmLabel="Ok" // optional, default: 'Ok'
208+
animationType="fade" // optional, default is 'none'
206209
/>
207210
</>
208211
);

src/Date/DatePickerModal.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
TouchableWithoutFeedback,
66
useWindowDimensions,
77
View,
8+
Platform,
89
} from 'react-native'
910

1011
import Calendar, {
@@ -26,6 +27,7 @@ interface DatePickerModalProps extends HeaderPickProps, BaseCalendarProps {
2627
visible: boolean
2728
onDismiss: () => any
2829
inputFormat?: string
30+
animationType?: 'slide' | 'fade' | 'none'
2931
}
3032

3133
export type LocalState = {
@@ -58,6 +60,12 @@ export function DatePickerModal(
5860
const theme = useTheme()
5961
const dimensions = useWindowDimensions()
6062
const { visible, onDismiss, mode, onChange, onConfirm } = props
63+
const animationType =
64+
props.animationType ||
65+
Platform.select({
66+
web: 'none',
67+
default: 'slide',
68+
})
6169
const anyProps = props as any
6270

6371
// use local state to add only onConfirm state changes
@@ -101,7 +109,7 @@ export function DatePickerModal(
101109

102110
return (
103111
<Modal
104-
animationType="slide"
112+
animationType={animationType}
105113
transparent={true}
106114
visible={visible}
107115
onRequestClose={onDismiss}

src/Time/TimePickerModal.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function TimePickerModal({
3838
label = 'Select time',
3939
cancelLabel = 'Cancel',
4040
confirmLabel = 'Ok',
41+
animationType = 'none',
4142
}: {
4243
label?: string
4344
cancelLabel?: string
@@ -47,6 +48,7 @@ export function TimePickerModal({
4748
visible: boolean | undefined
4849
onDismiss: () => any
4950
onConfirm: ({ hours, minutes }: { hours: number; minutes: number }) => any
51+
animationType?: 'slide' | 'fade' | 'none'
5052
}) {
5153
const theme = useTheme()
5254

@@ -90,7 +92,7 @@ export function TimePickerModal({
9092
)
9193
return (
9294
<Modal
93-
animationType="none"
95+
animationType={animationType}
9496
transparent={true}
9597
visible={visible}
9698
onRequestClose={onDismiss}

0 commit comments

Comments
 (0)