https://github.com/queeniecplusplus/react_batteryapp
https://github.com/queeniecplusplus/react_batteryapp
expo react-native
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/queeniecplusplus/react_batteryapp
- Owner: QueenieCplusplus
- Created: 2020-07-20T10:57:15.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-26T22:04:28.000Z (over 3 years ago)
- Last Synced: 2025-02-24T04:44:29.412Z (over 1 year ago)
- Topics: expo, react-native
- Language: JavaScript
- Homepage: https://github.com/QueenieCplusplus/QuickGoThru#react--react-native
- Size: 1.59 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# React_batteryApp
# CodeFile
import * as React from 'react';
// expo install expo-battery
import * as Battery from 'expo-battery';
import {Text, View } from 'react-native';
export default class App extends React.Component {
state = {
batteryLevel: null,
};
componentDidMount() {
this.subscribe();
}
componentWillUnmount() {
this.unsubscribe();
}
async subscribe() {
const batteryLevel = await Battery.getBatteryLevelAsync();
this.setState({ batteryLevel });
this.subscription = Battery.addBatteryLevelListener(({ batteryLevel }) => {
this.setState({ batteryLevel });
//console.log('batteryLevel changed!', batteryLevel);
});
}
unsubscribe() {
this.subscription && this.subscription.remove();
this.subscription = null;
}
render() {
return (
Current Battery Level: {this.state.batteryLevel}
);
}
}