henninghall / react-native-date-picker

React Native Date Picker is datetime picker for Android and iOS. It includes date, time and datetime picker modes. The datepicker is customizable and is supporting different languages. It's written with native code to achieve the best possible look, feel and performance.
MIT License
2.25k stars 346 forks source link

[LANGUAGES INCOMPATIBILITY] Specific languages incompatibility : picker bug with some iso codes #723

Closed Mgxcx closed 1 year ago

Mgxcx commented 1 year ago

Describe the bug The picker doesn't show anything with some languages iso code... (iOS switch automatically to device's language if iso isn't working but with android there is an UI bug...)

Expected behavior Must work for any languages please !!

To reproduce

  <RNDatePicker.default
    androidVariant={'iosClone'}
    date={date}
    fadeToColor={'none'}
    is24hourSource={'locale'}
    locale={
      Platform.OS === 'ios'
        ? lngPhraseToShortISO(i18n.getCurrentLanguage(), i18n.getDeviceLanguage())
        : lngPhraseToISOForLocaleHourInPickerAndroid(
            i18n.getCurrentLanguage(),
            i18n.getDeviceLanguage(),
          )
    }
    maximumDate={isTimeMode ? undefined : new Date()}
    mode={isTimeMode ? 'time' : 'date'}
    onDateChange={onDateChange}
    testID="_datePicker"
    textColor={isTimeMode ? (theme.scheme === 'dark' ? 'white' : 'black') : 'white'}
  />

Temporarily android fix (switch in 24h format) :

export const lngPhraseToISOForLocaleHourInPickerAndroid = (
  lngPhrase: string,
  fallbackLng: string,
): string => {
  const lngIso = languagesISOPhrase.find(
    (p) => p.phrase.toLowerCase() === lngPhrase?.toLowerCase(),
  )?.iso
  const lngFakeIso = languagesISOPhrase.find(
    (p) => p.phrase.toLowerCase() === lngPhrase?.toLowerCase(),
  )?.isFakeIso
  const need24HFormat = languagesISOPhrase.find(
    (p) => p.phrase.toLowerCase() === lngPhrase?.toLowerCase(),
  )?.need24HFormatInHourPickerAndroid
  return lngIso?.length && !lngFakeIso && !need24HFormat
    ? lngIso?.toLowerCase()
    : need24HFormat
    ? 'fr'
    : fallbackLng
}

Smartphone (please complete the following information):

Capture d’écran 2023-11-10 à 11 59 34
Mgxcx commented 1 year ago

Issue n'est plus présente sur la dernière version