Skip to content

Commit

Permalink
MOB-83 Change getLocation() return type to Result in RN wrapper (#18)
Browse files Browse the repository at this point in the history
A result handler function added to calls with result (`getLocation()`,
`addGeotag()`) to make sure the result is correct
  • Loading branch information
pavel-kuznetsov-hypertrack authored Jun 9, 2023
1 parent 6a97d59 commit 2e8e098
Show file tree
Hide file tree
Showing 5 changed files with 792 additions and 587 deletions.
2 changes: 2 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

buildscript {
ext {
kotlinVersion = "1.5.32"
buildToolsVersion = "31.0.0"
minSdkVersion = 23
compileSdkVersion = 31
Expand All @@ -20,6 +21,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("com.android.tools.build:gradle:7.2.1")
classpath("com.facebook.react:react-native-gradle-plugin")
classpath("de.undercouch:gradle-download-task:5.0.1")
Expand Down
10 changes: 5 additions & 5 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ PODS:
- fmt (6.2.1)
- glog (0.3.5)
- hermes-engine (0.70.0)
- hypertrack-sdk-react-native (9.2.0):
- HyperTrack/Objective-C (= 4.15.0)
- hypertrack-sdk-react-native (10.0.0):
- HyperTrack/Objective-C (= 4.16.0)
- React-Core
- HyperTrack/Objective-C (4.15.0)
- HyperTrack/Objective-C (4.16.0)
- libevent (2.1.12)
- OpenSSL-Universal (1.1.1100)
- RCT-Folly (2021.07.22.00):
Expand Down Expand Up @@ -548,8 +548,8 @@ SPEC CHECKSUMS:
fmt: ff9d55029c625d3757ed641535fd4a75fedc7ce9
glog: 04b94705f318337d7ead9e6d17c019bd9b1f6b1b
hermes-engine: 8e84f1284180801c1a1b241f443ba64f931ff561
HyperTrack: 4a92dd5067fbf0f203572ea4a3d6548f25fc65e6
hypertrack-sdk-react-native: 42a05d475629a178a251ad995aae38b5f8e70333
HyperTrack: b12dca3f01260a17246740f3601dd00c137d7c93
hypertrack-sdk-react-native: 34cc463ab8efeef91fb170af047e1ef36e8097b8
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OpenSSL-Universal: ebc357f1e6bc71fa463ccb2fe676756aff50e88c
RCT-Folly: 0080d0a6ebf2577475bda044aa59e2ca1f909cda
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"hypertrack-sdk-react-native": "9.2.0",
"hypertrack-sdk-react-native": "10.0.0",
"prettier": "^2.8.4",
"react": "18.1.0",
"react-dom": "^18.2.0",
Expand Down
53 changes: 48 additions & 5 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
EmitterSubscription,
} from 'react-native';

import HyperTrack, {HyperTrackError} from 'hypertrack-sdk-react-native';
import HyperTrack, {HyperTrackError, Location, LocationError, LocationWithDeviation, Result} from 'hypertrack-sdk-react-native';

const Button = ({title, onPress}: {title: string; onPress: () => void}) => (
<Pressable
Expand All @@ -26,7 +26,8 @@ const Button = ({title, onPress}: {title: string; onPress: () => void}) => (
</Pressable>
);

const PUBLISHABLE_KEY = 'Paste_your_publishable_key_here';
const PUBLISHABLE_KEY =
'B42VhCTk6-LoJ-4XcX6Z06achUxt3NFNh-5rejSBUpXeXFMaWJWZF6hBCQvLhrvyGdmUf8uYfYLTXS-Czz2tkw';

const App = () => {
const hyperTrack = useRef<HyperTrack | null>(null);
Expand Down Expand Up @@ -108,7 +109,7 @@ const App = () => {
if (hyperTrack.current !== null) {
try {
const result = await hyperTrack.current?.getLocation();
Alert.alert('Result', JSON.stringify(result));
Alert.alert('Result', getLocationResponseText(result));
} catch (error) {
console.log('error', error);
}
Expand All @@ -123,7 +124,7 @@ const App = () => {
value: Math.random(),
});
console.log('Add geotag: ', result);
Alert.alert('Result', JSON.stringify(result));
Alert.alert('Result', getLocationResponseText(result));
} catch (error) {
console.log('error', error);
}
Expand All @@ -144,7 +145,7 @@ const App = () => {
},
);
console.log('Add geotag with expected location: ', result);
Alert.alert('Result', JSON.stringify(result));
Alert.alert('Result', getLocationWithDeviationResponseText(result));
} catch (error) {
console.log('error', error);
}
Expand Down Expand Up @@ -234,6 +235,48 @@ const App = () => {

export default App;

function getLocationResponseText(
response: Result<Location, LocationError>
) {
switch (response.type) {
case 'success':
return `Location: ${JSON.stringify([
response.value.latitude,
response.value.longitude,
], null, 4)}`;
case 'failure':
switch (response.value.type) {
case 'notRunning':
return 'Not running';
case 'starting':
return 'Starting';
case 'errors':
return `Errors: ${JSON.stringify(response.value, null, 4)}`;
}
}
}

function getLocationWithDeviationResponseText(
response: Result<LocationWithDeviation, LocationError>
) {
switch (response.type) {
case 'success':
return `Location: ${JSON.stringify([
response.value.location.latitude,
response.value.location.longitude,
], null, 4)}\nDeviation: ${response.value.deviation}`;
case 'failure':
switch (response.value.type) {
case 'notRunning':
return 'Not running';
case 'starting':
return 'Starting';
case 'errors':
return `Errors: ${JSON.stringify(response.value, null, 4)}`;
}
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
Expand Down
Loading

0 comments on commit 2e8e098

Please sign in to comment.