/
App.tsx
60 lines (55 loc) · 1.76 KB
/
App.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { useEffect, useState } from 'react';
import { Text, TouchableOpacity, View } from 'react-native';
import {
isStepCountingSupported,
parseStepData,
startStepCounterUpdate,
stopStepCounterUpdate,
} from '@uguratakan/react-native-step-counter-improved';
export default function App() {
const [steps, setSteps] = useState(0);
const [supported, setSupported] = useState(false);
const [granted, setGranted] = useState(false);
const askPermission = async () => {
isStepCountingSupported().then((result) => {
console.debug('🚀 - isStepCountingSupported', result);
setGranted(result.granted === true);
setSupported(result.supported === true);
});
};
const startStepCounter = () => {
startStepCounterUpdate(new Date(), (data) => {
console.log('🚀 yeni bir adım atıldı ');
console.debug(parseStepData(data));
setSteps(data.steps);
});
};
useEffect(() => {
askPermission();
startStepCounter();
return () => {
stopStepCounterUpdate();
};
}, []);
return (
<View style={{ flex: 1 }}>
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>StepCounter is Supported:{`${supported}`}</Text>
<Text>StepCounter permission is Granted: {`${granted}`}</Text>
</View>
<Text style={{ alignSelf: 'center' }}>Current Steps:{steps}</Text>
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<TouchableOpacity
style={{
backgroundColor: '#ccc',
justifyContent: 'center',
alignItems: 'center',
width: 300,
height: 50,
}}>
<Text>Get current location</Text>
</TouchableOpacity>
</View>
</View>
);
}