Skip to content

Top App Bar Components

Overview

This library provides two separate Top App Bar components:

Top App Bar – The standard app bar, which can include a title, start icons, action buttons, and more. It supports different sizes and scroll-based background color changes. Center Aligned Top App Bar – A variant of the app bar where the title is centered, with optional start and end icons.

Top App Bar

The Top App Bar in its standard form includes a customizable title, start and end icons, and an optional action button list. This variant supports three different sizes (small, medium, large) and is ideal for more complex navigation schemes.

  • Small Top App Bar

small top app bar

  • Medium Top App Bar

medium top app bar

  • Large Top App Bar

large top app bar

  • Top App Bar with on scroll animation
animated top app bar

Properties

namedescriptiontypedefault
titleRequired. Title text to display in the app barstring-
sizeSize of the top app bar: SMALL, MEDIUM, LARGETopAppBarSize-
StartIconCustom start icon (e.g., back button, menu)React.FC-
actionsList of action buttons to displayIconButtonProps[]-
scrollStatus1 if scrolled down (background color changes); 0 if top is reachedSharedValue(number)-
iconPropsAdditional props for iconsT-
titleStyleStyle for the title textTextStyle-
defaultColorColor of the top app bar when at the top (unscrolled)ColorValue-
scrolledColorColor of the top app bar when scrolledColorValue-
animationDurationDuration for the background color animation when scrollinnumber300

Component Usage

typescript
import React from 'react';
import { Animated, NativeSyntheticEvent, NativeScrollEvent } from 'react-native';
import { useSharedValue } from 'react-native-reanimated';
import { TopAppBar } from '@computools/react-native-material-components';

export const MyComponent: React.FC = () => {
  const scrollStatus = useSharedValue(0);

  const onScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
    if (e.nativeEvent.contentOffset.y > 10) { // 10 is the offset threshold when the top app bar changes background color
      scrollStatus.value = 1;
    } else if (e.nativeEvent.contentOffset.y <= 10) {
      scrollStatus.value = 0;
    }
  };

  return (
    <>
      <Animated.ScrollView onScroll={onScroll}>
        {/* Scrollview content */}
      </Animated.ScrollView>
      <TopAppBar scrollStatus={scrollStatus} />
    </>
  );
};

Center Aligned Top App Bar

The Center Aligned Top App Bar component centers the title within the app bar. It can optionally include start and end icons. This is suitable for layouts where the title is the primary focus, and the icons are secondary.

center aligned top app bar

Properties

namedescriptiontypedefault
titleRequired. Title text to display in the center of the app barstring-
StartIconOptional custom start icon (e.g., back button, menu)React.FC-
EndIconOptional custom end icon (e.g., settings, profile)React.FC-
scrollStatus1 if scrolled down (background color changes); 0 if top is reachedSharedValue(number)-
iconPropsAdditional props for iconsT-
titleStyleStyle for the title textTextStyle-
defaultColorColor of the app bar when at the top (unscrolled)ColorValue-
scrolledColorColor of the app bar when scrolled downColorValue-
animationDurationDuration for background color change animationnumber300

Component Usage

typescript
import React from 'react';
import { Animated, NativeSyntheticEvent, NativeScrollEvent } from 'react-native';
import { useSharedValue } from 'react-native-reanimated';
import { CenterAlignedTopAppBar } from '@computools/react-native-material-components';

export const MyComponent: React.FC = () => {
  const scrollStatus = useSharedValue(0);

  const onScroll = (e: NativeSyntheticEvent<NativeScrollEvent>) => {
    if (e.nativeEvent.contentOffset.y > 10) {
      scrollStatus.value = 1;
    } else if (e.nativeEvent.contentOffset.y <= 10) {
      scrollStatus.value = 0;
    }
  };

  return (
    <>
      <Animated.ScrollView onScroll={onScroll}>
        {/* Scrollview content */}
      </Animated.ScrollView>
      <CenterAlignedTopAppBar scrollStatus={scrollStatus} />
    </>
  );
};