Skip to content

Commit 4060bbc

Browse files
Add support for inline date picker
1 parent c718a96 commit 4060bbc

16 files changed

+530
-351
lines changed

example/src/App.tsx

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
View,
77
Linking,
88
Image,
9+
Animated,
910
} from 'react-native';
1011
import {
1112
Title,
@@ -19,7 +20,11 @@ import {
1920
overlay,
2021
Paragraph,
2122
} from 'react-native-paper';
22-
import { DatePickerModal, TimePickerModal } from '../../src';
23+
import {
24+
DatePickerModal,
25+
DatePickerModalContent,
26+
TimePickerModal,
27+
} from '../../src';
2328

2429
function App({
2530
onToggleDarkMode,
@@ -93,6 +98,11 @@ function App({
9398
time.hours !== undefined && timeDate.setHours(time.hours);
9499
time.minutes !== undefined && timeDate.setMinutes(time.minutes);
95100

101+
const backgroundColor =
102+
theme.dark && theme.mode === 'adaptive'
103+
? overlay(3, theme.colors.surface)
104+
: (theme.colors.surface as any);
105+
96106
return (
97107
<>
98108
<ScrollView
@@ -120,15 +130,29 @@ function App({
120130
</Text>
121131
</Paragraph>
122132
</View>
123-
<View
133+
<View style={styles.content}>
134+
<Button
135+
uppercase={false}
136+
mode="contained"
137+
icon="github"
138+
style={styles.twitterButton}
139+
onPress={() =>
140+
Linking.openURL(
141+
'https://github.com/web-ridge/react-native-paper-dates'
142+
)
143+
}
144+
>
145+
GitHub
146+
</Button>
147+
<TwitterFollowButton userName={'RichardLindhout'} />
148+
<TwitterFollowButton userName={'web_ridge'} />
149+
</View>
150+
<Animated.View
124151
style={[
125152
styles.content,
126153
styles.contentShadow,
127154
{
128-
backgroundColor:
129-
theme.dark && theme.mode === 'adaptive'
130-
? overlay(3, theme.colors.surface)
131-
: (theme.colors.surface as any),
155+
backgroundColor,
132156
},
133157
]}
134158
>
@@ -198,24 +222,29 @@ function App({
198222
{/*<DatePickerInput />*/}
199223
{/*<Enter />*/}
200224
{/*<DateRangeInput />*/}
201-
</View>
225+
</Animated.View>
202226
<View style={styles.content}>
203-
<Button
204-
uppercase={false}
205-
mode="contained"
206-
icon="github"
207-
style={styles.twitterButton}
208-
onPress={() =>
209-
Linking.openURL(
210-
'https://github.com/web-ridge/react-native-paper-dates'
211-
)
212-
}
213-
>
214-
GitHub
215-
</Button>
216-
<TwitterFollowButton userName={'RichardLindhout'} />
217-
<TwitterFollowButton userName={'web_ridge'} />
227+
<Title>Inside page</Title>
218228
</View>
229+
<Animated.View
230+
style={[
231+
styles.content,
232+
styles.contentShadow,
233+
styles.contentInline,
234+
{ backgroundColor },
235+
]}
236+
>
237+
<DatePickerModalContent
238+
mode="range"
239+
onDismiss={onDismissRange}
240+
startDate={undefined}
241+
endDate={undefined}
242+
onConfirm={onChangeRange}
243+
/>
244+
</Animated.View>
245+
<Enter />
246+
<Enter />
247+
<Enter />
219248
</ScrollView>
220249
<DatePickerModal
221250
mode="range"
@@ -224,10 +253,10 @@ function App({
224253
startDate={undefined}
225254
endDate={undefined}
226255
onConfirm={onChangeRange}
227-
saveLabel="Save" // optional
228-
label="Select period" // optional
229-
startLabel="From" // optional
230-
endLabel="To" // optional
256+
saveLabel="Opslaan" // optional
257+
label="Selecteer periode" // optional
258+
startLabel="Van" // optional
259+
endLabel="Tot" // optional
231260
// animationType="slide" // optional, default is slide on ios/android and none on web
232261
/>
233262
<DatePickerModal
@@ -281,8 +310,24 @@ export default function AppWithProviders() {
281310
<PaperProvider
282311
theme={
283312
dark
284-
? { ...DarkTheme, roundness: 10 }
285-
: { ...DefaultTheme, roundness: 10 }
313+
? {
314+
...DarkTheme,
315+
roundness: 10,
316+
colors: {
317+
...DarkTheme.colors,
318+
primary: '#F59E00',
319+
accent: '#FBBE5E',
320+
},
321+
}
322+
: {
323+
...DefaultTheme,
324+
roundness: 10,
325+
colors: {
326+
...DefaultTheme.colors,
327+
primary: '#F59E00',
328+
accent: '#FBBE5E',
329+
},
330+
}
286331
}
287332
>
288333
<React.Fragment>
@@ -326,12 +371,16 @@ const styles = StyleSheet.create({
326371
root: { flex: 1 },
327372
content: {
328373
width: '100%',
329-
maxWidth: 450,
374+
maxWidth: 500,
330375
marginTop: 24,
331376
padding: 24,
332377
alignSelf: 'center',
333378
flex: 1,
334379
},
380+
contentInline: {
381+
padding: 0,
382+
height: 600,
383+
},
335384
contentShadow: {
336385
shadowColor: '#000',
337386
shadowOffset: {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"react": "^16.13.1",
6868
"react-dom": "^16.13.1",
6969
"react-native": "0.63.2",
70-
"react-native-paper": "^4.0.1",
70+
"react-native-paper": "^4.5.0",
7171
"react-window": "^1.8.5",
7272
"release-it": "^13.5.8",
7373
"typescript": "^3.8.3"

src/Date/AnimatedCrossView.tsx

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@ import { Animated, StyleSheet, View } from 'react-native'
33
import { useTheme } from 'react-native-paper'
44

55
export default function AnimatedCrossView({
6-
visible,
6+
// visible,
77
collapsed,
88
calendar,
99
calendarEdit,
1010
}: {
1111
calendar: any
1212
calendarEdit: any
13-
visible: boolean
13+
// visible: boolean
1414
collapsed: boolean
1515
}) {
1616
const theme = useTheme()
1717
const calendarOpacity = React.useRef<Animated.Value>(
1818
new Animated.Value(collapsed ? 1 : 0)
1919
)
2020
React.useEffect(() => {
21-
if (visible) {
22-
Animated.timing(calendarOpacity.current, {
23-
toValue: collapsed ? 1 : 0,
24-
duration: 250,
25-
useNativeDriver: true,
26-
}).start()
27-
}
28-
}, [visible, collapsed])
21+
// if (visible) {
22+
Animated.timing(calendarOpacity.current, {
23+
toValue: collapsed ? 1 : 0,
24+
duration: 250,
25+
useNativeDriver: true,
26+
}).start()
27+
// }
28+
}, [collapsed])
2929

3030
return (
3131
<View style={styles.root}>

src/Date/Calendar.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ export type ModeType = 'single' | 'range'
1717

1818
export type ScrollModeType = 'horizontal' | 'vertical'
1919

20-
export type BaseCalendarProps = {
21-
scrollMode?: ScrollModeType
22-
}
23-
2420
export type CalendarDate = Date | undefined
2521

2622
export type RangeChange = (params: {
@@ -30,14 +26,14 @@ export type RangeChange = (params: {
3026

3127
export type SingleChange = (params: { date: CalendarDate }) => any
3228

33-
export interface CalendarRangeProps extends BaseCalendarProps {
29+
export interface CalendarRangeProps {
3430
mode: 'range'
3531
startDate: CalendarDate
3632
endDate: CalendarDate
3733
onChange: RangeChange
3834
}
3935

40-
export interface CalendarSingleProps extends BaseCalendarProps {
36+
export interface CalendarSingleProps {
4137
mode: 'single'
4238
date?: CalendarDate
4339
onChange: SingleChange
@@ -64,8 +60,7 @@ function Calendar(props: CalendarSingleProps | CalendarRangeProps) {
6460
return Color(theme.colors.primary).lighten(0.9).hex()
6561
}, [theme])
6662

67-
const detectedScrollMode = mode === 'range' ? 'vertical' : 'horizontal'
68-
const scrollMode = props.scrollMode ? props.scrollMode : detectedScrollMode
63+
const scrollMode = mode === 'range' ? 'vertical' : 'horizontal'
6964

7065
const [selectedYear, setSelectedYear] = React.useState<number | undefined>(
7166
undefined

src/Date/CalendarEdit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from 'react-native'
88

99
import { CalendarDate, ModeType } from './Calendar'
10-
import { LocalState } from './DatePickerModal'
10+
import { LocalState } from './DatePickerModalContent'
1111
import TextInputWithMask from '../TextInputMask'
1212
import { useTheme } from 'react-native-paper'
1313

0 commit comments

Comments
 (0)