Skip to content

Commit

Permalink
Switch date picker libraries (#3126)
Browse files Browse the repository at this point in the history
* Revert other base PR changes, switch date picker library

rm expo-linear-gradient

Revert "remove unused packages, switch to `expo-linear-gradient`"

This reverts commit 20a0ffc

Revert "upgrade expo deps"

This reverts commit a43dca9.

Revert other library changes

This reverts commit 5219f66

Revert "re-add normalize-url"

This reverts commit 654019c.

Revert "add `expo-haptics`"

This reverts commit ff3a039.

Revert "add `expo-clipboard`"

This reverts commit 440ae91.

Revert "add `expo-file-system`"

This reverts commit c0fe0c9.

fix android alf

use modal on android

migrate to `react-native-date-picker`

rm `@reactnativecommunity/datetimepicker`

add `react-native-date-picker`

add `expo-file-system`

add `expo-clipboard`

add `expo-haptics`

re-add normalize-url

rm blur view

upgrade expo deps

remove unused packages, switch to `expo-linear-gradient`

* rm old library

* Use UTC for dates

---------

Co-authored-by: Eric Bailey <[email protected]>
  • Loading branch information
haileyok and estrattonbailey authored Mar 6, 2024
1 parent b8f36a8 commit 2d9a5db
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 56 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
"@react-native-camera-roll/camera-roll": "^5.2.2",
"@react-native-clipboard/clipboard": "^1.10.0",
"@react-native-community/blur": "^4.3.0",
"@react-native-community/datetimepicker": "7.6.1",
"@react-native-masked-view/masked-view": "0.3.0",
"@react-native-menu/menu": "^0.8.0",
"@react-native-picker/picker": "2.6.1",
Expand Down Expand Up @@ -152,6 +151,7 @@
"react-keyed-flatten-children": "^3.0.0",
"react-native": "0.73.2",
"react-native-appstate-hook": "^1.0.6",
"react-native-date-picker": "^4.4.0",
"react-native-drawer-layout": "^4.0.0-alpha.3",
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "~2.14.0",
Expand Down
39 changes: 19 additions & 20 deletions src/components/forms/DateField/index.android.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React from 'react'
import {View, Pressable} from 'react-native'
import DateTimePicker, {
BaseProps as DateTimePickerProps,
} from '@react-native-community/datetimepicker'

import {useTheme, atoms} from '#/alf'
import {Text} from '#/components/Typography'
Expand All @@ -15,6 +12,8 @@ import {
localizeDate,
toSimpleDateString,
} from '#/components/forms/DateField/utils'
import DatePicker from 'react-native-date-picker'
import {isAndroid} from 'platform/detection'

export * as utils from '#/components/forms/DateField/utils'
export const Label = TextField.Label
Expand All @@ -38,20 +37,20 @@ export function DateField({
const {chromeFocus, chromeError, chromeErrorHover} =
TextField.useSharedInputStyles()

const onChangeInternal = React.useCallback<
Required<DateTimePickerProps>['onChange']
>(
(_event, date) => {
const onChangeInternal = React.useCallback(
(date: Date) => {
setOpen(false)

if (date) {
const formatted = toSimpleDateString(date)
onChangeDate(formatted)
}
const formatted = toSimpleDateString(date)
onChangeDate(formatted)
},
[onChangeDate, setOpen],
)

const onCancel = React.useCallback(() => {
setOpen(false)
}, [])

return (
<View style={[atoms.relative, atoms.w_full]}>
<Pressable
Expand Down Expand Up @@ -89,18 +88,18 @@ export function DateField({
</Pressable>

{open && (
<DateTimePicker
<DatePicker
modal={isAndroid}
open={isAndroid}
theme={t.name === 'light' ? 'light' : 'dark'}
date={new Date(value)}
onConfirm={onChangeInternal}
onCancel={onCancel}
mode="date"
testID={`${testID}-datepicker`}
aria-label={label}
accessibilityLabel={label}
accessibilityHint={undefined}
testID={`${testID}-datepicker`}
mode="date"
timeZoneName={'Etc/UTC'}
display="spinner"
// @ts-ignore applies in iOS only -prf
themeVariant={t.name === 'light' ? 'light' : 'dark'}
value={new Date(value)}
onChange={onChangeInternal}
/>
)}
</View>
Expand Down
20 changes: 8 additions & 12 deletions src/components/forms/DateField/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React from 'react'
import {View} from 'react-native'
import DateTimePicker, {
DateTimePickerEvent,
} from '@react-native-community/datetimepicker'

import {useTheme, atoms} from '#/alf'
import * as TextField from '#/components/forms/TextField'
import {toSimpleDateString} from '#/components/forms/DateField/utils'
import {DateFieldProps} from '#/components/forms/DateField/types'
import DatePicker from 'react-native-date-picker'

export * as utils from '#/components/forms/DateField/utils'
export const Label = TextField.Label
Expand All @@ -28,7 +26,7 @@ export function DateField({
const t = useTheme()

const onChangeInternal = React.useCallback(
(event: DateTimePickerEvent, date: Date | undefined) => {
(date: Date | undefined) => {
if (date) {
const formatted = toSimpleDateString(date)
onChangeDate(formatted)
Expand All @@ -39,17 +37,15 @@ export function DateField({

return (
<View style={[atoms.relative, atoms.w_full]}>
<DateTimePicker
<DatePicker
theme={t.name === 'light' ? 'light' : 'dark'}
date={new Date(value)}
onDateChange={onChangeInternal}
mode="date"
testID={`${testID}-datepicker`}
aria-label={label}
accessibilityLabel={label}
accessibilityHint={undefined}
testID={`${testID}-datepicker`}
mode="date"
timeZoneName={'Etc/UTC'}
display="spinner"
themeVariant={t.name === 'light' ? 'light' : 'dark'}
value={new Date(value)}
onChange={onChangeInternal}
/>
</View>
)
Expand Down
2 changes: 1 addition & 1 deletion src/state/queries/preferences/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ export function usePreferencesSetBirthDateMutation() {

return useMutation<void, unknown, {birthDate: Date}>({
mutationFn: async ({birthDate}: {birthDate: Date}) => {
await getAgent().setPersonalDetails({birthDate})
await getAgent().setPersonalDetails({birthDate: birthDate.toISOString()})
// triggers a refetch
await queryClient.invalidateQueries({
queryKey: preferencesQueryKey,
Expand Down
32 changes: 17 additions & 15 deletions src/view/com/util/forms/DateInput.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import React, {useState, useCallback} from 'react'
import {StyleProp, StyleSheet, TextStyle, View, ViewStyle} from 'react-native'
import DateTimePicker, {
DateTimePickerEvent,
} from '@react-native-community/datetimepicker'
import {
FontAwesomeIcon,
FontAwesomeIconStyle,
Expand All @@ -14,6 +11,7 @@ import {TypographyVariant} from 'lib/ThemeContext'
import {useTheme} from 'lib/ThemeContext'
import {usePalette} from 'lib/hooks/usePalette'
import {getLocales} from 'expo-localization'
import DatePicker from 'react-native-date-picker'

const LOCALE = getLocales()[0]

Expand Down Expand Up @@ -43,11 +41,9 @@ export function DateInput(props: Props) {
}, [props.handleAsUTC])

const onChangeInternal = useCallback(
(event: DateTimePickerEvent, date: Date | undefined) => {
(date: Date) => {
setShow(false)
if (date) {
props.onChange(date)
}
props.onChange(date)
},
[setShow, props],
)
Expand All @@ -56,6 +52,10 @@ export function DateInput(props: Props) {
setShow(true)
}, [setShow])

const onCancel = useCallback(() => {
setShow(false)
}, [])

return (
<View>
{isAndroid && (
Expand All @@ -80,15 +80,17 @@ export function DateInput(props: Props) {
</Button>
)}
{(isIOS || show) && (
<DateTimePicker
testID={props.testID ? `${props.testID}-datepicker` : undefined}
<DatePicker
timeZoneOffsetInMinutes={0}
modal={isAndroid}
open={isAndroid}
theme={theme.colorScheme}
date={props.value}
onDateChange={onChangeInternal}
onConfirm={onChangeInternal}
onCancel={onCancel}
mode="date"
timeZoneName={props.handleAsUTC ? 'Etc/UTC' : undefined}
display="spinner"
// @ts-ignore applies in iOS only -prf
themeVariant={theme.colorScheme}
value={props.value}
onChange={onChangeInternal}
testID={props.testID ? `${props.testID}-datepicker` : undefined}
accessibilityLabel={props.accessibilityLabel}
accessibilityHint={props.accessibilityHint}
accessibilityLabelledBy={props.accessibilityLabelledBy}
Expand Down
12 changes: 5 additions & 7 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4986,13 +4986,6 @@
prompts "^2.4.2"
semver "^7.5.2"

"@react-native-community/[email protected]":
version "7.6.1"
resolved "https://registry.yarnpkg.com/@react-native-community/datetimepicker/-/datetimepicker-7.6.1.tgz#98bdee01e3df490526ee1125e438c2030becac1f"
integrity sha512-g66Q2Kd9Uw3eRL7kkrTsGhi+eXxNoPDRFYH6z78sZQuYjPkUQgJDDMUYgBmaBsQx/fKMtemPrCj1ulGmyi0OSw==
dependencies:
invariant "^2.2.4"

"@react-native-community/eslint-config@^3.0.0":
version "3.2.0"
resolved "https://registry.yarnpkg.com/@react-native-community/eslint-config/-/eslint-config-3.2.0.tgz#42f677d5fff385bccf1be1d3b8faa8c086cf998d"
Expand Down Expand Up @@ -18563,6 +18556,11 @@ react-native-appstate-hook@^1.0.6:
resolved "https://registry.yarnpkg.com/react-native-appstate-hook/-/react-native-appstate-hook-1.0.6.tgz#cbc16e7b89cfaea034cabd999f00e99053cabd06"
integrity sha512-0hPVyf5yLxCSVrrNEuGqN1ZnSSj3Ye2gZex0NtcK/AHYwMc0rXWFNZjBKOoZSouspqu3hXBbQ6NOUSTzrME1AQ==

react-native-date-picker@^4.4.0:
version "4.4.0"
resolved "https://registry.yarnpkg.com/react-native-date-picker/-/react-native-date-picker-4.4.0.tgz#fe5b6eb8d85a4a30b2991ada5169a30ce5023ead"
integrity sha512-Axx3byihwwhKRLRVjPAr/UaEysapkRcKmjjM8/05UaVm4Q0xDn2RFUcRdy1QAahhRcjLjlVYhepxvU5bdgy7ZQ==

react-native-dotenv@^3.3.1:
version "3.4.9"
resolved "https://registry.yarnpkg.com/react-native-dotenv/-/react-native-dotenv-3.4.9.tgz#621c5b0c1d0c5c7f569bfe5a1d804bec7885c010"
Expand Down

0 comments on commit 2d9a5db

Please sign in to comment.