-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
use-battery-state.tsx
33 lines (30 loc) · 1.01 KB
/
use-battery-state.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react';
import { Caption, Text } from 'react-native-paper';
import { useBatteryState } from 'use-expo';
import { Example, Information, Link, Page } from '../../atoms';
import { MoleculeProps } from '../../providers/molecule';
import { docs } from '../../providers/urls';
import { batteryStates } from './battery-states';
import { BatteryState } from 'expo-battery';
export const UseBatteryState: React.SFC<MoleculeProps> = (props) => {
const [batteryState] = useBatteryState();
return (
<Page
title={props.name}
subtitle={props.description}
>
<Information>
This example only uses the <Link url={docs.battery}>Battery</Link> module.
It renders the current battery state, received from the listener.
</Information>
<Example>
<Caption>Battery state</Caption>
<Text>{batteryStates[batteryState || BatteryState.UNKNOWN]}</Text>
</Example>
</Page>
);
};
UseBatteryState.defaultProps = {
name: 'useBatterySate',
description: 'get and/or listen to the battery state',
};