Skip to main content

useRTL

useRTL is a hook that reads and changes the app's layout direction between left-to-right and right-to-left.

Import

import { useRTL } from '@vortexlabs/vortex-native';

Other links

import { Stack, Text, useRTL } from "@vortexlabs/vortex-native";

const Example = () => {
  const [rtl] = useRTL();

  return (
    <Stack gap={2}>
      <Text>{rtl ? "Right to left" : "Left to right"}</Text>
      <Stack direction="row" gap={2}>
        <Text>1. Start</Text>
        <Text>2. Middle</Text>
        <Text>3. End</Text>
      </Stack>
    </Stack>
  );
};

Features

  • Reads the app's layout direction.
  • Changes the direction through React Native I18nManager.
  • Supports mirrored rows and start and end alignment in right-to-left layouts.

Changing Direction

setRTL allows and forces the direction with I18nManager. React Native applies it after the app reloads, so rtl doesn't change in the current session. Reload the app after calling it, for example with expo-updates reloadAsync.

import { reloadAsync } from "expo-updates";

const [rtl, setRTL] = useRTL();

const switchToRTL = async () => {
  setRTL(true);
  await reloadAsync();
};