• Stars
    star
    288
  • Rank 143,818 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 3 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Components to control your app status and navigation bars.

βž– 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 πŸ’–).

mit licence npm version npm downloads
platform - android platform - ios


android demo

Support

package version react-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:

Setup

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

Android

  1. 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)
  }
}
  1. To set the initial system bars styles, edit your android/app/src/main/res/values/styles.xml file:
<resources xmlns:tools="http://schemas.android.com/tools"><!-- use tools -->

  <!-- make AppTheme inherit from Theme.EdgeToEdge -->
  <style name="AppTheme" parent="Theme.EdgeToEdge">
    <!-- … -->

    <!-- set bars initial styles: true = dark-content, false = light-content -->
    <item name="android:windowLightStatusBar" tools:targetApi="m">true</item>
    <item name="android:windowLightNavigationBar" tools:targetApi="o_mr1">true</item>
  </style>

</resources>

iOS

To set the initial status bar style, go to 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" />
    {/* … */}
  </>
);

Sponsors

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

If you or 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.

Sponsors list

More Repositories

1

react-native-permissions

An unified permissions API for React Native on iOS, Android and Windows.
Objective-C++
4,010
star
2

react-native-bootsplash

πŸš€ Show a splash screen during app startup. Hide it when you are ready.
TypeScript
3,620
star
3

react-native-localize

🌍 A toolbox for your React Native app localization
TypeScript
2,259
star
4

react-native-dev-menu

Add custom items to the React Native dev menu.
Java
204
star
5

react-native-bootsplash-lottie-example

Java
53
star
6

react-atomic-state

Dead simple React global state management based on use-sync-external-store.
TypeScript
47
star
7

valienv

A simple environment variables validator for Node.js, web browsers and React Native βœ“
TypeScript
32
star
8

prisma-cursor-pagination

Relay cursor pagination helpers for prisma
TypeScript
15
star
9

purestead

Use Laravel Homestead the Vagrant way.
Shell
14
star
10

vagrant-rethinkdb

Try RethinkDB with Vagrant
JavaScript
6
star
11

react-router-with-chicane

4
star
12

react-native-module-template

Java
3
star
13

sound-mind.css

Default HTML elements style for modern daysΒ Β πŸ‘€
CSS
3
star
14

lillefp15-demo

A reason-react-native app to check Paris piscines pools opening hours
Reason
3
star
15

types-testing-library-vitest-dom

TypeScript definitions for @testing-library/jest-dom (with vitest)
3
star
16

PSD-Browser-Preview

Sync Photoshop and your browser
JavaScript
3
star
17

next-type-routes

An experiment to make next.js routes usage safer.
TypeScript
2
star
18

twitter-eraser

A simple script to purge old tweets
JavaScript
2
star
19

personal-website

Reason
1
star
20

ScrollViewIssue

JavaScript
1
star
21

punk-api-exercise

HTML
1
star
22

sign-machine-poc

TypeScript
1
star
23

rn-location-permission-example

Java
1
star
24

wff

An extend based semantic grid for Sass
CSS
1
star
25

bump-app-package-version

A GitHub action to bump your app package.json version
TypeScript
1
star