web-ridge / react-native-paper-dates

Smooth and fast cross platform Material Design date and time picker for React Native Paper
https://www.reactnativepaperdates.com
MIT License
654 stars 170 forks source link

[BUG] Failure to open modal on Android (Can't find variable: Intl) #153

Closed MartijnGevaert closed 2 years ago

MartijnGevaert commented 2 years ago

Greetings,

I noticed a bug where on Android, a Render error is thrown on react-native 0.67.4. I'm not using Hermes, but I am above RN 0.66 https://snack.expo.dev/okpH8pb3C image It does work on web.

MartijnGevaert commented 2 years ago

The issue was fixed by code importing below. Unfortunate that this requires such a large number of dependencies to add to package.json

Maybe this can be made clearer in the Readme? Or will this step no longer be needed in future releases?

(modified for nl language)

if (Platform.OS === 'android') {
  // this line is only needed if you don't use an .android.js file

  require('@formatjs/intl-getcanonicallocales/polyfill');
  require('@formatjs/intl-locale/polyfill');

  require('@formatjs/intl-pluralrules/polyfill');
  require('@formatjs/intl-pluralrules/locale-data/nl.js'); // USE YOUR OWN LANGUAGE OR MULTIPLE IMPORTS YOU WANT TO SUPPORT

  require('@formatjs/intl-displaynames/polyfill');
  require('@formatjs/intl-displaynames/locale-data/nl.js'); // USE YOUR OWN LANGUAGE OR MULTIPLE IMPORTS YOU WANT TO SUPPORT

  require('@formatjs/intl-listformat/polyfill');
  require('@formatjs/intl-listformat/locale-data/nl.js'); // USE YOUR OWN LANGUAGE OR MULTIPLE IMPORTS YOU WANT TO SUPPORT

  require('@formatjs/intl-numberformat/polyfill');
  require('@formatjs/intl-numberformat/locale-data/nl.js'); // USE YOUR OWN LANGUAGE OR MULTIPLE IMPORTS YOU WANT TO SUPPORT

  require('@formatjs/intl-relativetimeformat/polyfill');
  require('@formatjs/intl-relativetimeformat/locale-data/nl.js'); // USE YOUR OWN LANGUAGE OR MULTIPLE IMPORTS YOU WANT TO SUPPORT

  require('@formatjs/intl-datetimeformat/polyfill');
  require('@formatjs/intl-datetimeformat/locale-data/nl.js'); // USE YOUR OWN LANGUAGE OR MULTIPLE IMPORTS YOU WANT TO SUPPORT

  require('@formatjs/intl-datetimeformat/add-golden-tz.js');
}
RichardLindhout commented 2 years ago

You should upgrade & use Hermes on Android, no polyfills are needed then. Intl works there for all languages without bigger binary because it uses underlying platform

RichardLindhout commented 2 years ago

Hermes also have great speed improvements on Android devices!

MartijnGevaert commented 2 years ago

This worked, thanks, I didn't use Hermes before because it breaks the android debugger on VScode in my project.