# react-native-use-native

> test

Latest version **1.0.4** (published 2023-01-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-native-use-native
pnpm add react-native-use-native
yarn add react-native-use-native
bun add react-native-use-native
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2023-01-16 |
| First published | 2023-01-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 16.0.0 |
| Dependencies | 0 |
| Unpacked size | 61.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Chen Yuanji |
| Maintainers | happycyj |
| Keywords | react-native, android, use-native |

## Links

- npm: https://www.npmjs.com/package/react-native-use-native
- npm.io page: https://npm.io/package/react-native-use-native

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2023-01-16
- 1.0.3 — 2023-01-16
- 1.0.2 — 2023-01-14
- 1.0.1 — 2023-01-14
- 1.0.0 — 2023-01-14

## README

# react-native-use-native

A tool to use native code by JavaScript. Only some Android classes are now supported.

## Updates
Now lastest version is: 1.0.4
Since version 1.0.3, $app is an `ReactApplicationContext` class Object, `$appnative` is a `Context` class Object. But, you only use string `$appnative`. Start from version 1.0.4, you can use `$appnative`.

### Version 1.0.3 Updates
Mainly Update:
1. Since version 1.0.3, the non-basic type will return the internal name(such as `$3`) not string `Refrence Type`.
2. Support Array and List.
3. Support the Boolean values.

## Requirements
### react-native == 0.70 
The lower version and greater version is not tested.

## Installation

```sh
npm install react-native-use-native
```

## Usage
The basic is to use `useJavaStatic` method to call call static methods and use `useJava()` method to call non-static methods.  
### Method declaration
```js
useJavaStatic(className:string,methodName:string,params:any[],packageName:string=""):Promise<string>
useJava(objectName:string,methodName:string,params:any[]):Promise<string>
```
In `useJavaStatic`, when packageName=="",  the className must be the full name includes package name such as `android.widget.Toast` not `Toast`. Of Course, you can write `Toast` in className and `android.widget` in packageName. 

An example about Toast:
```js
import {useJavaStatic,useJava,$app} from 'react-native-use-native';
const toast=await useJavaStatic("android.widget.Toast","makeText",[$app,"HelloToast",0]);
await useJava(toast,"show",[]);
```
The $app refers to the ReactApplicationContext of now application. You also can directly use `useJavaNative`. Please see the source code to know more.

### use Libraries
Some classes(such as `Toast`) is packaged to JavaScript/TypeScript Classes, you can directly use these classes.
```js
import {Toast} from 'react-native-use-native';
let toast=await Toast.makeText($app,"HelloToast",Toast.LENGTH_SHORT);
await toast.show();
```

### Create Java Object
You also can create a Java Object by using `createJavaObject`.
You can use `getJavaObjectValue` to get the value of below's type:int,float,double,Integer,Float,Double and String. Else type will return the string value:Refrence Type. It only can find the object that returned in JS or created by `createJavaObject`. 

### Notes 
The Java/Android packages you want to use must be imported in Java Code.

## Contributing

See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.

## License

MIT

---

Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)

---
_Source: https://npm.io/package/react-native-use-native · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
