How to have Luxon's Intl API working in React-Native
Asked Answered
G

1

9

I've been using Luxon for quite sometime as a replacement for moment, being light weight and an overall great documentation, I've now bumped into a case where I needed to use luxon's toFormat function to write the date month name.

Now this problem only occurs in Android and not in iOS, I'm assuming because some of the javascript in iOS also comes from Safari, and the browser does support Luxon's Intl API.

Basically my question is how do you make Luxon's Intl Api work on Android?

React-Native version: 0.62.2

Gerik answered 24/4, 2020 at 12:13 Comment(0)
G
11

So while I was writting my question I was still reading luxon's documentation and searching for any possible solution.

From Luxon's docs I was redirected to JSC Android Buildscripts

Which at first sight looked like a promising solution, while at the same time I had found an issue that was reported in react-native's github Fresh Install Android Broken on React Native 0.60 RC2

And basically by reading both sides I found that in the app/build.gradle file there's a variable called jscFlavor, which literally states

For example, to use the international variant, you can use:

def jscFlavor = 'org.webkit:android-jsc-intl:+'

Basically by changing the jscFlavor to 'org.webkit:android-jsc-intl:+' I was able to have Intl working in Android with Luxon

Gerik answered 24/4, 2020 at 12:13 Comment(3)
But that means you can't use RN Hermes correct?Gully
Looks like Intl ships with Hermes by default starting RN 0.65: github.com/facebook/hermes/issues/23#issuecomment-816126715Recover
Which Expo SDK 44 doesn't support, so we have to wait for SDK 45 and see what version it supports.Bornie

© 2022 - 2024 — McMap. All rights reserved.