Add typings react-native-bluetooth-serial (#24908)

This commit is contained in:
Rodrigo Weber
2018-04-11 15:39:29 -03:00
committed by Mohamed Hegazy
parent 81d0e4984d
commit 2a5c6453e9
4 changed files with 68 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
// Type definitions for react-native-bluetooth-serial 1.0
// Project: https://github.com/rusel1989/react-native-bluetooth-serial
// Definitions by: Rodrigo Weber <https://github.com/RodrigoAWeber>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.6
import * as React from "react";
import * as ReactNative from "react-native";
export type Buffer = (data: number[]) => void;
export namespace BluetoothSerial {
function on(eventName: string, handler: () => void): void;
function removeListener(eventName: string, handler: () => void): void;
function write(data: Buffer | string): Promise<boolean>;
function list(): Promise<Array<{ id: string, name: string }>>;
function isEnabled(): Promise<boolean>;
function connect(id: string): Promise<void>;
function disconnect(): Promise<void>;
function isConnected(): Promise<boolean>;
}

View File

@@ -0,0 +1,22 @@
import * as React from 'react';
import { View, Text } from 'react-native';
import { BluetoothSerial } from 'react-native-bluetooth-serial';
class Example extends React.Component {
async componentDidMount() {
const devices = await BluetoothSerial.list();
await BluetoothSerial.connect(devices[0].id);
BluetoothSerial.write("Hello");
await BluetoothSerial.disconnect();
}
render() {
return (
<View>
<Text>Printer</Text>
</View>
);
}
}

View File

@@ -0,0 +1,25 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6",
"dom"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"react-native-bluetooth-serial-tests.tsx"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }