@situm/react-native 3.16.3 → 3.17.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,13 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import React, { createContext, type MutableRefObject, useReducer } from "react";
2
+ import React, {
3
+ createContext,
4
+ type MutableRefObject,
5
+ useEffect,
6
+ useReducer,
7
+ useState,
8
+ } from "react";
3
9
 
10
+ import SitumPlugin from "../../sdk";
4
11
  import {
5
12
  type Building,
6
13
  type Directions,
@@ -22,6 +29,7 @@ export interface State {
22
29
  webViewRef: MutableRefObject<undefined> | undefined;
23
30
  sdkInitialized: boolean;
24
31
  user?: User;
32
+ apiDomain?: string;
25
33
  location?: Location;
26
34
  locationStatus?: LocationStatusName;
27
35
  buildings: Building[] | null;
@@ -38,6 +46,7 @@ export const initialState: State = {
38
46
  webViewRef: undefined,
39
47
  sdkInitialized: false,
40
48
  user: undefined,
49
+ apiDomain: undefined,
41
50
  location: undefined,
42
51
  locationStatus: undefined,
43
52
  buildings: null,
@@ -101,7 +110,7 @@ const store = createStore<State>({
101
110
  },
102
111
  setBuildingIdentifier: (
103
112
  state: State,
104
- payload: State["buildingIdentifier"]
113
+ payload: State["buildingIdentifier"],
105
114
  ) => {
106
115
  return { ...state, buildingIdentifier: payload };
107
116
  },
@@ -120,6 +129,10 @@ export const selectUser = (state: State) => {
120
129
  return state.user;
121
130
  };
122
131
 
132
+ export const selectApiDomain = (state: State) => {
133
+ return state.apiDomain;
134
+ };
135
+
123
136
  export const selectLocation = (state: State) => {
124
137
  return state.location;
125
138
  };
@@ -181,7 +194,7 @@ export const {
181
194
  * Context specifically to store the only instance of our hook.
182
195
  */
183
196
  export const UseSitumContext = createContext<{ useSitum: any } | undefined>(
184
- undefined
197
+ undefined,
185
198
  );
186
199
 
187
200
  const UseSitumProvider: React.FC<{ children: React.ReactNode }> = ({
@@ -199,19 +212,56 @@ const UseSitumProvider: React.FC<{ children: React.ReactNode }> = ({
199
212
  };
200
213
 
201
214
  /**
202
- * Main context of the application, stores the plugins' state.
215
+ * Main context of the application, stores the plugin's state.
203
216
  */
204
217
  const SitumProvider: React.FC<
205
218
  React.PropsWithChildren<{
219
+ /**
220
+ * Your Situm email account.
221
+ */
206
222
  email?: string;
207
- apiKey?: string;
223
+ /**
224
+ * Your Situm API key. Find your API key at your [Situm dashboard's profile](https://dashboard.situm.com/accounts/profile)
225
+ *
226
+ * When specifying a valid situm API key in this parameter, you won't need to call later on the `SitumPlugin.init()` & `SitumPlugin.setApiKey()` methods,
227
+ * and also you won't need to specify `MapViewConfiguration.situmApiKey` when configuring your MapView.
228
+ */
229
+ apiKey: string;
230
+ /**
231
+ * Set the API domain that will be used by the native SDKs and MapView to obtain the situm's data.
232
+ *
233
+ * When specifying a valid domain in this parameter, you won't need to call later on the `SitumPlugin.setDashboardURL()` method,
234
+ * and also you won't need to specify `MapViewConfiguration.apiDomain` when configuring your MapView.
235
+ *
236
+ * Defaults to "api.situm.com"
237
+ */
238
+ apiDomain?: string;
208
239
  }>
209
- > = ({ email, apiKey, children }) => {
240
+ > = ({ email, apiKey, apiDomain, children }) => {
210
241
  const [state, dispatch] = useReducer(store.reducer, {
211
242
  ...store.initialState,
212
243
  user: { email, apiKey },
244
+ apiDomain: apiDomain,
213
245
  });
214
246
 
247
+ const [isInitialized, setIsInitialized] = useState(false);
248
+
249
+ useEffect(() => {
250
+ try {
251
+ SitumPlugin.init();
252
+ apiDomain && SitumPlugin.setDashboardURL(apiDomain);
253
+ if (!apiKey) {
254
+ throw new Error(
255
+ "Please specify SitumProvider.apiKey to be able to successfully use SitumPlugin and MapView.",
256
+ );
257
+ }
258
+ SitumPlugin.setApiKey(apiKey);
259
+ } catch (e) {
260
+ console.error(`SitumProvider > Could not initialize ${e}`);
261
+ }
262
+ setIsInitialized(true);
263
+ }, [apiKey, apiDomain]);
264
+
215
265
  return (
216
266
  <SitumContext.Provider
217
267
  value={{
@@ -219,7 +269,14 @@ const SitumProvider: React.FC<
219
269
  dispatch,
220
270
  }}
221
271
  >
222
- <UseSitumProvider>{children}</UseSitumProvider>
272
+ {/**
273
+ * Make sure to execute first SitumProvider's initialization & authentication useEffect(),
274
+ * before letting children components rendering MapView or calling SitumPlugin methods.
275
+ *
276
+ * If we directly let the `children` render, the children's useEffect() will execute before SitumProvider's useEffect().
277
+ * This causes a crash when the children wants to access SitumPlugin before it is initialized.
278
+ */}
279
+ <UseSitumProvider>{isInitialized ? children : <></>}</UseSitumProvider>
223
280
  </SitumContext.Provider>
224
281
  );
225
282
  };
package/README.md DELETED
@@ -1,187 +0,0 @@
1
- <p align="center"> <img width="233" src="https://situm.com/wp-content/themes/situm/img/logo-situm.svg" style="margin-bottom:1rem" /> <h1 align="center">@situm/react-native</h1> </p>
2
-
3
- <p align="center" style="text-align:center">
4
-
5
- [Situm Wayfinding](https://situm.com/wayfinding) for React Native. Integrate plug&play navigation experience with indoor maps, routes and turn-by-turn directions in no time. With the power of [Situm](https://www.situm.com/).
6
-
7
- </p>
8
-
9
- <div align="center" style="text-align:center">
10
-
11
- [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)
12
- ![Latest version:](https://img.shields.io/npm/v/@situm/react-native/latest)
13
- ![Node compatibility:](https://img.shields.io/node/v/@situm/react-native)
14
- [![TypeScript](https://badges.frapsoft.com/typescript/code/typescript.svg?v=101)](https://github.com/ellerbrock/typescript-badges/)
15
- ![React Native](https://img.shields.io/badge/react--native%40lastest-0.79.1-blueviolet)
16
-
17
- </div>
18
-
19
- ## Introduction
20
-
21
- Situm React Native Plugin is a set of utilities that allow any developer to build React Native location based apps using [Situm](https://www.situm.com/)'s indoor positioning system.
22
-
23
- This plugin has two parts:
24
-
25
- - The base SDK, the building blocks that allow you to:
26
-
27
- - obtain information related to buildings where Situm's positioning system is already configured: floorplans, points of interest, geotriggered events, etc.
28
- - retrieve the location of the smartphone inside these buildings (position, orientation, and floor where the smartphone is).
29
- - compute a route from a point A (e.g. where the smartphone is) to a point B (e.g. any point of interest within the building).
30
- - trigger notifications when the user enters a certain area.
31
-
32
- - A full featured and easy to integrate React Native component that allows you to:
33
- - show your cartography on a map
34
- - show the user location on the map
35
- - calculate point-to-point wayfinging routes
36
- - explore points of interest on your buildings on the map
37
-
38
- ![Preview of WYF module](./plugin/docs/assets/preview.png)
39
-
40
- <!-- ## Table of contents
41
-
42
- - [Setup your account](#setup-your-account)
43
- - [Installing pre-requisites](#installing-pre-requisites)
44
- - [Using the Plugin](#using-the-plugin)
45
- - [Getting Started](#getting-started)
46
- - [Accessing plugin object](#accessing-plugin-object)
47
- - [Methods](#methods)
48
- - [Submitting Contributions](#submitting-contributions)
49
- - [License](#license)
50
- - [More information](#more-information)
51
- - [Support information](#support-information) -->
52
-
53
- ## Getting started
54
-
55
- There is a comprehensive tutorial on how to set-up a new application using this plugin on the Situm [documentation page](https://situm.com/docs/a-basic-react-native-app/).
56
-
57
- Below you will find the basic steps to install and configure the plugin on your React Native project. These steps have already been done for you in the example application of this repository, but they are required for other projects.
58
-
59
- ## Running the example
60
-
61
- Check the [example/README](./example/README.md) file of this repository to create your first React Native application using Situm React Native. In this example app you will find example screens for each method the plugin exposes.
62
-
63
- ### Configure the plugin on your React Native project
64
-
65
- #### Install the plugin
66
-
67
- Firstly you need to setup react-native development environment. To get started please follow instructions under section **React Native CLI Quickstart** on this [guide.](https://reactnative.dev/docs/environment-setup)
68
-
69
- To add the Situm dependency to your React Native project, you can use the `yarn` or `npm` command. To add this dependency to your project, you can use the following command in your terminal:
70
-
71
- ```shell
72
- yarn add @situm/react-native react-native-webview
73
-
74
- #OR
75
-
76
- npm install --save @situm/react-native react-native-webview
77
- ```
78
-
79
- #### Set up your Situm credentials
80
-
81
- Follow the [Wayfinding guide](https://situm.com/docs/first-steps-for-wayfinding/) if you haven't set up a Situm account.
82
- After that, authenticate your app by calling the `setApiKey()` method.
83
-
84
- ```TypeScript
85
- SitumPlugin.init();
86
- SitumPlugin.setApiKey("YOUR_SITUM_API_KEY");
87
- ```
88
-
89
- #### Android
90
-
91
- 1. Add the `ACCESS_FINE_LOCATION` permission to your `AndroidManifest.xml` file if you have configured Situm SDK to [use GPS](<https://developers.situm.com/sdk_documentation/android/javadoc/latest/es/situm/sdk/location/locationrequest#useGps()>):
92
-
93
- ```
94
- <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
95
- ```
96
-
97
- 3. Set the `minSdkVersion` to 21 or later on your app's `build.gradle` file.
98
-
99
- #### iOS
100
-
101
- 1. Add depedency in `PodFile`
102
-
103
- ```
104
- target 'YourApp' do
105
-
106
- pod 'ReactNativeSitumPlugin', :path => '../node_modules/@situm/react-native/ReactNativeSitumPlugin.podspec'
107
-
108
- end
109
- ```
110
-
111
- You may need to add a Header Search Path: ([screenshot](https://reactnative.dev/docs/linking-libraries-ios.html#step-3))
112
-
113
- ```bash
114
- $(SRCROOT)/../node_modules/@situm/react-native/lib/ios
115
- ```
116
-
117
- 2. Declare the following permissions in your app's `Info.plist` file to successfully start positioning:
118
-
119
- ```
120
- <key>NSLocationWhenInUseUsageDescription</key>
121
- <string>Location is required to find out where you are</string>
122
- <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
123
- <string>Location is required to find out where you are</string>
124
- <key>NSMotionUsageDescription</key>
125
- <string>We use your phone sensors (giroscope, accelerometer and altimeter) to improve location quality</string>
126
- ```
127
-
128
- 3. For offline support you will have to add the underlying web application's domain inside the entry `WKAppBoundDomains` on `Info.plist` as follows:
129
-
130
- ```
131
- <key>WKAppBoundDomains</key>
132
- <array>
133
- <string>maps.situm.com</string>
134
- </array>
135
- ```
136
-
137
- ## Migrate from the old Situm React Native Wayfinding plugin
138
-
139
- The new [Situm React Native](https://www.npmjs.com/package/@situm/react-native) package breaks compatibility with the previous Situm React Native Wayfinding plugin. Integrating the new version is simpler and more straightforward. If you want to migrate your application, follow the steps described in the [Situm documentation](https://situm.com/docs/react-native-wayfinding-migration-guide).
140
-
141
- ## Development
142
-
143
- ### Prepare for development
144
-
145
- ```bash
146
- yarn
147
- ```
148
-
149
- ### Run the tests
150
-
151
- ```bash
152
- yarn test
153
- ```
154
-
155
- Situm-React-Native-Plugin is licensed under [MIT License](https://opensource.org/licenses/MIT)
156
-
157
- This will also generate the docs (see next section). More info is available at our [Developers Page](http://developers.situm.com/pages/mobile/react-native/).
158
-
159
- ### Build the documentation
160
-
161
- ```bash
162
- yarn run doc
163
- ```
164
-
165
- Docs will be available in the _docs/_ folder.
166
-
167
- ## Versioning
168
-
169
- Please refer to [CHANGELOG.md](./CHANGELOG.md) for a list of notable changes for each version of the plugin.
170
-
171
- You can also see the [tags on this repository](https://github.com/situmtech/situm-react-native/tags).
172
-
173
- ## Submitting contributions
174
-
175
- You will need to sign a Contributor License Agreement (CLA) before making a submission. [Learn more here](https://situm.com/contributions/).
176
-
177
- ## License
178
-
179
- This project is licensed under the MIT - see the [LICENSE](./LICENSE) file for further details.
180
-
181
- ## More information
182
-
183
- More info is available at our [Developers Page](https://situm.com/docs/01-introduction/).
184
-
185
- ## Support information
186
-
187
- For any question or bug report, please send an email to [support@situm.es](mailto:support@situm.es)