diff --git a/posthog-react-native/src/legacy.ts b/posthog-react-native/src/legacy.ts index b9460fbf..09d0721c 100644 --- a/posthog-react-native/src/legacy.ts +++ b/posthog-react-native/src/legacy.ts @@ -10,6 +10,7 @@ export const getLegacyValues = async (): Promise<{ distinctId?: string; anonymou return } + // legacy didn't support macos, no need to check it if (Platform.OS === 'ios') { const posthogFileDirectory = `${OptionalExpoFileSystem.documentDirectory}../Library/Application%20Support/${OptionalExpoApplication.applicationId}/` const posthogDistinctIdFile = posthogFileDirectory + 'posthog.distinctId' diff --git a/posthog-react-native/src/optional/OptionalExpoApplication.ts b/posthog-react-native/src/optional/OptionalExpoApplication.ts index 15ef9ad6..34902d6f 100644 --- a/posthog-react-native/src/optional/OptionalExpoApplication.ts +++ b/posthog-react-native/src/optional/OptionalExpoApplication.ts @@ -1,7 +1,11 @@ import type ExpoApplication from 'expo-application' +import { Platform } from 'react-native' export let OptionalExpoApplication: typeof ExpoApplication | undefined = undefined try { - OptionalExpoApplication = require('expo-application') + // macos not supported + if (Platform.OS !== 'macos') { + OptionalExpoApplication = require('expo-application') + } } catch (e) {} diff --git a/posthog-react-native/src/optional/OptionalExpoDevice.ts b/posthog-react-native/src/optional/OptionalExpoDevice.ts index 224163f2..84f5d342 100644 --- a/posthog-react-native/src/optional/OptionalExpoDevice.ts +++ b/posthog-react-native/src/optional/OptionalExpoDevice.ts @@ -1,7 +1,11 @@ import type ExpoDevice from 'expo-device' +import { Platform } from 'react-native' export let OptionalExpoDevice: typeof ExpoDevice | undefined = undefined try { - OptionalExpoDevice = require('expo-device') + // macos not supported + if (Platform.OS !== 'macos') { + OptionalExpoDevice = require('expo-device') + } } catch (e) {} diff --git a/posthog-react-native/src/optional/OptionalExpoFileSystem.ts b/posthog-react-native/src/optional/OptionalExpoFileSystem.ts index 3703ff63..c2f355d4 100644 --- a/posthog-react-native/src/optional/OptionalExpoFileSystem.ts +++ b/posthog-react-native/src/optional/OptionalExpoFileSystem.ts @@ -4,12 +4,12 @@ import { Platform } from 'react-native' export let OptionalExpoFileSystem: typeof ExpoFileSystem | undefined = undefined try { - // do not try to load expo-file-system on web, otherwise it will throw an error + // do not try to load expo-file-system on web and macos, otherwise it will throw an error // Error: The method or property expo-file-system.writeAsStringAsync is not available on web // See https://github.com/PostHog/posthog-js-lite/issues/140 - // Once expo-file-system is supported on web, we can remove this try/catch block + // Once expo-file-system is supported on web/macos, we can remove this try/catch block // For now, use the react-native-async-storage/async-storage package instead - if (Platform.OS !== 'web') { + if (Platform.OS !== 'web' && Platform.OS !== 'macos') { OptionalExpoFileSystem = require('expo-file-system') // No Web support } } catch (e) {} diff --git a/posthog-react-native/src/optional/OptionalExpoLocalization.ts b/posthog-react-native/src/optional/OptionalExpoLocalization.ts index 41c67cb1..6cf84546 100644 --- a/posthog-react-native/src/optional/OptionalExpoLocalization.ts +++ b/posthog-react-native/src/optional/OptionalExpoLocalization.ts @@ -1,7 +1,11 @@ import type ExpoLocalization from 'expo-localization' +import { Platform } from 'react-native' export let OptionalExpoLocalization: typeof ExpoLocalization | undefined = undefined try { - OptionalExpoLocalization = require('expo-localization') + // macos not supported + if (Platform.OS !== 'macos') { + OptionalExpoLocalization = require('expo-localization') + } } catch (e) {} diff --git a/posthog-react-native/src/optional/OptionalReactNativeDeviceInfo.ts b/posthog-react-native/src/optional/OptionalReactNativeDeviceInfo.ts index 49f74e09..8dce1f01 100644 --- a/posthog-react-native/src/optional/OptionalReactNativeDeviceInfo.ts +++ b/posthog-react-native/src/optional/OptionalReactNativeDeviceInfo.ts @@ -1,7 +1,11 @@ +import { Platform } from 'react-native' import type ReactNativeDeviceInfo from 'react-native-device-info' export let OptionalReactNativeDeviceInfo: typeof ReactNativeDeviceInfo | undefined = undefined try { - OptionalReactNativeDeviceInfo = require('react-native-device-info') // No Web support + // macos not supported + if (Platform.OS !== 'macos') { + OptionalReactNativeDeviceInfo = require('react-native-device-info') // No Web support, returns unknown + } } catch (e) {} diff --git a/posthog-react-native/src/optional/OptionalReactNativeNavigation.ts b/posthog-react-native/src/optional/OptionalReactNativeNavigation.ts index c9e51b38..45632982 100644 --- a/posthog-react-native/src/optional/OptionalReactNativeNavigation.ts +++ b/posthog-react-native/src/optional/OptionalReactNativeNavigation.ts @@ -1,7 +1,12 @@ import type ReactNativeNavigation from '@react-navigation/native' +import { Platform } from 'react-native' export let OptionalReactNativeNavigation: typeof ReactNativeNavigation | undefined = undefined try { - OptionalReactNativeNavigation = require('@react-navigation/native') + // macos not supported + if (Platform.OS !== 'macos') { + // experimental support for web https://reactnavigation.org/docs/web-support/ + OptionalReactNativeNavigation = require('@react-navigation/native') + } } catch (e) {} diff --git a/posthog-react-native/src/optional/OptionalReactNativeNavigationWix.ts b/posthog-react-native/src/optional/OptionalReactNativeNavigationWix.ts index 421adf61..828b6194 100644 --- a/posthog-react-native/src/optional/OptionalReactNativeNavigationWix.ts +++ b/posthog-react-native/src/optional/OptionalReactNativeNavigationWix.ts @@ -1,7 +1,11 @@ +import { Platform } from 'react-native' import type ReactNativeNavigationWix from 'react-native-navigation' export let OptionalReactNativeNavigationWix: typeof ReactNativeNavigationWix | undefined = undefined try { - OptionalReactNativeNavigationWix = require('react-native-navigation') + // macos/web not supported + if (Platform.OS !== 'web' && Platform.OS !== 'macos') { + OptionalReactNativeNavigationWix = require('react-native-navigation') + } } catch (e) {}