1.0.3 • Published 5 years ago

@react-native-community/status-bar v1.0.3

Weekly downloads
192
License
MIT
Repository
-
Last release
5 years ago

react-native-status-bar

npm package CircleCI Status Supports Android and iOS MIT License code style: prettier

Getting started

$ npm install @react-native-community/status-bar --save

Mostly automatic installation

$ react-native link @react-native-community/status-bar

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-status-bar and add RNCStatusBar.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNCStatusBar.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.reactnativecommunity.statusbar.RNCStatusBarPackage; to the imports at the top of the file
  • Add new RNCStatusBarPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-status-bar'
    project(':react-native-status-bar').projectDir = new File(rootProject.projectDir,  '../../node_modules/@react-native-community/status-bar/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
    implementation project(':react-native-status-bar')

Usage

import StatusBar from '@react-native-community/status-bar';

function MyComponent() {
  return (
    <TouchableHighlight
      style={styles.wrapper}
      onPress={() => StatusBar.setHidden(true, "slide");} // or "fade"
    >
      <View style={styles.button}>
        <Text> Hide status bar </Text>
      </View>
    </TouchableHighlight>
  )
}

Api

For cases where using a component is not ideal, there is also an imperative API exposed as static functions on the component. It is however not recommended to use the static API and the component for the same prop because any value set by the static API will get overriden by the one set by the component in the next render.

Constants

currentHeight (Android only) The height of the status bar.

Props

Methods

Type Definitions


Reference

Props

animated

If the transition between status bar property changes should be animated. Supported for backgroundColor, barStyle and hidden.

TypeRequired
boolNo

barStyle

Sets the color of the status bar text.

TypeRequired
enum('default', 'light-content', 'dark-content')No

hidden

If the status bar is hidden.

TypeRequired
boolNo

backgroundColor

The background color of the status bar.

TypeRequiredPlatform
colorNoAndroid

translucent

If the status bar is translucent. When translucent is set to true, the app will draw under the status bar. This is useful when using a semi transparent status bar color.

TypeRequiredPlatform
boolNoAndroid

networkActivityIndicatorVisible

If the network activity indicator should be visible.

TypeRequiredPlatform
boolNoiOS

showHideTransition

The transition effect when showing and hiding the status bar using the hidden prop. Defaults to 'fade'.

TypeRequiredPlatform
enum('fade', 'slide')NoiOS

Methods

setHidden()

static setHidden(hidden: boolean, [animation]: StatusBarAnimation)

Show or hide the status bar

Parameters:

NameTypeRequiredDescription
hiddenbooleanYesHide the status bar.
animationStatusBarAnimationNoOptional animation when changing the status bar hidden property.

setBarStyle()

static setBarStyle(style: StatusBarStyle, [animated]: boolean)

Set the status bar style

Parameters:

NameTypeRequiredDescription
styleStatusBarStyle(
#statusbarstyle)YesStatus bar style to set
animatedbooleanNoAnimate the style change.

setNetworkActivityIndicatorVisible()

static setNetworkActivityIndicatorVisible(visible: boolean)

Control the visibility of the network activity indicator

Parameters:

NameTypeRequiredDescription
visiblebooleanYesShow the indicator.

setBackgroundColor()

static setBackgroundColor(color: string, [animated]: boolean)

Set the background color for the status bar

Parameters:

NameTypeRequiredDescription
colorcolorYesBackground color.
animatedbooleanNoAnimate the style change.

setTranslucent()

static setTranslucent(translucent: boolean)

Control the translucency of the status bar

Parameters:

NameTypeRequiredDescription
translucentbooleanYesSet as translucent.

Type Definitions

StatusBarStyle

Status bar style

Type
$Enum

Constants:

ValueDescription
defaultDefault status bar style (dark for iOS, light for Android)
light-contentDark background, white texts and icons
dark-contentLight background, dark texts and icons (requires API>=23 on Android)

StatusBarAnimation

Status bar animation

Type
$Enum

Constants:

ValueDescription
noneNo animation
fadeFade animation
slideSlide animation