npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-flic

v1.0.0

Published

PBF Flic SDK wrapper for React-Native.

Downloads

8

Readme

react-native-flic

React-Native wrapper for the PBF Flic buttons.

The wrapper basically proxies every event received from the Flic SDK to React-Native.

Getting started

$ npm install react-native-flic --save

Mostly automatic installation

$ react-native link react-native-flic

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-flic and add RNFlic.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNFlic.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.opencii.rn.flic.RNFlicPackage; to the imports at the top of the file
  • Add new RNFlicPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-flic'
    project(':react-native-flic').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-flic/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-flic')

Setup Flic Manager

Important Assuming you have the PBF Flic SDK library, you will have to add it manually in iOS (Xcode). For Android, place the library in react-native-flic/android/libs.

You will need to configure the Flic Manager to use your App ID and App Secret.

Android

  • APP_ID in react-native-flic/android/src/main/java/com/opencii/rn/flic/RNFlicModule.java
  • APP_SECRET in react-native-flic/android/src/main/java/com/opencii/rn/flic/RNFlicModule.java

iOS

  • appID in react-native-flic/ios/RNFlic.m
  • appSecret in react-native-flic/ios/RNFlic.m

Flic Events in React-Native

I tried to keep the events the same for Android and iOS, but the events received from Flic SDK are not the same on both platforms.

| Event name | Description | Properties | Platform | |-----------------------|--------------------------|------------|---------------| | GET_KNOWN_BUTTONS | Sent by getKnownButtons method | - | iOS, Android | | SEARCH_BUTTON_START | Sent by searchButtons method | - | iOS, Android | | SEARCH_BUTTON_TIMEOUT | Sent by searchButtons method | - | iOS, Android | | BUTTON_READY | Button discoverd and connected | rssi, buttonId | iOS, Android | | MANAGER_RESTORED | Flic Manager instance restored | - | iOS | | BLUETOOTH_SWITCHED_STATE | Bluetooth state changed | state | iOS | | BUTTON_PRESSED | Flic Button pressed | - | iOS, Android | | BUTTON_RELEASED | Flic Button released | - | Android | | BUTTON_CONNECTED | Flic Button connected | buttonId | iOS, Android | | BUTTON_DISCONNECTED | Flic Button disconnected | buttonId, error | iOS, Android | | BUTTON_CONNECTING_FAILED | Flic Button failed to connect | buttonId | Android | | FOUND_PRIVATE_BUTTON | Private Flic Button found | buttonId | Android | | FOUND_PUBLIC_BUTTON | Public Flic Button found | buttonId | Android | | CONNECTION_ESTABLISHED | Flic Button connected | buttonId | Android | | BUTTON_ADDED_SUCCESS | Flic Button added | buttonId | Android | | BUTTON_ADDED_FAILED | Flic Button add failed | - | Android |

Flic Methods in React-Native

There are some methods available in RN, you can easily add your own.

| Method name | Description | Arguments | Platform | |-----------------------|--------------------------|------------|---------------| | Flic.getKnownButtons | Get known buttons and connect them, returns event GET_KNOWN_BUTTONS | | iOS, Android | | Flic.makeCall(number) | Make a phone call from RN | number | Android | | Flic.searchButtons | Search for new buttons, returns event FOUND_PRIVATE_BUTTON or FOUND_PUBLIC_BUTTON and connects the button | - | iOS, Android |

Usage

This example uses Native-Base for UI components.

import React, { Component } from 'react';
import { View, NativeEventEmitter } from 'react-native';
import { Button, Text, Badge } from 'native-base';
import Flic from 'react-native-flic';

class FlicExample extends Component {
  constructor(props) {
    super(props);
    this.eventListener = false;
  }

  state = {
    status: '',
    pressCount: 0,
    buttonConnected: false,
  }

  componentDidMount() {
    if (!this.eventListener) {
      const FlicEvents = new NativeEventEmitter(Flic);
      FlicEvents.addListener('FLIC', event => this.receivedEvent(event));
    }

    // Pair known buttons
    Flic.getKnownButtons('FLIC');
  }

  receivedEvent(response) {
    const { pressCount } = this.state;

    console.log('Response received:', response);

    if (response.event) {
      this.setState({ status: response.event });

      switch (response.event) {
        case 'BUTTON_PRESSED':
          // Do whatever you want.
          this.setState({ pressCount: pressCount + 1 });
          break;
        case 'BUTTON_CONNECTED':
          this.setState({ buttonConnected: true });
          break;

        default:
      }
    }
  }

  render() {  
    const { buttonConnected, status, pressCount } = this.state;

    return (
      <View style={{ flex: 1 }}>
        <Button
          block
          key="search-flic-buttons"
          style={{ marginBottom: 10 }}
          onPress={() => Flic.searchButtons('FLIC')}
        >
          <Text>Search for Flic buttons</Text>
        </Button>

        <Button
          block
          key="get-flic-buttons"
          style={{ marginBottom: 10 }}
          onPress={() => Flic.getKnownButtons('FLIC')}
        >
          <Text>Pair Flic buttons</Text>
        </Button>

        {buttonConnected &&
          <Badge success style={{ marginBottom: 10, alignSelf: 'center' }}>
            <Text>Flic button Connected</Text>
          </Badge>
        }

        <Text style={{ marginTop: 10, marginBottom: 10 }}>Flic event: {status}</Text>

        {pressCount > 0 &&
          <Text style={{ fontSize: 24 }}>{pressCount} time(s) pressed</Text>
        }
      </View>
    );
  }
}

export default FlicExample;