Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

react-native-bars

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-native-bars

Components to control your app status and navigation bars.

Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
539
-55.34%
Maintainers
1
Weekly downloads
 
Created
Source

➖ react-native-bars

Components to control your app status and navigation bars.
Inspired by the built-in StatusBar module and react-native-transparent-status-and-navigation-bar by @MoOx (Thanks to them 💖).

npm version npm MIT Platform - Android Platform - iOS


android demo

Funding

This library helped you? Consider sponsoring!

This module is provided as is, I work on it in my free time.

If your company uses it in a production app, consider sponsoring this project 💰. You also can contact me for premium enterprise support, help with issues, prioritize bugfixes, feature requests, etc.

Support

package versionreact-native version
2.0.0+0.70.0+
1.0.0+0.65.0+

Installation

$ npm install --save react-native-bars
# --- or ---
$ yarn add react-native-bars

Recommendations

This module will works best with:

  • react-native-safe-area-context: A library to handle safe area insets and avoid drawing below status and navigation bars.

Setup

ℹ️ For react-native < 0.70 setup, use latest v1 and follow this README.

Android

  • Edit your android/app/src/main/java/com/yourprojectname/MainActivity.java file:
// …

// Add these required imports:
import android.os.Bundle;
import com.zoontek.rnbars.RNBars;

public class MainActivity extends ReactActivity {

  // …

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState); // or super.onCreate(null) with react-native-screens
    RNBars.init(this, "dark-content"); // <- initialize with initial bars styles (could be light-content)
  }
}
  • To setup initial bar styles on Android < 8.1, edit your android/app/src/main/res/values/styles.xml file:
    👉 Dont forget to edit android:windowLightStatusBar to match your initial styles.
<resources>

  <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <!-- … -->

    <!-- Set status bar background transparent -->
    <item name="android:statusBarColor">@android:color/transparent</item>

    <!-- Navigation bar will stay translucent on Android < 8.1 -->
    <item name="android:windowTranslucentNavigation">true</item>
  </style>

</resources>
  • For Android >= 8.1, create (or edit) your android/app/src/main/res/values-v27/styles.xml file:
    👉 Dont forget to edit android:{windowLightStatusBar,windowLightNavigationBar} to match your initial styles.
<resources xmlns:tools="http://schemas.android.com/tools">

  <style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
    <!-- … -->

    <!-- Set system bars background transparent -->
    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>

    <!-- Disable auto contrasted system bars background -->
    <item name="android:enforceStatusBarContrast" tools:targetApi="q">false</item>
    <item name="android:enforceNavigationBarContrast" tools:targetApi="q">false</item>
  </style>

</resources>

iOS

You can setup your initial status bar style in Xcode > General > Deployment Info:

Xcode setup

Usage

import { NavigationBar, StatusBar, SystemBars } from "react-native-bars";

const App = () => {
  return (
    <>
      <StatusBar animated={true} barStyle="light-content" />
      <NavigationBar barStyle="light-content" />

      {/* Or, to update both with one component: */}
      <SystemBars animated={true} barStyle="light-content" />
    </>
  );
};

API

<StatusBar />

A component to control your app status bar.

import { StatusBar } from "react-native-bars";

type StatusBarProps = {
  // Should transition between status bar property changes be animated? (has no effect on Android)
  animated?: boolean;
  // Sets the color of the status bar content
  barStyle: "light-content" | "dark-content";
};

const App = () => (
  <>
    <StatusBar animated={true} barStyle="dark-content" />
    {/* … */}
  </>
);

StatusBar.pushStackEntry

const entry: StatusBarProps = StatusBar.pushStackEntry(
  props /*: StatusBarProps*/,
);

StatusBar.popStackEntry

StatusBar.popStackEntry(entry/*: StatusBarProps*/): void;

StatusBar.replaceStackEntry

const entry: StatusBarProps = StatusBar.replaceStackEntry(
  entry /*: StatusBarProps*/,
  props /*: StatusBarProps*/,
);

<NavigationBar />

A component to control your app navigation bar. It has no effect on iOS and Android < 8.1.

import { NavigationBar } from "react-native-bars";

type NavigationBarProps = {
  // Sets the color of the navigation bar content
  barStyle: "light-content" | "dark-content";
};

const App = () => (
  <>
    <NavigationBar barStyle="dark-content" />
    {/* … */}
  </>
);

NavigationBar.pushStackEntry

const entry: NavigationBarProps = NavigationBar.pushStackEntry(
  props /*: NavigationBarProps*/,
);

NavigationBar.popStackEntry

NavigationBar.popStackEntry(entry/*: NavigationBarProps*/): void;

NavigationBar.replaceStackEntry

const entry: NavigationBarProps = NavigationBar.replaceStackEntry(
  entry /*: NavigationBarProps*/,
  props /*: NavigationBarProps*/,
);

<SystemBars />

A component to control both your app status and navigation bars.

import { SystemBars } from "react-native-bars";

type SystemBarsProps = {
  // Should transition between bars property changes be animated? (has no effect on Android)
  animated?: boolean;
  // Sets the color of the bars content
  barStyle: "light-content" | "dark-content";
};

const App = () => (
  <>
    <SystemBars animated={true} barStyle="dark-content" />
    {/* … */}
  </>
);

Keywords

navigation-bar

FAQs

Package last updated on 10 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts