Skip to content

Commit

Permalink
feat: update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
elencho authored Jul 3, 2024
1 parent 326c93c commit 7560463
Showing 1 changed file with 77 additions and 4 deletions.
81 changes: 77 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,96 @@
# react-native-inactive-time

detect user inactivity from application
👾Library is for you - if you want to detect when user closed app last time and how long it took to open it again.👾

https://github.com/elencho/react-native-inactive-time/assets/53994979/8823d56c-9a6b-4e75-aa46-75a2c0b9003e


## Installation

```sh
npm install react-native-inactive-time
```
```sh
yarn add react-native-inactive-time
```

This library uses [AsyncStorage](https://github.com/react-native-async-storage/async-storage), so it will be good to install it too.

```sh
yarn add @react-native-async-storage/async-storage
```
```sh
npm install @react-native-async-storage/async-storage
```

## Usage

Make sure **useInactivityListener()** is accessible from whole add, add it in App.js or maybe RootNavigator.

```js
import useInactivityListener from 'react-native-inactive-time';
import useInactivityListener from 'react-native-inactive-time';
import CustomText from './CustomText';

export default function App() {
const { elapsedTime, formattedTime } = useInactivityListener();

return (
<View style={styles.container}>
<CustomText />
<Text>Elapsed Time: {elapsedTime}</Text>
<Text>Formatted Time: {formattedTime}</Text>
</View>
);
}
```
**useInactivityListener** is onetime listener, so that means after killing the app elapsedTime, formattedTime extracted from useInactivityListener() may be null.for that we have another method: **getElapsedTime()**

```js
import { multiply } from 'react-native-inactive-time';
import { getElapsedTime, type ITime } from 'react-native-inactive-time';

// ...
const CustomText = () => {
const [elapsedTime, setElapsedTime] = useState<ITime>(null);
useEffect(() => {
onMount();
}, []);

const onMount = async () => {
const elapsedTime = await getElapsedTime();
setElapsedTime(elapsedTime);
};
return (
<View>
<Text>Using UseEffect: {elapsedTime}</Text>
</View>
);
};

const result = await multiply(3, 7);
```

### Methods

Prop | Description | Return Type
------ | ------ | ------
**`useInactivityListener()`** | **REQUIRED** Method which should be defined at top component, can also extend elapsed time and formatted time| void | number | null | string
**`getElapsedTime()`** | method to use inside hooks | number | null
**`elapsedTime`** | time difference from last close to last open in milliseconds | number
**`formattedTime`** | formatted time difference from last close to last open | string


## Plans

Library is beta version right now, I want to add tests and get some user feedback to make is more user friendly, so all you comments matter for me.


## Contact

[LinkediIn](https://www.linkedin.com/in/elene-botchoradze-252796193/): Elene Botchoradze


Email: e.bochoradze@gmail.com


## Contributing

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

0 comments on commit 7560463

Please sign in to comment.