# react-native-calculator

> React Native Calculator and Calculator Input Component

Latest version **0.5.2** (published 2019-02-22) · MIT license · 0 weekly downloads

## Install

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

## Health

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

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

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.2 |
| Published | 2019-02-22 |
| First published | 2018-06-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 79.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 27 |
| Author | Budi Adiono |
| Maintainers | budiadiono |
| Keywords | react, native, calculator, component, input |

## Links

- npm: https://www.npmjs.com/package/react-native-calculator
- Repository: https://github.com/budiadiono/react-native-calculator
- Homepage: https://github.com/budiadiono/react-native-calculator#readme
- Issues: https://github.com/budiadiono/react-native-calculator/issues
- npm.io page: https://npm.io/package/react-native-calculator

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.5.2 (latest) — 2019-02-22
- 0.5.1 — 2019-02-07
- 0.5.0 — 2018-12-08
- 0.4.0 — 2018-11-20
- 0.3.0 — 2018-10-17
- 0.2.4 — 2018-09-25
- 0.2.3 — 2018-09-25
- 0.2.2 — 2018-09-24
- 0.2.1 — 2018-08-06
- 0.2.0 — 2018-07-13
- 0.1.0 — 2018-07-10
- 0.0.2 — 2018-06-12
- 0.0.1 — 2018-06-12

## README

# React Native Calculator

[![npm version](https://badge.fury.io/js/react-native-calculator.svg)](https://badge.fury.io/js/react-native-calculator)
[![build status](https://travis-ci.org/budiadiono/react-native-calculator.svg)](https://travis-ci.org/budiadiono/react-native-calculator)

Simple react native calculator and calculator input component.

## Installation

Using npm:

```
npm i -S react-native-calculator
```

or yarn:

```
yarn add react-native-calculator
```

## Demo

<a href="https://snack.expo.io/@budiadiono/react-native-calculator-example" target="_blank">
<img src="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=exp://expo.io/@budiadiono/react-native-calculator-example">
</a>

## Calculator Component

<img alt="react-native-gifted-chat" src="https://thumbs.gfycat.com/EnchantingVainFallowdeer-size_restricted.gif" width="261" height="464" /> <img alt="react-native-gifted-chat" src="https://thumbs.gfycat.com/BeautifulTimelyAmoeba-size_restricted.gif" width="261" height="464" />

### Usage

```javascript
import React from 'react'
import { View } from 'react-native'
import { Calculator } from 'react-native-calculator'

export default class App extends React.Component {
  render() {
    return (
      <View style={{ flex: 1 }}>
        <Calculator style={{ flex: 1 }} />
      </View>
    )
  }
}
```

### Props

All props in [common props](#common-props) and...

| Prop Name       | Data Type                                   | Default Value | Description                         |
| --------------- | ------------------------------------------- | ------------- | ----------------------------------- |
| hasAcceptButton | boolean                                     | false         | Show accept button after calculate. |
| style           | ViewStyle                                   |               | Container style.                    |
| onCalc          | `(value : number , text : string ) => void` |               | Calculate button click event.       |
| onAccept        | `(value : number , text : string ) => void` |               | Accept button click event.          |
| hideDisplay     | boolean                                     | false         | Hide display text field.            |

## Calculator Input Component

<img alt="react-native-gifted-chat" src="https://thumbs.gfycat.com/DismalSpotlessAcaciarat-size_restricted.gif" width="261" height="464" />

### Usage

```javascript
import React from 'react'
import { View } from 'react-native'
import { CalculatorInput } from 'react-native-calculator'

export default class App extends React.Component {
  render() {
    return (
      <View>
        <CalculatorInput
          fieldTextStyle={{ fontSize: 24 }}
          fieldContainerStyle={{ height: 36 }}
        />
      </View>
    )
  }
}
```

### Props

All props in [common props](#common-props) and...

| Prop Name           | Data Type                                               | Default Value | Description                                                                              |
| ------------------- | ------------------------------------------------------- | ------------- | ---------------------------------------------------------------------------------------- |
| modalAnimationType  | 'none'                                                  | 'slide'       | 'fade'                                                                                   | slide | Modal animation type. |
| modalBackdropStyle  | ViewStyle                                               |               | Style of modal backdrop.                                                                 |
| fieldContainerStyle | ViewStyle                                               |               | Text field container style.                                                              |
| fieldTextStyle      | TextStyle                                               |               | Text style.                                                                              |
| onChange            | `(value : number , text : string ) => void`             |               | Value change event.                                                                      |
| prefix              | string                                                  |               | Prefix.                                                                                  |
| suffix              | string                                                  |               | Suffix.                                                                                  |
| onBeforeChange      | `(value : number , text : string ) => boolean`          |               | Called before changes applied. Return true if changes are accepted.                      |
| onBeforeChangeAsync | `(value : number , text : string ) => Promise<boolean>` |               | Called asynchronously before changes applied. Resolve with true if changes are accepted. |

## Common Props

| Prop Name                    | Data Type                                          | Default Value | Description                                             |
| ---------------------------- | -------------------------------------------------- | ------------- | ------------------------------------------------------- |
| decimalSeparator             | string                                             | .             | Decimal separator sign.                                 |
| thousandSeparator            | string                                             | ,             | Thousand separator sign.                                |
| numericButtonBackgroundColor | string                                             | #ffffff       | Numeric button background color.                        |
| numericButtonColor           | string                                             | #aaaaaa       | Numeric text button color.                              |
| actionButtonBackgroundColor  | string                                             | #e7e5e3       | Action button background color.                         |
| actionButtonColor            | string                                             | #000000       | Action text button color.                               |
| calcButtonBackgroundColor    | string                                             | #ff8d00       | Calculate button background color.                      |
| calcButtonColor              | string                                             | #ffffff       | Calculator text button color.                           |
| acceptButtonBackgroundColor  | string                                             | #14CC60       | Accept button background color.                         |
| acceptButtonColor            | string                                             | #ffffff       | Accept text button color.                               |
| displayBackgroundColor       | string                                             | #ffffff       | Digit display background color.                         |
| displayColor                 | string                                             | #000000       | Digit display text color.                               |
| borderColor                  | string                                             | #52525B       | Border color.                                           |
| fontSize                     | number                                             | 18            | Button text font size.                                  |
| value                        | number                                             | 0             | Initial value.                                          |
| width                        | number                                             | (auto)        | Calculator component width.                             |
| height                       | number                                             | (auto)        | Calculator component height.                            |
| displayHeight                | number                                             | (auto)        | Digit display container height.                         |
| keyboardHeight               | number                                             | (auto)        | Keyboard container height.                              |
| onTextChange                 | (text: string) => void                             |               | Text change event.                                      |
| displayTextAlign             | `"auto" / "left" / "right" / "center" / "justify"` | `"left"`      | Digit align display.                                    |
| noDecimal                    | boolean                                            | false         | Hide decimal separator button to disable decimal value. |
| roundTo                      | number                                             | 2             | How many decimal places to round the value              |

## License

MIT

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