Coder Social home page Coder Social logo

iq-scm / react-native-bars Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zoontek/react-native-bars

0.0 0.0 0.0 3.65 MB

Components to control your app status and navigation bars.

License: MIT License

Shell 0.21% JavaScript 1.42% Ruby 7.30% Objective-C 0.97% Java 51.97% TypeScript 34.43% Objective-C++ 3.70%

react-native-bars's Introduction

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

react-native-bars's People

Contributors

chrismcleod avatar dependabot[bot] avatar leonardoballand avatar zoontek avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.