Coder Social home page Coder Social logo

react-native-silent-switch's Introduction

React Native Silent Switch

Detect the iOS silent switch using React Native

Install

Using 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
  • 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

import SilentSwitch from 'react-native-silent-switch'
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()
}
import SilentSwitch from 'react-native-silent-switch'
import StatusBarAlert from 'react-native-statusbar-alert'
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>
  )
}

react-native-silent-switch's People

Contributors

gnestor avatar paulief avatar pimdewitte avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

react-native-silent-switch's Issues

No compatible with latest RN

RN: 50.4
iOS: 11.1
silent switch: 0.1.0

Unable to build, with the following error:
/project/node_modules/react-native/React/Base/RCTBridgeModule.h:54:16: Redefinition of 'RCTMethodInfo'

Constant Hissing Noise when Using this Component

I expect this is purely down to the way that it works, play a sound wait for timeout etc, but it causes the device to constantly emit a quite hissing noise. his becomes more noticeable at night when there is minimal background noise. It then becomes quite audible.

New warning when upgrading RN to 0.56.0

Just upgraded my project to React-Native 0.56.0 (was previously 0.49) and React 16.4.1. Now on app startup, I get the following warning:

Module RCTSilentSwitch requires main queue setup since it overrides 'init' but doesn't implement requiresMainQueueSetup. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.

library update with new react native version

Is this library not updated,

getting below warning

[!] use_native_modules! skipped the react-native dependency 'react-native-silent-switch'. No podspec file was found.
    - Check to see if there is an updated version that contains the necessary podspec file
    - Contact the library maintainers or send them a PR to add a podspec. The react-native-webview podspec is a good example of a package.json driven podspec. See
    https://github.com/react-native-community/react-native-webview/blob/master/react-native-webview.podspec
    - If necessary, you can disable autolinking for the dependency and link it manually. See
    https://github.com/react-native-community/cli/blob/master/docs/autolinking.md#how-can-i-disable-autolinking-for-unsupported-library

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.