Skip to content

Commit

Permalink
Release 4.0.0 with latest Expo and HT SDKs (#11)
Browse files Browse the repository at this point in the history
* Add SDK init params to AndroidManifest and Info.plist

* Crash the build if publishableKey is not provided

* Bump expo SDK version from 48 to 49

* Bump version from 3.0.0 to 4.0.0

* Format readme

* Update changelog

* Update license

* Update readme

* Remove unused motion description

---------

Co-authored-by: pavel-kuznetsov-hypertrack <[email protected]>
  • Loading branch information
ferologics and pavel-kuznetsov-hypertrack committed Oct 3, 2023
1 parent 5c5d989 commit 34d8b45
Show file tree
Hide file tree
Showing 11 changed files with 7,233 additions and 9,216 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
build
.yarn
.idea
.vscode
3 changes: 0 additions & 3 deletions .justfile

This file was deleted.

21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,48 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.0.0] - 2023-10-03

### Changed

- Updated expo required version to 49
- Updated [React Native HyperTrack SDK](https://github.com/hypertrack/sdk-react-native) version to `11.0.2`
- binds iOS `5.0.2` and Android `7.0.3` native SDKs

## [3.0.0] - 2023-03-07

### Changed

- Updated expo required version to 48

## [2.0.0] - 2023-03-03

### Changed

- Updated expo required version to 47

### Removed

- AppDelegate methods for push notifications (we don't need them anymore for HyperTrack iOS SDK 4.14.0+)

## [1.2.0] - 2023-01-04

### Changed

- Bumped the minimum deployment target to iOS 13, in lockstep with Expo

## [1.1.0] - 2022-10-04

### Changed

- Use ExpoAppDelegateSubscriber protocol to proxy AppDelegate methods ([#2](https://github.com/hypertrack/sdk-expo/pull/2))

## [1.0.0] - 2022-07-29

### Added

- Initial release of the expo plugin.
4 changes: 1 addition & 3 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# License

MIT License

Copyright (c) 2022 HyperTrack
Copyright (c) 2023 HyperTrack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
28 changes: 12 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# HyperTrack Expo config plugin for React Native HyperTrack SDK

![GitHub](https://img.shields.io/github/license/hypertrack/sdk-expo.svg)
![hypertrack-sdk-expo](https://img.shields.io/npm/v/hypertrack-sdk-expo?label=hypertrack-sdk-expo)
[![GitHub](https://img.shields.io/github/license/hypertrack/sdk-expo?color=orange)](./LICENSE)
[![npm](https://img.shields.io/npm/v/hypertrack-sdk-expo)](https://www.npmjs.com/package/hypertrack-sdk-expo)
[![hypertrack-sdk-react-native](https://img.shields.io/badge/hypertrack_sdk_react_native-11.0.2-brightgreen.svg)](https://www.npmjs.com/package/hypertrack-sdk-expo)

[HyperTrack](https://www.hypertrack.com) lets you add live location tracking to your mobile app. Live location is made available along with ongoing activity, tracking controls and tracking outage with reasons.

Expand All @@ -23,11 +24,7 @@ Add `hypertrack-sdk-expo` to [`plugins`](https://docs.expo.io/versions/latest/co
```json
{
"expo": {
"plugins": [
[
"hypertrack-sdk-expo"
]
]
"plugins": [["hypertrack-sdk-expo"]]
}
}
```
Expand All @@ -37,6 +34,7 @@ Add `hypertrack-sdk-expo` to [`plugins`](https://docs.expo.io/versions/latest/co
Use [expo-build-properties](https://docs.expo.dev/versions/latest/sdk/build-properties/) to set build properties.

Run `npx expo install expo-build-properties` and add this to `plugins` in `app.json` or `app.config.js`:

```json
[
"expo-build-properties",
Expand Down Expand Up @@ -70,27 +68,27 @@ For `Bare workflow projects, you can follow the [manual setup guide for React Na
Ensure you use versions that work together!

| `expo` | `hypertrack-sdk-expo` | `hypertrack-sdk-react-native` |
|----------|-----------------------|-------------------------------|
| -------- | --------------------- | ----------------------------- |
| ^45.0.0 | 1.0.0 | ^7.19.1 |
| ^46.0.14 | 1.1.0 | ^8.2.1 |
| ^46.0.14 | 1.2.0 | ^8.2.1 |
| ^47.0.0 | 2.0.0 | ^9.0.0 |
| ^48.0.0 | 3.0.0 | ^9.0.0 |
| ^49.0.0 | 4.0.0 | ^11.0.2 |

## Configuring permission purpose strings

iOS requires specifying [permission purpose strings](https://hypertrack.com/docs/install-sdk-ios/#add-location-and-motion-purpose-strings) in `Info.plist` for app to build.

You can use plugin parameters described below to set the strings.

Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app.
Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app.

If no extra properties are added, defaults will be used.
If no extra properties are added, defaults will be used.

- `locationPermission` (_string_): Sets `NSLocationAlwaysAndWhenInUseUsageDescription`, `NSLocationAlwaysUsageDescription`, `NSLocationWhenInUseUsageDescription`

- `motionPermission` (_string_): Sets `NSMotionUsageDescription`
-

Edit `hypertrack-sdk-expo` item in your `app.json` or `app.config.js`:

Expand All @@ -101,13 +99,11 @@ Edit `hypertrack-sdk-expo` item in your `app.json` or `app.config.js`:
[
"hypertrack-sdk-expo",
{
"locationPermission":
"PUT_YOUR_PERMISSION_HINT_MESSAGE_HERE",
"motionPermission":
"PUT_YOUR_PERMISSION_HINT_MESSAGE_HERE"
"locationPermission": "PUT_YOUR_PERMISSION_HINT_MESSAGE_HERE",
"motionPermission": "PUT_YOUR_PERMISSION_HINT_MESSAGE_HERE"
}
]
]
}
}
```
```
18 changes: 18 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
build:
yarn expo-module clean
yarn expo-module build

clean:
npx yarn clean
npx yarn cache clean --force
rm -rf node_modules ~/Library/Developer/Xcode/DerivedData

release:
npm publish --dry-run
@echo "THIS IS DRY RUN. Check if everything is ok and then run 'npm publish'. Checklist:"
@echo "\t- check the release steps in CONTRIBUTING"

setup:
npx yarn
npx expo install --yarn

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hypertrack-sdk-expo",
"version": "3.0.0",
"version": "4.0.0",
"license": "MIT",
"description": "Config plugin to auto configure hypertrack-sdk-react-native on prebuild",
"homepage": "https://github.com/hypertrack/sdk-expo",
Expand Down Expand Up @@ -31,15 +31,15 @@
"repository": "https://github.com/hypertrack/sdk-expo",
"author": "HyperTrack <[email protected]> (https://hypertrack.com)",
"devDependencies": {
"expo": "^48.0.0",
"expo-module-scripts": "^3.0.0"
"expo": "^49.0.0",
"expo-module-scripts": "^3.1.0"
},
"dependencies": {
"@expo/config-plugins": "^5.0.0",
"expo-modules-core": "^1.0.0"
},
"peerDependencies": {
"expo": "^48.0.0"
"expo": "^49.0.0"
},
"upstreamPackage": "hypertrack-sdk-react-native"
}
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import { withHyperTrackIOS } from "./withHyperTrackIOS";
export type Props = {
locationPermission?: string;
motionPermission?: string;
publishableKey?: string;
automaticallyRequestPermissions?: boolean;
allowMockLocations?: boolean;
loggingEnabled?: boolean;
};
const withHyperTrack: ConfigPlugin<Props> = (config, props) => {
config = withHyperTrackIOS(config, props);
Expand All @@ -19,5 +23,5 @@ const withHyperTrack: ConfigPlugin<Props> = (config, props) => {
export default createRunOncePlugin(
withHyperTrack,
"hypertrack-sdk-expo",
"2.0.0"
"4.0.0"
);
64 changes: 60 additions & 4 deletions src/withHyperTrackAndroid.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import {
ConfigPlugin,
WarningAggregator,
withAndroidManifest,
withAppBuildGradle,
withProjectBuildGradle,
} from "@expo/config-plugins";
import { mergeContents } from "@expo/config-plugins/build/utils/generateCode";
import { Props } from ".";
import { ExpoConfig } from "@expo/config-types";
import {
ManifestApplication,
addMetaDataItemToMainApplication,
} from "@expo/config-plugins/build/android/Manifest";

export const withHyperTrackAndroid: ConfigPlugin<Props> = (config, props) => {
withAndroidPackage(config);
withAndroidPackagingOptions(config);
updateAndroidManifest(config, props);
return config;
};

export const withAndroidPackage: ConfigPlugin = (config) => {
return withProjectBuildGradle(config, (config) => {
Expand Down Expand Up @@ -76,8 +89,51 @@ const packagingOptionsContents = `
}
`;

export const withHyperTrackAndroid: ConfigPlugin<Props> = (config, props) => {
withAndroidPackage(config);
withAndroidPackagingOptions(config);
return config;
const updateAndroidManifest: ConfigPlugin<Props> = (config, props) => {
return withAndroidManifest(config, (newConfig) => {
const {
publishableKey,
allowMockLocations,
loggingEnabled,
automaticallyRequestPermissions,
} = props || {};

if (!publishableKey) {
throw new Error("'publishableKey' param is required");
}

const applications = () => newConfig.modResults.manifest.application;

newConfig.modResults.manifest.application = applications()
?.map((application: ManifestApplication) => {
return addMetaDataItemToMainApplication(
application,
"HyperTrackPublishableKey",
publishableKey!
);
})
?.map((application: ManifestApplication) => {
return addMetaDataItemToMainApplication(
application,
"HyperTrackAllowMockLocations",
allowMockLocations ? "true" : "false"
);
})
?.map((application: ManifestApplication) => {
return addMetaDataItemToMainApplication(
application,
"HyperTrackLoggingEnabled",
loggingEnabled ? "true" : "false"
);
})
?.map((application: ManifestApplication) => {
return addMetaDataItemToMainApplication(
application,
"HyperTrackAutomaticallyRequestPermissions",
automaticallyRequestPermissions ? "true" : "false"
);
});

return newConfig;
});
};
64 changes: 38 additions & 26 deletions src/withHyperTrackIOS.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
import {
ConfigPlugin,
withInfoPlist,
withAppDelegate,
} from "@expo/config-plugins";
import { ConfigPlugin, withInfoPlist } from "@expo/config-plugins";
import { Props } from ".";
import {
mergeContents,
MergeResults,
} from "@expo/config-plugins/build/utils/generateCode";

const LOCATION_PERMISSION_HINT = "You need this permission to allow HyperTrack to track your location"
const LOCATION_PERMISSION_HINT =
"You need this permission to allow HyperTrack to track your location";

const NSLocationAlwaysAndWhenInUseUsageDescription = LOCATION_PERMISSION_HINT
const NSLocationAlwaysUsageDescription = LOCATION_PERMISSION_HINT
const NSLocationWhenInUseUsageDescription = LOCATION_PERMISSION_HINT
const NSMotionUsageDescription =
"To track your movement accurately, HyperTrack Live needs to access motion sensors";
const NSLocationAlwaysAndWhenInUseUsageDescription = LOCATION_PERMISSION_HINT;
const NSLocationAlwaysUsageDescription = LOCATION_PERMISSION_HINT;
const NSLocationWhenInUseUsageDescription = LOCATION_PERMISSION_HINT;

export const withHyperTrackIOS: ConfigPlugin<Props> = (config, props) => {
withBackgroundModes(config, props);
return config;
};

const withBackgroundModes: ConfigPlugin<Props> = (config, props) => {
const {
locationPermission: locationPermissionDescription,
publishableKey,
automaticallyRequestPermissions,
allowMockLocations,
loggingEnabled,
} = props || {};

if (!publishableKey) {
throw new Error("'publishableKey' param is required");
}

const BACKGROUND_MODE_KEYS = ["location", "remote-notification"];
return withInfoPlist(config, (newConfig) => {
// Set UIBackgroundModes
if (!Array.isArray(newConfig.modResults.UIBackgroundModes)) {
newConfig.modResults.UIBackgroundModes = [];
}
Expand All @@ -28,22 +37,25 @@ const withBackgroundModes: ConfigPlugin<Props> = (config, props) => {
newConfig.modResults.UIBackgroundModes.push(key);
}
}
const { locationPermission, motionPermission } = props || {};

// Set permission descriptions
newConfig.modResults.NSLocationAlwaysAndWhenInUseUsageDescription =
locationPermission ?? NSLocationAlwaysAndWhenInUseUsageDescription;
locationPermissionDescription ??
NSLocationAlwaysAndWhenInUseUsageDescription;
newConfig.modResults.NSLocationAlwaysUsageDescription =
locationPermission ?? NSLocationAlwaysUsageDescription;
locationPermissionDescription ?? NSLocationAlwaysUsageDescription;
newConfig.modResults.NSLocationWhenInUseUsageDescription =
locationPermission ?? NSLocationWhenInUseUsageDescription;
newConfig.modResults.NSMotionUsageDescription =
motionPermission ?? NSMotionUsageDescription;
locationPermissionDescription ?? NSLocationWhenInUseUsageDescription;

// Set SDK init params
newConfig.modResults.HyperTrackPublishableKey =
publishableKey ?? "INVALID_PUBLISHABLE_KEY";
newConfig.modResults.HyperTrackAutomaticallyRequestPermissions =
automaticallyRequestPermissions ?? false;
newConfig.modResults.HyperTrackAllowMockLocations =
allowMockLocations ?? false;
newConfig.modResults.HyperTrackLoggingEnabled = loggingEnabled ?? false;

return newConfig;
});
};

export const withHyperTrackIOS: ConfigPlugin<Props> = (config, props) => {
withBackgroundModes(config, props);
return config;
};
Loading

0 comments on commit 34d8b45

Please sign in to comment.