Drawer Content

The content for your drawer navigation content.

Pro component

Requires all-access to use the source code

Apple
Apple
~/app/(drawer)/_layout.tsx
import { DrawerContentComponentProps } from '@react-navigation/drawer';
import { Icon } from '@roninoss/icons';
import { Stack } from 'expo-router';
import { Drawer } from 'expo-router/drawer';
import { Platform, Pressable, View } from 'react-native';

import { Text } from '~/components/nativewindui/Text';
import {
  DrawerContentRoot,
  DrawerContentSection,
  DrawerContentSectionItem,
  DrawerContentSectionTitle,
  getActiveDrawerContentScreen,
} from '~/components/nativewindui/DrawerContent';
import { useColorScheme } from '~/lib/useColorScheme';

export default function DrawerLayout() {
  const { colors } = useColorScheme();
  return (
    <>
      <Stack.Screen options={{ headerShown: false }} />
      <Drawer
        drawerContent={DrawerContent}
        screenOptions={{
          headerShown: true,
          swipeEnabled: true,
          headerTintColor: Platform.OS === 'ios' ? undefined : colors.foreground,
        }}>
        <Drawer.Screen
          name="index"
          options={{
            title: 'Drawer',
          }}
        />
      </Drawer>
    </>
  );
}

function DrawerContent(props: DrawerContentComponentProps) {
  const { colors } = useColorScheme();

  const activeScreen = getActiveDrawerContentScreen(props);

  return (
    <DrawerContentRoot
      navigation={props.navigation}
      actions={
        <Pressable>
          <Icon
            ios={{ name: 'ellipsis.circle', weight: 'light' }}
            materialIcon={{
              name: 'dots-horizontal-circle-outline',
              type: 'MaterialCommunityIcons',
            }}
            color={Platform.select({ default: colors.grey, ios: colors.primary })}
          />
        </Pressable>
      }>
      <DrawerContentSectionTitle type="large">Music</DrawerContentSectionTitle>
      <DrawerContentSection>
        <DrawerContentSectionItem
          icon={{ name: 'play-circle-outline' }}
          isActive={activeScreen === 'index'}
          label="Listen Now"
          rightView={<Text className="px-1 text-sm">1</Text>}
        />
        <DrawerContentSectionItem icon={{ name: 'atom' }} isActive={false} label="React Native" />
        <DrawerContentSectionItem icon={{ name: 'alarm' }} isActive={false} label="Clock" />
      </DrawerContentSection>
      {Platform.OS === 'android' && <View className="bg-border mx-3.5 my-1 h-px" />}
      <DrawerContentSectionTitle>Library</DrawerContentSectionTitle>
      <DrawerContentSection>
        <DrawerContentSectionItem
          icon={{ name: 'microphone-variant' }}
          isActive={false}
          label="Artists"
        />
        <DrawerContentSectionItem icon={{ name: 'music-note' }} isActive={false} label="Songs" />
        <DrawerContentSectionItem icon={{ name: 'monitor' }} isActive={false} label="TV & Movies" />
      </DrawerContentSection>
    </DrawerContentRoot>
  );
}
Logo

Unlock All Pro Screens & Components

Elevate your app with powerful, native-feeling components and templates. Build faster with beautiful ready-to-use designs.

Get all-access

Usage

import {
  DrawerContentRoot,
  DrawerContentSection,
  DrawerContentSectionItem,
  DrawerContentSectionTitle,
  getActiveDrawerContentScreen,
} from '~/components/nativewindui/DrawerContent';
<DrawerContentRoot navigation={props.navigation}>
  <DrawerContentSectionTitle type="large">Section Title</DrawerContentSectionTitle>
  <DrawerContentSection>
    <DrawerContentSectionItem isActive label="Item 1" />
    <DrawerContentSectionItem label="Item 2" />
  </DrawerContentSection>
  <DrawerContentSectionTitle>Section Title 2</DrawerContentSectionTitle>
  <DrawerContentSection>
    <DrawerContentSectionItem label="Item 3" />
    <DrawerContentSectionItem label="Item 4" />
  </DrawerContentSection>
</DrawerContentRoot>

Props

DrawerContentRoot

Inherits all the props from React Native's View component.

PropTypeDescription
actionsReact.ReactNodeActions to be displayed in the drawer content.

DrawerContentSectionTitle

Inherits all the props from NativeWindUI's Text component except for the variant prop.

PropTypeDefaultDescription
type'large' | 'default'defaultThe type of the section title.

DrawerContentSection

Inherits all the props from React Native's View component.

DrawerContentSectionItem

PropTypeDefaultDescription
iconIconProps<'sfSymbol' | 'material'>The icon to be displayed.
labelstringThe label to be displayed.
onPress() => voidThe function to be called when the item is pressed.
isActivebooleanfalseWhether the item is active.
rightViewReact.ReactNodeThe view to be displayed on the right of the item.

Utils

getActiveDrawerContentScreen: A function to get the active drawer content screen.

© Ronin Technologies LLC 2024