diff --git a/shared/app/global-errors.tsx b/shared/app/global-errors.tsx index b768ef909740..4f5757efd0aa 100644 --- a/shared/app/global-errors.tsx +++ b/shared/app/global-errors.tsx @@ -61,7 +61,7 @@ const useData = () => { if (error) { setExpandedError(error) } - if (!C.isMobile) { + if (!isMobile) { clearCountdown() } } @@ -74,14 +74,14 @@ const useData = () => { const id = setTimeout( () => { setDetails(detailsForError(error)) - if (!C.isMobile) { + if (!isMobile) { setSummary(summaryForError(error)) } }, error ? 0 : 7000 ) // if it's set, do it immediately, if it's cleared set it in a bit const newError = !!error - if (!C.isMobile) { + if (!isMobile) { if (countdownTimerRef.current) clearTimeout(countdownTimerRef.current) countdownTimerRef.current = undefined if (newError) { @@ -121,7 +121,7 @@ const GlobalError = () => { } if (daemonError) { - if (C.isMobile) { + if (isMobile) { return null } if (ignoreDisconnectOverlay) { @@ -144,7 +144,7 @@ const GlobalError = () => { ) } - if (C.isMobile) { + if (isMobile) { return ( - - - - - - - - - ) -} -// get focus so react doesn't hold onto old divs - -export default Main diff --git a/shared/app/main.native.tsx b/shared/app/main.tsx similarity index 64% rename from shared/app/main.native.tsx rename to shared/app/main.tsx index c5f107199f63..62aff1061068 100644 --- a/shared/app/main.native.tsx +++ b/shared/app/main.tsx @@ -1,14 +1,29 @@ import Router from '@/router-v2/router' -import {PortalHost} from '@/common-adapters/portal.native' import ResetModal from '../login/reset/modal' import GlobalError from './global-errors' import OutOfDate from './out-of-date' -import RuntimeStats from './runtime-stats' -import {BottomSheetModalProvider} from '@gorhom/bottom-sheet' import {FsStatusProvider} from '@/fs/common/status' import {SystemFileManagerIntegrationProvider} from '@/fs/common/sfmi' +import RemoteProxies from '../desktop/remote/proxies.desktop' +import {PortalHost} from '@/common-adapters/portal.native' +import RuntimeStats from './runtime-stats' +import {BottomSheetModalProvider} from '@gorhom/bottom-sheet' + +const DesktopMain = function DesktopMain() { + return ( + + + + + + + + + + ) +} -const Main = () => { +const NativeMain = () => { return ( @@ -25,4 +40,4 @@ const Main = () => { ) } -export default Main +export default isMobile ? NativeMain : DesktopMain diff --git a/shared/app/out-of-date.tsx b/shared/app/out-of-date.tsx index 4f1fa0ec0e42..c0c143554e0c 100644 --- a/shared/app/out-of-date.tsx +++ b/shared/app/out-of-date.tsx @@ -27,7 +27,7 @@ const OutOfDate = () => { const [mobileCritical, setMobileCritical] = React.useState(false) React.useEffect(() => { - if (!C.isMobile) { + if (!isMobile) { return } @@ -58,8 +58,8 @@ const OutOfDate = () => { } }, []) - const critical = C.isMobile ? mobileCritical : outOfDate.critical - const message = C.isMobile ? mobileMessage : outOfDate.message + const critical = isMobile ? mobileCritical : outOfDate.critical + const message = isMobile ? mobileMessage : outOfDate.message return !critical ? null : ( @@ -69,7 +69,7 @@ const OutOfDate = () => { {message} - {Kb.Styles.isMobile && } + {isMobile && } ) } diff --git a/shared/app/runtime-stats.tsx b/shared/app/runtime-stats.tsx index 2ea975b665cc..bad8651248a6 100644 --- a/shared/app/runtime-stats.tsx +++ b/shared/app/runtime-stats.tsx @@ -182,11 +182,11 @@ const LogStats = (props: {num?: number}) => { direction="vertical" style={{ backgroundColor: 'rgba(0,0,0, 0.3)', - minHeight: (Kb.Styles.isMobile ? 12 : 20) * maxBuckets, + minHeight: (isMobile ? 12 : 20) * maxBuckets, }} fullWidth={true} > - {!Kb.Styles.isMobile && ( + {!isMobile && ( Logs @@ -399,7 +399,7 @@ const RuntimeStatsMobile = ({stats}: Props) => { const RuntimeStats = () => { const stats = useConfigState(s => s.runtimeStats) return stats ? ( - Kb.Styles.isMobile ? ( + isMobile ? ( ) : ( diff --git a/shared/babel.config.js b/shared/babel.config.js index 54400cda8130..4426ce983535 100644 --- a/shared/babel.config.js +++ b/shared/babel.config.js @@ -1,7 +1,25 @@ const reactCompilerPlugin = 'babel-plugin-react-compiler' const moduleResolverPlugin = ['module-resolver', {alias: {'@': './'}}] -const makeElectronConfig = isTest => ({ +// Replaces platform globals (isMobile, isElectron, isAndroid, isIOS) with boolean +// literals at Babel transform time. This lets Metro's constant-folding-plugin DCE +// dead platform branches in production bundles. +const makePlatformPlugin = defines => babel => { + const {types: t} = babel + return { + name: 'inline-platform-globals', + visitor: { + Identifier(path) { + const {name} = path.node + if (!(name in defines) || !path.isReferencedIdentifier()) return + if (path.scope.getBinding(name)) return + path.replaceWith(t.booleanLiteral(defines[name])) + }, + }, + } +} + +const makeElectronConfig = (isTest, platformPlugin) => ({ presets: [ ['@babel/preset-env', {targets: {node: 'current'}}], ...(isTest ? [['@babel/preset-react', {runtime: 'automatic'}], '@babel/preset-flow'] : []), @@ -9,13 +27,15 @@ const makeElectronConfig = isTest => ({ ], plugins: [ reactCompilerPlugin, // must run first! + platformPlugin, ], }) -const makeReactNativeConfig = () => ({ +const makeReactNativeConfig = platformPlugin => ({ plugins: [ reactCompilerPlugin, // must run first! moduleResolverPlugin, + platformPlugin, ], presets: [['babel-preset-expo', {unstable_transformImportMeta: true, jsxRuntime: 'automatic'}]], sourceMaps: true, @@ -34,20 +54,29 @@ const detectPlatform = (apiEnv, callerName) => { module.exports = function (api /*: any */) { const apiEnv = api.env() const callerName = api.caller(c => c?.name ?? null) + const metroPlatform = api.caller(c => c?.platform ?? null) // 'ios' | 'android' | null const platform = detectPlatform(apiEnv, callerName) const isTest = apiEnv === 'test' || apiEnv === 'test-rn' - api.cache.using(() => `${apiEnv}:${callerName ?? 'unknown'}:${platform}`) + api.cache.using(() => `${apiEnv}:${callerName ?? 'unknown'}:${platform}:${metroPlatform ?? 'none'}`) + + const isRN = platform === 'react-native' + const platformPlugin = makePlatformPlugin({ + isMobile: isRN, + isElectron: !isRN, + isAndroid: metroPlatform === 'android', + isIOS: metroPlatform === 'ios', + }) - // console.error('KB babel.config.js ', {apiEnv, callerName, platform}) + // console.error('KB babel.config.js ', {apiEnv, callerName, platform, metroPlatform}) if (platform === 'electron') { // console.error('KB babel.config.js for Electron') - return makeElectronConfig(isTest) + return makeElectronConfig(isTest, platformPlugin) } if (platform === 'react-native') { // console.error('KB babel.config.js for ReactNative') - return makeReactNativeConfig() + return makeReactNativeConfig(platformPlugin) } throw new Error(`Unable to determine Babel platform from env/caller: ${apiEnv}/${callerName ?? 'unknown'}`) diff --git a/shared/chat/audio/audio-player.tsx b/shared/chat/audio/audio-player.tsx index ccd8fac2c810..6127f19e7dac 100644 --- a/shared/chat/audio/audio-player.tsx +++ b/shared/chat/audio/audio-player.tsx @@ -1,6 +1,5 @@ import * as React from 'react' import * as Kb from '@/common-adapters' -import * as C from '@/constants' import AudioVideo from './audio-video' import {formatAudioRecordDuration} from '@/util/timestamp' @@ -34,13 +33,13 @@ const AudioVis = (props: VisProps) => { style={{ backgroundColor: index < threshold ? Kb.Styles.globalColors.blue : Kb.Styles.globalColors.black, height, - marginRight: C.isMobile ? 4 * Kb.Styles.hairlineWidth : 2, - width: C.isMobile ? 3 * Kb.Styles.hairlineWidth : 1, + marginRight: isMobile ? 4 * Kb.Styles.hairlineWidth : 2, + width: isMobile ? 3 * Kb.Styles.hairlineWidth : 1, }} /> ) }) - return C.isMobile ? ( + return isMobile ? ( { - const {url, paused, onPositionUpdated, onEnded} = props - const vidRef = React.useRef(null) - - const onTimeUpdate = (e: React.SyntheticEvent) => { - const ct = e.currentTarget.currentTime - const dur = e.currentTarget.duration - if (dur === 0) { - return - } - onPositionUpdated(ct / dur) - } - - const onEndedRaw = () => { - onEnded() - } - - const lastPausedRef = React.useRef(paused) - React.useEffect(() => { - if (lastPausedRef.current === paused) { - return - } - lastPausedRef.current = paused - if (paused) { - vidRef.current?.pause() - } else { - vidRef.current - ?.play() - .then(() => {}) - .catch(() => {}) - } - }, [paused]) - - return ( -