# react-native-silent-switch

> Detect the iOS silent switch using React Native

Latest version **0.1.0** (published 2017-10-11) · ISC license · 0 weekly downloads

## Install

```sh
npm install react-native-silent-switch
pnpm add react-native-silent-switch
yarn add react-native-silent-switch
bun add react-native-silent-switch
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2017-10-11 |
| First published | 2016-04-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 20 |
| Author | Grant Nestor |
| Maintainers | gnestor |
| Keywords | react-native, ios, silent, mute, sound, switch |

## Links

- npm: https://www.npmjs.com/package/react-native-silent-switch
- Repository: https://github.com/gnestor/react-native-silent-switch
- Issues: https://github.com/gnestor/react-native-silent-switch/issues
- npm.io page: https://npm.io/package/react-native-silent-switch

## Recent versions

- 0.1.0 (latest) — 2017-10-11
- 0.0.2 — 2016-05-24
- 0.0.1 — 2016-04-30

## README

# React Native Silent Switch

Detect the iOS silent switch using React Native

## Install

### Using [rnpm](https://github.com/rnpm/rnpm)

* Install: `rnpm install react-native-silent-switch`
* Add `mute.caf` from the library to your project bundle
  * Project Navigator > [YOUR PROJECT NAME] > Build Phases > Copy Bundle Resources
* Verify that `$(SRCROOT)/../../node_modules/react-native/React` is in the library's header search paths for both Debug and Release schemes
    * Project Navigator > RCTSilentSwitch.xcodeproj > Build Settings > Header Search Paths > Debug AND Release

### Manually

* Install: `npm install react-native-silent-switch --save`
* Link library in Xcode: See [React Native guide](https://facebook.github.io/react-native/docs/linking-libraries-ios.html)
* Add `mute.caf` from the library to your project bundle
  * Project Navigator > [YOUR PROJECT NAME] > Build Phases > Copy Bundle Resources
* Verify that `$(SRCROOT)/../../node_modules/react-native/React` is in the library's header search paths for both Debug and Release schemes
  * Project Navigator > RCTSilentSwitch.xcodeproj > Build Settings > Header Search Paths > Debug AND Release

## Usage

```js
import SilentSwitch from 'react-native-silent-switch'
```

```js
componentDidMount() {
  // Listen for silent switch toggle events
  SilentSwitch.addEventListener(silent => {
    // When switched to silent, the callback will return true. When switched from silent, it will return false.
    if (silent) this.navigator.push({id: 'SilentAlert'})
  })
}

componentWillUnmount() {
  SilentSwitch.removeEventListener()
}
```

## Usage with [react-native-statusbar-alert](https://github.com/gnestor/react-native-statusbar-alert)

```js
import SilentSwitch from 'react-native-silent-switch'
import StatusBarAlert from 'react-native-statusbar-alert'
```

```js
componentDidMount() {
  SilentSwitch.addEventListener(silent => {
    if (silent) {
      this.setState({
        alerts: [{
          message: 'Silent Switch ON',
          onPress: () => this.navigator.push({id: 'SilentAlert'})
        }, ...this.state.alerts]
      })
    } else {
      this.setState({
        alerts: this.state.alerts.filter(alert => alert.message !== 'Silent Switch ON')
      })
    }
  })
}

componentWillUnmount() {
  SilentSwitch.removeEventListener()
}

render() {
  return (
    <View style={styles.container}>
      <StatusBarAlert
        visible={this.state.alerts.length > 0}
        {...this.state.alerts[0]}
      />
      <Navigator
        initialRoute={initialRoute}
        renderScene={this.renderScene}
        navigationBar={
          <Navigator.NavigationBar
            routeMapper={routeMapper}
            style={{top: -20}}
          />
        }
      />
    </View>
  )
}
```

---
_Source: https://npm.io/package/react-native-silent-switch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
