Vue NativeVue Native
Guide
Components
Composables
Navigation
  • iOS
  • Android
  • macOS
GitHub
Guide
Components
Composables
Navigation
  • iOS
  • Android
  • macOS
GitHub
  • Device & System

    • useNetwork
    • useAppState
    • useColorScheme
    • useDeviceInfo
    • useDimensions
    • usePlatform
  • Storage & Files

    • useAsyncStorage
    • useSecureStorage
    • useFileSystem
    • useDatabase
  • Sensors & Hardware

    • useGeolocation
    • useBiometry
    • useHaptics
    • useSensors
    • useBluetooth
  • Media

    • useCamera
    • useAudio
    • useCalendar
    • useContacts
  • Networking

    • useHttp
    • useWebSocket
  • Permissions

    • usePermissions
  • Navigation

    • useBackHandler
    • useSharedElementTransition
  • UI

    • useKeyboard
    • useClipboard
    • useShare
    • useLinking
    • useAnimation
    • useGesture
    • useNotifications
    • useI18n
    • usePerformance
  • Authentication

    • useAppleSignIn
    • useGoogleSignIn
  • Monetization & Updates

    • useIAP
    • useOTAUpdate
    • useBackgroundTask
  • Desktop (macOS)

    • useWindow
    • useMenu
    • useFileDialog
    • useDragDrop

usePlatform

Returns the current platform the app is running on. Provides simple boolean flags for platform-specific logic. Values are determined at build time and are not reactive.

Usage

<script setup>
import { usePlatform } from '@thelacanians/vue-native-runtime'

const { platform, isIOS, isAndroid, isMacOS } = usePlatform()
</script>

<template>
  <VView>
    <VText>Running on: {{ platform }}</VText>
    <VText v-if="isIOS">Welcome, iOS user!</VText>
    <VText v-if="isAndroid">Welcome, Android user!</VText>
    <VText v-if="isMacOS">Welcome, macOS user!</VText>
  </VView>
</template>

API

usePlatform(): {
  platform: 'ios' | 'android' | 'macos'
  isIOS: boolean
  isAndroid: boolean
  isMacOS: boolean
  isApple: boolean
  isDesktop: boolean
  isMobile: boolean
}

Return Value

PropertyTypeDescription
platform'ios' | 'android' | 'macos'The current platform identifier.
isIOSbooleantrue if the app is running on iOS.
isAndroidbooleantrue if the app is running on Android.
isMacOSbooleantrue if the app is running on macOS.
isApplebooleantrue if the app is running on an Apple platform (iOS or macOS).
isDesktopbooleantrue if the app is running on a desktop platform (macOS).
isMobilebooleantrue if the app is running on a mobile platform (iOS or Android).

Platform Support

PlatformSupport
iOSReturns 'ios' as the platform value.
AndroidReturns 'android' as the platform value.
macOSReturns 'macos' as the platform value.

Example

<script setup>
import { usePlatform } from '@thelacanians/vue-native-runtime'

const { platform, isIOS, isAndroid, isMacOS, isApple, isDesktop, isMobile } = usePlatform()

const buttonStyle = {
  backgroundColor: isIOS ? '#007AFF' : isAndroid ? '#6200EE' : '#000000',
  borderRadius: isIOS || isMacOS ? 10 : 4,
  padding: isMacOS ? 8 : 12,
}
</script>

<template>
  <VView :style="{ flex: 1, padding: 20 }">
    <VText :style="{ fontSize: 18, marginBottom: 16 }">
      Platform-Specific Styling
    </VText>

    <VButton
      title="Native Button"
      :style="buttonStyle"
    />

    <VText v-if="isIOS" :style="{ marginTop: 12 }">
      Using San Francisco font defaults
    </VText>
    <VText v-if="isAndroid" :style="{ marginTop: 12 }">
      Using Roboto font defaults
    </VText>
    <VText v-if="isMacOS" :style="{ marginTop: 12 }">
      Running on macOS — menu bar and window controls are available
    </VText>
    <VText v-if="isApple" :style="{ marginTop: 8, color: '#888' }">
      Apple platform: {{ platform }}
    </VText>
    <VText v-if="isMobile" :style="{ marginTop: 8, color: '#888' }">
      Mobile platform — touch optimised layout
    </VText>
    <VText v-if="isDesktop" :style="{ marginTop: 8, color: '#888' }">
      Desktop platform — mouse and keyboard input expected
    </VText>
  </VView>
</template>

Notes

  • Return values are not reactive — they are plain values determined at build time, not Ref wrappers.
  • Uses the __PLATFORM__ compile-time constant injected by the Vite plugin during the build process.
  • Falls back to 'ios' if the __PLATFORM__ constant is not defined.
  • Since values are resolved at build time, dead code elimination can remove unused platform branches in production builds.
  • For conditional logic that does not need to be in a template, prefer using usePlatform over manual typeof checks or global variables.
Edit this page
Last Updated: 2/28/26, 11:24 PM
Contributors: Abdul Hamid, Claude Opus 4.6
Prev
useDimensions