Skip to content

Commit ac99256

Browse files
authored
Support dark theme by default (#547)
1 parent 76ce31b commit ac99256

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from 'react'
2-
import { Platform } from 'react-native'
2+
import { Platform, Appearance } from 'react-native'
33
import DatePickerIOS from './DatePickerIOS'
44
import DatePickerAndroid from './DatePickerAndroid'
55
import propTypes from './propTypes'
@@ -19,7 +19,8 @@ const DatePickerWrapper = (props) => {
1919
<DatePicker
2020
ref={props.innerRef}
2121
{...props}
22-
textColor={colorToHex(props.textColor)}
22+
textColor={colorToHex(getTextColor(props))}
23+
theme={getTheme(props)}
2324
fadeToColor={colorToHex(props.fadeToColor)}
2425
title={getTitle(props)}
2526
confirmText={props.confirmText ? props.confirmText : 'Confirm'}
@@ -31,6 +32,19 @@ const DatePickerWrapper = (props) => {
3132
)
3233
}
3334

35+
const getTheme = (props) => {
36+
if (props.theme) return props.theme
37+
if (!Appearance) return 'auto'
38+
return Appearance.getColorScheme()
39+
}
40+
41+
const getTextColor = (props) => {
42+
if (props.textColor) return props.textColor
43+
const darkTheme = getTheme(props) === 'dark'
44+
if (darkTheme) return 'white'
45+
return undefined
46+
}
47+
3448
const getAndroidVariant = (props) => {
3549
const { modal, androidVariant } = props
3650
if (androidVariant) return androidVariant

0 commit comments

Comments
 (0)