mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 12:56:46 +08:00
Add typings react-native-bluetooth-serial (#24908)
This commit is contained in:
committed by
Mohamed Hegazy
parent
81d0e4984d
commit
2a5c6453e9
20
types/react-native-bluetooth-serial/index.d.ts
vendored
Normal file
20
types/react-native-bluetooth-serial/index.d.ts
vendored
Normal 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>;
|
||||
}
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
25
types/react-native-bluetooth-serial/tsconfig.json
Normal file
25
types/react-native-bluetooth-serial/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/react-native-bluetooth-serial/tslint.json
Normal file
1
types/react-native-bluetooth-serial/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user