Move /platform/detection vars into /env (#9707)
* Add platform vars to env * Replace /platform/detection with /env
This commit is contained in:
@@ -3,10 +3,10 @@ import {msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {type SessionAccount, useSessionApi} from '#/state/session'
|
||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {logEvent} from '../statsig/statsig'
|
||||
import {type LogEvents} from '../statsig/statsig'
|
||||
|
||||
@@ -28,7 +28,7 @@ export function useAccountSwitcher() {
|
||||
try {
|
||||
setPendingDid(account.did)
|
||||
if (account.accessJwt) {
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
// We're switching accounts, which remounts the entire app.
|
||||
// On mobile, this gets us Home, but on the web we also need reset the URL.
|
||||
// We can't change the URL via a navigate() call because the navigator
|
||||
|
||||
@@ -2,13 +2,13 @@ import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||
|
||||
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||
import {clamp} from '#/lib/numbers'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {IS_WEB} from '#/env'
|
||||
|
||||
export function useBottomBarOffset(modifier: number = 0) {
|
||||
const {isTabletOrDesktop} = useWebMediaQueries()
|
||||
const {bottom: bottomInset} = useSafeAreaInsets()
|
||||
return (
|
||||
(isWeb && isTabletOrDesktop ? 0 : clamp(60 + bottomInset, 60, 75)) +
|
||||
(IS_WEB && isTabletOrDesktop ? 0 : clamp(60 + bottomInset, 60, 75)) +
|
||||
modifier
|
||||
)
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import * as WebBrowser from 'expo-web-browser'
|
||||
import {useOpenComposer} from '#/lib/hooks/useOpenComposer'
|
||||
import {parseLinkingUrl} from '#/lib/parseLinkingUrl'
|
||||
import {logger} from '#/logger'
|
||||
import {isIOS, isNative} from '#/platform/detection'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
import {useIntentDialogs} from '#/components/intents/IntentDialogs'
|
||||
import {IS_IOS, IS_NATIVE} from '#/env'
|
||||
import {Referrer} from '../../../modules/expo-bluesky-swiss-army'
|
||||
import {useApplyPullRequestOTAUpdate} from './useOTAUpdates'
|
||||
|
||||
@@ -29,7 +29,7 @@ export function useIntentHandler() {
|
||||
|
||||
React.useEffect(() => {
|
||||
const handleIncomingURL = async (url: string) => {
|
||||
if (isIOS) {
|
||||
if (IS_IOS) {
|
||||
// Close in-app browser if it's open (iOS only)
|
||||
await WebBrowser.dismissBrowser().catch(() => {})
|
||||
}
|
||||
@@ -150,7 +150,7 @@ export function useComposeIntent() {
|
||||
setTimeout(() => {
|
||||
openComposer({
|
||||
text: text ?? undefined,
|
||||
imageUris: isNative ? imageUris : undefined,
|
||||
imageUris: IS_NATIVE ? imageUris : undefined,
|
||||
})
|
||||
}, 500)
|
||||
},
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {useEffect, useState} from 'react'
|
||||
import {Keyboard} from 'react-native'
|
||||
|
||||
import {isIOS} from '#/platform/detection'
|
||||
import {IS_IOS} from '#/env'
|
||||
|
||||
export function useIsKeyboardVisible({
|
||||
iosUseWillEvents,
|
||||
@@ -14,9 +14,9 @@ export function useIsKeyboardVisible({
|
||||
// only iOS supports the "will" events
|
||||
// -prf
|
||||
const showEvent =
|
||||
isIOS && iosUseWillEvents ? 'keyboardWillShow' : 'keyboardDidShow'
|
||||
IS_IOS && iosUseWillEvents ? 'keyboardWillShow' : 'keyboardDidShow'
|
||||
const hideEvent =
|
||||
isIOS && iosUseWillEvents ? 'keyboardWillHide' : 'keyboardDidHide'
|
||||
IS_IOS && iosUseWillEvents ? 'keyboardWillHide' : 'keyboardDidHide'
|
||||
|
||||
useEffect(() => {
|
||||
const keyboardShowListener = Keyboard.addListener(showEvent, () =>
|
||||
|
||||
@@ -9,7 +9,6 @@ import {useQueryClient} from '@tanstack/react-query'
|
||||
import {useAccountSwitcher} from '#/lib/hooks/useAccountSwitcher'
|
||||
import {logger as notyLogger} from '#/lib/notifications/util'
|
||||
import {type NavigationProp} from '#/lib/routes/types'
|
||||
import {isAndroid, isIOS} from '#/platform/detection'
|
||||
import {useCurrentConvoId} from '#/state/messages/current-convo-id'
|
||||
import {RQKEY as RQKEY_NOTIFS} from '#/state/queries/notifications/feed'
|
||||
import {invalidateCachedUnreadPage} from '#/state/queries/notifications/unread'
|
||||
@@ -17,6 +16,7 @@ import {truncateAndInvalidate} from '#/state/queries/util'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useLoggedOutViewControls} from '#/state/shell/logged-out'
|
||||
import {useCloseAllActiveElements} from '#/state/util'
|
||||
import {IS_ANDROID, IS_IOS} from '#/env'
|
||||
import {resetToTab} from '#/Navigation'
|
||||
import {router} from '#/routes'
|
||||
|
||||
@@ -90,7 +90,7 @@ export function useNotificationsHandler() {
|
||||
// channels allow for the mute/unmute functionality we want for the background
|
||||
// handler.
|
||||
useEffect(() => {
|
||||
if (!isAndroid) return
|
||||
if (!IS_ANDROID) return
|
||||
// assign both chat notifications to a group
|
||||
// NOTE: I don't think that it will retroactively move them into the group
|
||||
// if the channels already exist. no big deal imo -sfn
|
||||
@@ -379,7 +379,7 @@ export function getNotificationPayload(
|
||||
}
|
||||
|
||||
const payload = (
|
||||
isIOS ? e.request.trigger.payload : e.request.content.data
|
||||
IS_IOS ? e.request.trigger.payload : e.request.content.data
|
||||
) as NotificationPayload
|
||||
|
||||
if (payload && payload.reason) {
|
||||
|
||||
@@ -12,14 +12,14 @@ import {
|
||||
|
||||
import {isNetworkError} from '#/lib/strings/errors'
|
||||
import {logger} from '#/logger'
|
||||
import {isAndroid, isIOS} from '#/platform/detection'
|
||||
import {IS_ANDROID, IS_IOS} from '#/env'
|
||||
import {IS_TESTFLIGHT} from '#/env'
|
||||
|
||||
const MINIMUM_MINIMIZE_TIME = 15 * 60e3
|
||||
|
||||
async function setExtraParams() {
|
||||
await setExtraParamAsync(
|
||||
isIOS ? 'ios-build-number' : 'android-build-number',
|
||||
IS_IOS ? 'ios-build-number' : 'android-build-number',
|
||||
// Hilariously, `buildVersion` is not actually a string on Android even though the TS type says it is.
|
||||
// This just ensures it gets passed as a string
|
||||
`${nativeBuildVersion}`,
|
||||
@@ -32,7 +32,7 @@ async function setExtraParams() {
|
||||
|
||||
async function setExtraParamsPullRequest(channel: string) {
|
||||
await setExtraParamAsync(
|
||||
isIOS ? 'ios-build-number' : 'android-build-number',
|
||||
IS_IOS ? 'ios-build-number' : 'android-build-number',
|
||||
// Hilariously, `buildVersion` is not actually a string on Android even though the TS type says it is.
|
||||
// This just ensures it gets passed as a string
|
||||
`${nativeBuildVersion}`,
|
||||
@@ -198,7 +198,7 @@ export function useOTAUpdates() {
|
||||
// `maintainVisibleContentPosition`. See repro repo for more details:
|
||||
// https://github.com/mozzius/ota-crash-repro
|
||||
// Old Arch only - re-enable once we're on the New Archictecture! -sfn
|
||||
if (isAndroid) return
|
||||
if (IS_ANDROID) return
|
||||
|
||||
const subscription = AppState.addEventListener(
|
||||
'change',
|
||||
|
||||
@@ -12,11 +12,11 @@ import {
|
||||
toNiceDomain,
|
||||
} from '#/lib/strings/url-helpers'
|
||||
import {logger} from '#/logger'
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {useInAppBrowser} from '#/state/preferences/in-app-browser'
|
||||
import {useTheme} from '#/alf'
|
||||
import {useDialogContext} from '#/components/Dialog'
|
||||
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
|
||||
import {IS_NATIVE} from '#/env'
|
||||
|
||||
export function useOpenLink() {
|
||||
const enabled = useInAppBrowser()
|
||||
@@ -41,7 +41,7 @@ export function useOpenLink() {
|
||||
}
|
||||
}
|
||||
|
||||
if (isNative && !url.startsWith('mailto:')) {
|
||||
if (IS_NATIVE && !url.startsWith('mailto:')) {
|
||||
if (override === undefined && enabled === undefined) {
|
||||
// consent dialog is a global dialog, and while it's possible to nest dialogs,
|
||||
// the actual components need to be nested. sibling dialogs on iOS are not supported.
|
||||
|
||||
@@ -2,8 +2,8 @@ import {Linking} from 'react-native'
|
||||
import {useCameraPermissions as useExpoCameraPermissions} from 'expo-camera'
|
||||
import * as MediaLibrary from 'expo-media-library'
|
||||
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {Alert} from '#/view/com/util/Alert'
|
||||
import {IS_WEB} from '#/env'
|
||||
|
||||
const openPermissionAlert = (perm: string) => {
|
||||
Alert.alert(
|
||||
@@ -26,7 +26,7 @@ export function usePhotoLibraryPermission() {
|
||||
const requestPhotoAccessIfNeeded = async () => {
|
||||
// On the, we use <input type="file"> to produce a filepicker
|
||||
// This does not need any permission granting.
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export function useVideoLibraryPermission() {
|
||||
const requestVideoAccessIfNeeded = async () => {
|
||||
// On the, we use <input type="file"> to produce a filepicker
|
||||
// This does not need any permission granting.
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import {useCallback} from 'react'
|
||||
import * as IntentLauncher from 'expo-intent-launcher'
|
||||
|
||||
import {getTranslatorLink} from '#/locale/helpers'
|
||||
import {isAndroid} from '#/platform/detection'
|
||||
import {IS_ANDROID} from '#/env'
|
||||
import {useOpenLink} from './useOpenLink'
|
||||
|
||||
export function useTranslate() {
|
||||
@@ -11,7 +11,7 @@ export function useTranslate() {
|
||||
return useCallback(
|
||||
async (text: string, language: string) => {
|
||||
const translateUrl = getTranslatorLink(text, language)
|
||||
if (isAndroid) {
|
||||
if (IS_ANDROID) {
|
||||
try {
|
||||
// use getApplicationIconAsync to determine if the translate app is installed
|
||||
if (
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {useMediaQuery} from 'react-responsive'
|
||||
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {IS_NATIVE} from '#/env'
|
||||
|
||||
/**
|
||||
* @deprecated use `useBreakpoints` from `#/alf` instead
|
||||
@@ -11,7 +11,7 @@ export function useWebMediaQueries() {
|
||||
const isMobile = useMediaQuery({maxWidth: 800 - 1})
|
||||
const isTabletOrMobile = isMobile || isTablet
|
||||
const isTabletOrDesktop = isDesktop || isTablet
|
||||
if (isNative) {
|
||||
if (IS_NATIVE) {
|
||||
return {
|
||||
isMobile: true,
|
||||
isTablet: false,
|
||||
|
||||
Reference in New Issue
Block a user