Closed pcarion closed 8 years ago
I agree, the country data file is huge and a local copy of the file containing only the necessary data would be a big improvement. Maybe we could add some functionality to provide your own data as well. Not everyone needs the currency or all translations for example. Some might not even need all countries (Antartica for example doesn't even have a calling code if I'm not mistaken).
I started to work on such a converter... I am generating a file like this:
'use strict';
module.exports = {
"AD": {
"flagImage": "data:image/png;base64,iVBORw <from countries.json> Jggg==",
"currency": "EUR",
"callingCode": "376",
"name": {
"cym": "Andorra",
"deu": "Andorra",
"fra": "Andorre",
"hrv": "Andora",
"ita": "Andorra",
"jpn": "アンドラ",
"nld": "Andorra",
"por": "Andorra",
"rus": "Андорра",
"spa": "Andorra",
"fin": "Andorra"
}
},
Trying to see how I could escape the names to be more robust.
I also think that a country code of 2 characters instead of 3 for the translations would be more useful...
Good point. Speed and efficiency is very important for a basic component like a country picker. I think we should default include the bare minimum but make extra features possible. Can we use the unicode flags instead of the large base64 encoded images?
+1 for a 2 char country code for translation.
Unicode flags would be a nice improvement. However, on Android, unicode flags are only supported since Lollipop. Half of the Android users still use older versions, hence I don't think unicode flags are a solid solution at the moment.
Ah ok, but we can then use Platform.version to discover this and include base64 strings as legacy option?
Hello @pcarion, thank you and I agree !
Do you have a js script file to make the new countries.js
file ?
If so, could you make a PR with your script ?
See my PR #29 :)
Improve here #29
Let me expose here a concern I have with the memory usage of the
CountryPicker
component and I am OK to tackle this issue and submit a PR if you think it is a valid concern.Currently, you load the
countries.json
file from theworld_country
npm module, to get extra data from the selected country.This file is big (
444K
) and it may be a waste of space considering that very few piece of information is needed from the file:You already have a configuration file of yours (
countryFlags.js
) to store the image of the flags.My suggestion would be to parse (offline) the
countries.json
and generate a localcountryInfo.js
file, that would be stored in your repo (with proper attribution to the author ofworld_country
) with only the information needed in the context of your app.This would require a few changes in the code (such as
orderCountryList
andgetCountry
) but nothing major and the footprint of the component in memory would be much smaller...