Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: set locale and timezone using the react-native-localize library #373

Merged
merged 3 commits into from
Feb 5, 2025

Conversation

marandaneto
Copy link
Member

@marandaneto marandaneto commented Feb 5, 2025

Problem

Closes #286

Changes

Release info Sub-libraries affected

Bump level

  • Major
  • Minor
  • Patch

Libraries affected

  • All of them
  • posthog-web
  • posthog-node
  • posthog-react-native

Changelog notes

  • Added support for X

Copy link

github-actions bot commented Feb 5, 2025

Size Change: +283 B (+0.26%)

Total Size: 110 kB

Filename Size Change
posthog-react-native/lib/posthog-react-native/src/native-deps.js 1.31 kB +115 B (+9.59%) ⚠️
posthog-react-native/lib/posthog-react-native/src/version.js 123 B -1 B (-0.81%)
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeLocalize.js 169 B +169 B (new file) 🆕
ℹ️ View Unchanged
Filename Size
posthog-node/lib/index.cjs.js 20.8 kB
posthog-node/lib/index.esm.js 20.7 kB
posthog-react-native/lib/posthog-core/src/eventemitter.js 1.08 kB
posthog-react-native/lib/posthog-core/src/index.js 10 kB
posthog-react-native/lib/posthog-core/src/lz-string.js 1.42 kB
posthog-react-native/lib/posthog-core/src/types.js 420 B
posthog-react-native/lib/posthog-core/src/utils.js 870 B
posthog-react-native/lib/posthog-core/src/vendor/uuidv7.js 2.04 kB
posthog-react-native/lib/posthog-react-native/index.js 485 B
posthog-react-native/lib/posthog-react-native/src/autocapture.js 1.8 kB
posthog-react-native/lib/posthog-react-native/src/frameworks/wix-navigation.js 651 B
posthog-react-native/lib/posthog-react-native/src/hooks/useFeatureFlag.js 437 B
posthog-react-native/lib/posthog-react-native/src/hooks/useFeatureFlags.js 362 B
posthog-react-native/lib/posthog-react-native/src/hooks/useLifecycleTracker.js 416 B
posthog-react-native/lib/posthog-react-native/src/hooks/useNavigationTracker.js 628 B
posthog-react-native/lib/posthog-react-native/src/hooks/usePostHog.js 249 B
posthog-react-native/lib/posthog-react-native/src/legacy.js 810 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalAsyncStorage.js 183 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoApplication.js 215 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoDevice.js 211 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoFileSystem.js 224 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalExpoLocalization.js 216 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeDeviceInfo.js 220 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeNavigation.js 218 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalReactNativeNavigationWix.js 222 B
posthog-react-native/lib/posthog-react-native/src/optional/OptionalSessionReplay.js 231 B
posthog-react-native/lib/posthog-react-native/src/posthog-rn.js 4.42 kB
posthog-react-native/lib/posthog-react-native/src/PostHogContext.js 210 B
posthog-react-native/lib/posthog-react-native/src/PostHogProvider.js 1.57 kB
posthog-react-native/lib/posthog-react-native/src/storage.js 1.09 kB
posthog-react-native/lib/posthog-react-native/src/types.js 90 B
posthog-web/lib/index.cjs.js 17.8 kB
posthog-web/lib/index.esm.js 17.8 kB

compressed-size-action

@marandaneto marandaneto changed the title chore: set locale and timezoen for rn libs chore: set locale and timezone using the react-native-localize library Feb 5, 2025
@marandaneto marandaneto requested review from k11kirky, a team and ioannisj and removed request for a team February 5, 2025 12:56
@marandaneto
Copy link
Member Author

@k11kirky tagged you because yarn install updated a few things, the linter too, just double check its ok

@marandaneto marandaneto marked this pull request as ready for review February 5, 2025 12:58
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR replaces Expo's localization with react-native-localize for handling locale and timezone settings in the PostHog React Native SDK, addressing compatibility issues when Expo is not being used.

  • Added react-native-localize as a new peer dependency in /posthog-react-native/package.json
  • Implemented new OptionalReactNativeLocalize.ts for handling locale/timezone when Expo is unavailable
  • Modified /posthog-react-native/src/native-deps.tsx to use react-native-localize as fallback for non-Expo apps
  • Breaking change: Removed several deprecated device info methods (is24Hour, getTimezone, etc.) from react-native-device-info
  • Added timezone/locale functionality using getLocales() and getTimeZone() from react-native-localize

💡 (5/5) You can turn off certain types of comments like style here!

7 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines +20 to +21
OptionalReactNativeLocalize = require('react-native-localize')
} catch (e) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Empty catch block could silently fail. Consider logging the error when in debug mode.

@@ -33,6 +33,7 @@
"react-native": "^0.69.1",
"react-native-device-info": "^10.3.0",
"react-native-navigation": "^6.0.0",
"react-native-localize": "^3.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: react-native-localize is added as a devDependency but not as a peerDependency. Since it's replacing core functionality, it should probably be added to peerDependencies with an appropriate version range.

Comment on lines +63 to +73
const localesFn = OptionalReactNativeLocalize.getLocales
if (localesFn) {
const locales = localesFn()

if (locales && locales.length > 0) {
const languageTag = locales[0].languageTag
if (languageTag) {
properties.$locale = languageTag
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding error handling for localesFn() call which could throw an exception

Comment on lines +75 to +82
const timezoneFn = OptionalReactNativeLocalize.getTimeZone
if (timezoneFn) {
const timezone = timezoneFn()

if (timezone) {
properties.$timezone = timezone
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding error handling for timezoneFn() call which could throw an exception

@marandaneto marandaneto enabled auto-merge (squash) February 5, 2025 17:25
@@ -72,7 +72,7 @@ export class WrappedMessages extends AnthropicOriginal.Messages {
return parentPromise.then((value) => {
const passThroughStream = new PassThrough({ objectMode: true })
let accumulatedContent = ''
let usage: { inputTokens: number; outputTokens: number } = {
const usage: { inputTokens: number; outputTokens: number } = {
Copy link
Contributor

@k11kirky k11kirky Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should have stayed let - its gets reasigned under

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the linter did it automatically btw (eslint, prettier), but as I can see it, the usage props are resigned, but not the usage itself.
Happy to change it back but am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 2 openai usage gets reasigned, but not the anthropic one.

@marandaneto marandaneto merged commit 670b52c into main Feb 5, 2025
4 checks passed
@marandaneto marandaneto deleted the fix/rn-lib-timezone branch February 5, 2025 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set locale and timezone info if not using Expo
2 participants