1.0.8 • Published 5 years ago

react-native-light v1.0.8

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

react-native-light

npm version

React Native module for mobile flashlight. (IOS / ANDROID)

Installation

Using yarn:

yarn add react-native-light

or using npm:

npm install --save react-native-light

Linking

react-native link react-native-light

Usage

Methods

Method NameReturn typeNotes
turnLightOntrun light on
turnLightOffturn light off
toggletoggle light
isLightActiveBooleanif light is active

Events

Event NameReturnsNotes
onLightTurnedOnCallback that is called once the light turned on.
onLightTurnedOffCallback that is called once the light turned off.

Example

import React, { Component } from 'react';
import { StyleSheet, Button, View } from 'react-native';
import { turnLightOn, turnLightOff, toggle, isLightActive, lightEventEmitter } from "react-native-light";

export default class App extends Component {  

  async showState() {
    const state = await isLightActive();
    alert(state);
  }

  componentDidMount() {
    lightEventEmitter.addListener('onLightTurnedOn', () => {
      alert('you just turned on the light')
    });
    lightEventEmitter.addListener('onLightTurnedOff', () => {
      alert('you just turned off the light')
    });
  }

  render() {
    return (
      <View style={styles.container}>
        <View style={styles.buttons}>
          <Button title='on' onPress={() => turnLightOn()} />
          <Button title='off' onPress={() => turnLightOff()} />
          <Button title='toggle' onPress={() => toggle()} />
          <Button title='state' onPress={() => this.showState()} />
        </View>
      </View>
      );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
    backgroundColor: '#F5FCFF'
  },
  buttons: {
    justifyContent: 'space-between',
    alignItems: 'center',
    height: 200
  }
});
1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago