File tree Expand file tree Collapse file tree 2 files changed +33
-2
lines changed
packages/react-native/src Expand file tree Collapse file tree 2 files changed +33
-2
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ ' posthog-react-native ' : patch
3+ ---
4+
5+ Support getting locale and timezone from expo-localization >= 14
Original file line number Diff line number Diff line change @@ -63,8 +63,34 @@ export const getAppProperties = (): PostHogCustomAppProperties => {
6363 }
6464
6565 if ( OptionalExpoLocalization ) {
66- properties . $locale = OptionalExpoLocalization . locale
67- properties . $timezone = OptionalExpoLocalization . timezone
66+ // expo-localization >= 14 use functions to get these results, older versions use JS getters
67+ // https://github.com/expo/expo/blob/sdk-54/packages/expo-localization/CHANGELOG.md#1400--2022-10-25
68+ // this type below supports both variants, and type-checks with older and newer versions of expo-localization
69+ const optionalExpoLocalization : {
70+ locale ?: string
71+ getLocales ?: ( ) => {
72+ languageTag : string
73+ } [ ]
74+ timezone ?: string
75+ getCalendars ?: ( ) => {
76+ timeZone : string | null
77+ } [ ]
78+ } = OptionalExpoLocalization
79+
80+ let locale = optionalExpoLocalization . locale
81+ if ( ! locale && optionalExpoLocalization . getLocales ) {
82+ locale = optionalExpoLocalization . getLocales ( ) [ 0 ] ?. languageTag
83+ }
84+ if ( locale ) {
85+ properties . $locale = locale
86+ }
87+ let timezone : string | undefined | null = optionalExpoLocalization . timezone
88+ if ( ! timezone && optionalExpoLocalization . getCalendars ) {
89+ timezone = optionalExpoLocalization . getCalendars ( ) [ 0 ] ?. timeZone
90+ }
91+ if ( timezone ) {
92+ properties . $timezone = timezone
93+ }
6894 } else if ( OptionalReactNativeLocalize ) {
6995 const localesFn = OptionalReactNativeLocalize . getLocales
7096 if ( localesFn ) {
You can’t perform that action at this time.
0 commit comments