Move /platform/detection vars into /env (#9707)
* Add platform vars to env * Replace /platform/detection with /env
This commit is contained in:
@@ -25,12 +25,12 @@ import {
|
||||
linkRequiresWarning,
|
||||
} from '#/lib/strings/url-helpers'
|
||||
import {type TypographyVariant} from '#/lib/ThemeContext'
|
||||
import {isAndroid, isWeb} from '#/platform/detection'
|
||||
import {emitSoftReset} from '#/state/events'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {WebAuxClickWrapper} from '#/view/com/util/WebAuxClickWrapper'
|
||||
import {useTheme} from '#/alf'
|
||||
import {useGlobalDialogsControlContext} from '#/components/dialogs/Context'
|
||||
import {IS_ANDROID, IS_WEB} from '#/env'
|
||||
import {router} from '../../../routes'
|
||||
import {PressableWithHover} from './PressableWithHover'
|
||||
import {Text} from './text/Text'
|
||||
@@ -130,7 +130,7 @@ export const Link = memo(function Link({
|
||||
android_ripple={{
|
||||
color: t.atoms.bg_contrast_25.backgroundColor,
|
||||
}}
|
||||
unstable_pressDelay={isAndroid ? 90 : undefined}>
|
||||
unstable_pressDelay={IS_ANDROID ? 90 : undefined}>
|
||||
{/* @ts-ignore web only -prf */}
|
||||
<View style={style} href={anchorHref}>
|
||||
{children ? children : <Text>{title || 'link'}</Text>}
|
||||
@@ -219,7 +219,7 @@ export const TextLink = memo(function TextLink({
|
||||
})
|
||||
}
|
||||
if (
|
||||
isWeb &&
|
||||
IS_WEB &&
|
||||
href !== '#' &&
|
||||
e != null &&
|
||||
isModifiedEvent(e as React.MouseEvent)
|
||||
@@ -323,7 +323,7 @@ export const TextLinkOnWebOnly = memo(function DesktopWebTextLink({
|
||||
onBeforePress,
|
||||
...props
|
||||
}: TextLinkOnWebOnlyProps) {
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
return (
|
||||
<TextLink
|
||||
testID={testID}
|
||||
|
||||
@@ -11,9 +11,9 @@ import {updateActiveVideoViewAsync} from '@haileyok/bluesky-video'
|
||||
import {useDedupe} from '#/lib/hooks/useDedupe'
|
||||
import {useScrollHandlers} from '#/lib/ScrollContext'
|
||||
import {addStyle} from '#/lib/styles'
|
||||
import {isIOS} from '#/platform/detection'
|
||||
import {useLightbox} from '#/state/lightbox'
|
||||
import {useTheme} from '#/alf'
|
||||
import {IS_IOS} from '#/env'
|
||||
import {FlatList_INTERNAL} from './Views'
|
||||
|
||||
export type ListMethods = FlatList_INTERNAL
|
||||
@@ -94,7 +94,7 @@ let List = React.forwardRef<ListMethods, ListProps>(
|
||||
}
|
||||
}
|
||||
|
||||
if (isIOS) {
|
||||
if (IS_IOS) {
|
||||
runOnJS(dedupe)(updateActiveVideoViewAsync)
|
||||
}
|
||||
},
|
||||
@@ -184,7 +184,7 @@ export {List}
|
||||
|
||||
// We only want to use this context value on iOS because the `scrollsToTop` prop is iOS-only
|
||||
// removing it saves us a re-render on Android
|
||||
const useAllowScrollToTop = isIOS ? useAllowScrollToTopIOS : () => undefined
|
||||
const useAllowScrollToTop = IS_IOS ? useAllowScrollToTopIOS : () => undefined
|
||||
function useAllowScrollToTopIOS() {
|
||||
const {activeLightbox} = useLightbox()
|
||||
return !activeLightbox
|
||||
|
||||
@@ -9,9 +9,9 @@ import {
|
||||
import EventEmitter from 'eventemitter3'
|
||||
|
||||
import {ScrollProvider} from '#/lib/ScrollContext'
|
||||
import {isNative, isWeb} from '#/platform/detection'
|
||||
import {useMinimalShellMode} from '#/state/shell'
|
||||
import {useShellLayout} from '#/state/shell/shell-layout'
|
||||
import {IS_NATIVE, IS_WEB} from '#/env'
|
||||
|
||||
const WEB_HIDE_SHELL_THRESHOLD = 200
|
||||
|
||||
@@ -35,7 +35,7 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
return listenToForcedWindowScroll(() => {
|
||||
startDragOffset.set(null)
|
||||
startMode.set(null)
|
||||
@@ -48,7 +48,7 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
||||
(e: NativeScrollEvent) => {
|
||||
'worklet'
|
||||
const offsetY = Math.max(0, e.contentOffset.y)
|
||||
if (isNative) {
|
||||
if (IS_NATIVE) {
|
||||
const startDragOffsetValue = startDragOffset.get()
|
||||
if (startDragOffsetValue === null) {
|
||||
return
|
||||
@@ -75,7 +75,7 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
||||
(e: NativeScrollEvent) => {
|
||||
'worklet'
|
||||
const offsetY = Math.max(0, e.contentOffset.y)
|
||||
if (isNative) {
|
||||
if (IS_NATIVE) {
|
||||
startDragOffset.set(offsetY)
|
||||
startMode.set(headerMode.get())
|
||||
}
|
||||
@@ -86,7 +86,7 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
||||
const onEndDrag = useCallback(
|
||||
(e: NativeScrollEvent) => {
|
||||
'worklet'
|
||||
if (isNative) {
|
||||
if (IS_NATIVE) {
|
||||
if (e.velocity && e.velocity.y !== 0) {
|
||||
// If we detect a velocity, wait for onMomentumEnd to snap.
|
||||
return
|
||||
@@ -100,7 +100,7 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
||||
const onMomentumEnd = useCallback(
|
||||
(e: NativeScrollEvent) => {
|
||||
'worklet'
|
||||
if (isNative) {
|
||||
if (IS_NATIVE) {
|
||||
snapToClosestState(e)
|
||||
}
|
||||
},
|
||||
@@ -111,7 +111,7 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
||||
(e: NativeScrollEvent) => {
|
||||
'worklet'
|
||||
const offsetY = Math.max(0, e.contentOffset.y)
|
||||
if (isNative) {
|
||||
if (IS_NATIVE) {
|
||||
const startDragOffsetValue = startDragOffset.get()
|
||||
const startModeValue = startMode.get()
|
||||
if (startDragOffsetValue === null || startModeValue === null) {
|
||||
@@ -177,7 +177,7 @@ export function MainScrollProvider({children}: {children: React.ReactNode}) {
|
||||
|
||||
const emitter = new EventEmitter()
|
||||
|
||||
if (isWeb) {
|
||||
if (IS_WEB) {
|
||||
const originalScroll = window.scroll
|
||||
window.scroll = function () {
|
||||
emitter.emit('forced-scroll')
|
||||
|
||||
@@ -12,7 +12,6 @@ import {NON_BREAKING_SPACE} from '#/lib/strings/constants'
|
||||
import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||
import {niceDate} from '#/lib/strings/time'
|
||||
import {isAndroid} from '#/platform/detection'
|
||||
import {useProfileShadow} from '#/state/cache/profile-shadow'
|
||||
import {precacheProfile} from '#/state/queries/profile'
|
||||
import {atoms as a, platform, useTheme, web} from '#/alf'
|
||||
@@ -21,6 +20,7 @@ import {ProfileHoverCard} from '#/components/ProfileHoverCard'
|
||||
import {Text} from '#/components/Typography'
|
||||
import {useSimpleVerificationState} from '#/components/verification'
|
||||
import {VerificationCheck} from '#/components/verification/VerificationCheck'
|
||||
import {IS_ANDROID} from '#/env'
|
||||
import {TimeElapsed} from './TimeElapsed'
|
||||
import {PreviewableUserAvatar} from './UserAvatar'
|
||||
|
||||
@@ -152,14 +152,14 @@ let PostMeta = (opts: PostMetaOpts): React.ReactNode => {
|
||||
a.pl_xs,
|
||||
a.text_md,
|
||||
a.leading_tight,
|
||||
isAndroid && a.flex_grow,
|
||||
IS_ANDROID && a.flex_grow,
|
||||
a.text_right,
|
||||
t.atoms.text_contrast_medium,
|
||||
web({
|
||||
whiteSpace: 'nowrap',
|
||||
}),
|
||||
]}>
|
||||
{!isAndroid && (
|
||||
{!IS_ANDROID && (
|
||||
<Text
|
||||
style={[
|
||||
a.text_md,
|
||||
|
||||
@@ -30,7 +30,6 @@ import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
||||
import {isCancelledError} from '#/lib/strings/errors'
|
||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||
import {logger} from '#/logger'
|
||||
import {isAndroid, isNative, isWeb} from '#/platform/detection'
|
||||
import {
|
||||
type ComposerImage,
|
||||
compressImage,
|
||||
@@ -54,6 +53,7 @@ import {LiveStatusDialog} from '#/components/live/LiveStatusDialog'
|
||||
import {MediaInsetBorder} from '#/components/MediaInsetBorder'
|
||||
import * as Menu from '#/components/Menu'
|
||||
import {ProfileHoverCard} from '#/components/ProfileHoverCard'
|
||||
import {IS_ANDROID, IS_NATIVE, IS_WEB} from '#/env'
|
||||
import type * as bsky from '#/types/bsky'
|
||||
|
||||
export type UserAvatarType = 'user' | 'algo' | 'list' | 'labeler'
|
||||
@@ -88,7 +88,7 @@ interface PreviewableUserAvatarProps extends BaseUserAvatarProps {
|
||||
onBeforePress?: () => void
|
||||
}
|
||||
|
||||
const BLUR_AMOUNT = isWeb ? 5 : 100
|
||||
const BLUR_AMOUNT = IS_WEB ? 5 : 100
|
||||
|
||||
let DefaultAvatar = ({
|
||||
type,
|
||||
@@ -286,7 +286,7 @@ let UserAvatar = ({
|
||||
}, [size, style])
|
||||
|
||||
return avatar &&
|
||||
!((moderation?.blur && isAndroid) /* android crashes with blur */) ? (
|
||||
!((moderation?.blur && IS_ANDROID) /* android crashes with blur */) ? (
|
||||
<View style={containerStyle}>
|
||||
{usePlainRNImage ? (
|
||||
<RNImage
|
||||
@@ -394,7 +394,7 @@ let EditableUserAvatar = ({
|
||||
}
|
||||
|
||||
try {
|
||||
if (isNative) {
|
||||
if (IS_NATIVE) {
|
||||
onSelectNewAvatar(
|
||||
await compressIfNeeded(
|
||||
await openCropper({
|
||||
@@ -464,7 +464,7 @@ let EditableUserAvatar = ({
|
||||
</Menu.Trigger>
|
||||
<Menu.Outer showCancel>
|
||||
<Menu.Group>
|
||||
{isNative && (
|
||||
{IS_NATIVE && (
|
||||
<Menu.Item
|
||||
testID="changeAvatarCameraBtn"
|
||||
label={_(msg`Upload from Camera`)}
|
||||
@@ -481,7 +481,7 @@ let EditableUserAvatar = ({
|
||||
label={_(msg`Upload from Library`)}
|
||||
onPress={onOpenLibrary}>
|
||||
<Menu.ItemText>
|
||||
{isNative ? (
|
||||
{IS_NATIVE ? (
|
||||
<Trans>Upload from Library</Trans>
|
||||
) : (
|
||||
<Trans>Upload from Files</Trans>
|
||||
@@ -571,7 +571,7 @@ let PreviewableUserAvatar = ({
|
||||
<ProfileHoverCard did={profile.did} disable={disableHoverCard}>
|
||||
{disableNavigation ? (
|
||||
avatarEl
|
||||
) : status.isActive && (isNative || isTouchDevice) ? (
|
||||
) : status.isActive && (IS_NATIVE || isTouchDevice) ? (
|
||||
<>
|
||||
<Button
|
||||
label={_(
|
||||
|
||||
@@ -14,7 +14,6 @@ import {openCamera, openCropper, openPicker} from '#/lib/media/picker'
|
||||
import {type PickerImage} from '#/lib/media/picker.shared'
|
||||
import {isCancelledError} from '#/lib/strings/errors'
|
||||
import {logger} from '#/logger'
|
||||
import {isAndroid, isNative} from '#/platform/detection'
|
||||
import {
|
||||
type ComposerImage,
|
||||
compressImage,
|
||||
@@ -32,6 +31,7 @@ import {
|
||||
import {StreamingLive_Stroke2_Corner0_Rounded as LibraryIcon} from '#/components/icons/StreamingLive'
|
||||
import {Trash_Stroke2_Corner0_Rounded as TrashIcon} from '#/components/icons/Trash'
|
||||
import * as Menu from '#/components/Menu'
|
||||
import {IS_ANDROID, IS_NATIVE} from '#/env'
|
||||
|
||||
export function UserBanner({
|
||||
type,
|
||||
@@ -75,7 +75,7 @@ export function UserBanner({
|
||||
}
|
||||
|
||||
try {
|
||||
if (isNative) {
|
||||
if (IS_NATIVE) {
|
||||
onSelectNewBanner?.(
|
||||
await compressIfNeeded(
|
||||
await openCropper({
|
||||
@@ -153,7 +153,7 @@ export function UserBanner({
|
||||
</Menu.Trigger>
|
||||
<Menu.Outer showCancel>
|
||||
<Menu.Group>
|
||||
{isNative && (
|
||||
{IS_NATIVE && (
|
||||
<Menu.Item
|
||||
testID="changeBannerCameraBtn"
|
||||
label={_(msg`Upload from Camera`)}
|
||||
@@ -170,7 +170,7 @@ export function UserBanner({
|
||||
label={_(msg`Upload from Library`)}
|
||||
onPress={onOpenLibrary}>
|
||||
<Menu.ItemText>
|
||||
{isNative ? (
|
||||
{IS_NATIVE ? (
|
||||
<Trans>Upload from Library</Trans>
|
||||
) : (
|
||||
<Trans>Upload from Files</Trans>
|
||||
@@ -207,7 +207,7 @@ export function UserBanner({
|
||||
/>
|
||||
</>
|
||||
) : banner &&
|
||||
!((moderation?.blur && isAndroid) /* android crashes with blur */) ? (
|
||||
!((moderation?.blur && IS_ANDROID) /* android crashes with blur */) ? (
|
||||
<Image
|
||||
testID="userBannerImage"
|
||||
style={[styles.bannerImage, t.atoms.bg_contrast_25]}
|
||||
|
||||
@@ -13,7 +13,7 @@ import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle'
|
||||
import {usePalette} from '#/lib/hooks/usePalette'
|
||||
import {clamp} from '#/lib/numbers'
|
||||
import {colors, s} from '#/lib/styles'
|
||||
import {isAndroid} from '#/platform/detection'
|
||||
import {IS_ANDROID} from '#/env'
|
||||
import {Text} from './text/Text'
|
||||
import {FlatList_INTERNAL} from './Views'
|
||||
|
||||
@@ -120,7 +120,7 @@ export const ViewSelector = React.forwardRef<
|
||||
renderItem={renderItemInternal}
|
||||
ListFooterComponent={ListFooterComponent}
|
||||
// NOTE sticky header disabled on android due to major performance issues -prf
|
||||
stickyHeaderIndices={isAndroid ? undefined : STICKY_HEADER_INDICES}
|
||||
stickyHeaderIndices={IS_ANDROID ? undefined : STICKY_HEADER_INDICES}
|
||||
onScroll={onScroll}
|
||||
onEndReached={onEndReached}
|
||||
refreshControl={
|
||||
|
||||
@@ -12,9 +12,9 @@ import {PressableScale} from '#/lib/custom-animations/PressableScale'
|
||||
import {useHaptics} from '#/lib/haptics'
|
||||
import {useMinimalShellFabTransform} from '#/lib/hooks/useMinimalShellTransform'
|
||||
import {clamp} from '#/lib/numbers'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {ios, useBreakpoints, useTheme} from '#/alf'
|
||||
import {atoms as a} from '#/alf'
|
||||
import {IS_WEB} from '#/env'
|
||||
|
||||
export interface FABProps extends ComponentProps<typeof Pressable> {
|
||||
testID?: string
|
||||
@@ -84,7 +84,7 @@ const styles = StyleSheet.create({
|
||||
},
|
||||
outer: {
|
||||
// @ts-ignore web-only
|
||||
position: isWeb ? 'fixed' : 'absolute',
|
||||
position: IS_WEB ? 'fixed' : 'absolute',
|
||||
zIndex: 1,
|
||||
cursor: 'pointer',
|
||||
},
|
||||
|
||||
@@ -5,8 +5,8 @@ import {useColorSchemeStyle} from '#/lib/hooks/useColorSchemeStyle'
|
||||
import {useIsKeyboardVisible} from '#/lib/hooks/useIsKeyboardVisible'
|
||||
import {usePalette} from '#/lib/hooks/usePalette'
|
||||
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {atoms as a} from '#/alf'
|
||||
import {IS_WEB} from '#/env'
|
||||
import {Text} from '../text/Text'
|
||||
|
||||
export const LoggedOutLayout = ({
|
||||
@@ -79,7 +79,7 @@ export const LoggedOutLayout = ({
|
||||
contentContainerStyle={styles.scrollViewContentContainer}
|
||||
keyboardShouldPersistTaps="handled"
|
||||
keyboardDismissMode="on-drag">
|
||||
<View style={[styles.contentWrapper, isWeb && a.my_auto]}>
|
||||
<View style={[styles.contentWrapper, IS_WEB && a.my_auto]}>
|
||||
{children}
|
||||
</View>
|
||||
</ScrollView>
|
||||
|
||||
@@ -5,13 +5,13 @@ import {UITextView} from 'react-native-uitextview'
|
||||
import {lh, s} from '#/lib/styles'
|
||||
import {type TypographyVariant, useTheme} from '#/lib/ThemeContext'
|
||||
import {logger} from '#/logger'
|
||||
import {isIOS, isWeb} from '#/platform/detection'
|
||||
import {applyFonts, useAlf} from '#/alf'
|
||||
import {
|
||||
childHasEmoji,
|
||||
renderChildrenWithEmoji,
|
||||
type StringChild,
|
||||
} from '#/alf/typography'
|
||||
import {IS_IOS, IS_WEB} from '#/env'
|
||||
|
||||
export type CustomTextProps = Omit<TextProps, 'children'> & {
|
||||
type?: TypographyVariant
|
||||
@@ -81,10 +81,10 @@ function Text_DEPRECATED({
|
||||
}
|
||||
|
||||
return {
|
||||
uiTextView: selectable && isIOS,
|
||||
uiTextView: selectable && IS_IOS,
|
||||
selectable,
|
||||
style: flattened,
|
||||
dataSet: isWeb
|
||||
dataSet: IS_WEB
|
||||
? Object.assign({tooltip: title}, dataSet || {})
|
||||
: undefined,
|
||||
...props,
|
||||
|
||||
Reference in New Issue
Block a user