react-native-radar 3.8.3 → 3.8.4

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.
@@ -871,7 +871,7 @@ public class RNRadarModule extends ReactContextBaseJavaModule implements Permiss
871
871
  near.setLatitude(latitude);
872
872
  near.setLongitude(longitude);
873
873
  int limit = optionsMap.hasKey("limit") ? optionsMap.getInt("limit") : 10;
874
- String country = optionsMap.hasKey("country") ? optionsMap.getString("country") : null;
874
+ String country = optionsMap.hasKey("countryCode") ? optionsMap.getString("countryCode") : optionsMap.hasKey("country") ? optionsMap.getString("country") : null;
875
875
  String[] layers = optionsMap.hasKey("layers") ? RNRadarUtils.stringArrayForArray(optionsMap.getArray("layers")) : null;
876
876
 
877
877
  Radar.autocomplete(query, near, layers, limit, country, new Radar.RadarGeocodeCallback() {
package/ios/RNRadar.m CHANGED
@@ -756,7 +756,10 @@ RCT_EXPORT_METHOD(autocomplete:(NSDictionary *)optionsDict resolve:(RCTPromiseRe
756
756
  }
757
757
 
758
758
  NSArray *layers = optionsDict[@"layers"];
759
- NSString *country = optionsDict[@"country"];
759
+ NSString *country = optionsDict[@"countryCode"];
760
+ if (country == nil) {
761
+ country = optionsDict[@"country"];
762
+ }
760
763
 
761
764
  __block RCTPromiseResolveBlock resolver = resolve;
762
765
  __block RCTPromiseRejectBlock rejecter = reject;
@@ -28,14 +28,15 @@ import {
28
28
  import { default as defaultStyles } from './styles';
29
29
 
30
30
  const defaultAutocompleteOptions = {
31
- debounceMS: 200,
32
- threshold: 3,
33
- limit: 8,
34
- placeholder: "Search address",
35
- showPin: true,
31
+ debounceMS: 200, // Debounce time in milliseconds
32
+ threshold: 3, // Minimum number of characters to trigger autocomplete
33
+ limit: 8, // Maximum number of results to return
34
+ placeholder: "Search address", // Placeholder text for the input field
35
+ showMarkers: true,
36
+ disabled: false,
36
37
  };
37
38
 
38
- const autocompleteUI = ({ options = {}, onSelect, location, style = {} }) => {
39
+ const autocompleteUI = ({ options = {} }) => {
39
40
  const [query, setQuery] = useState("");
40
41
  const [results, setResults] = useState([]);
41
42
  const [isOpen, setIsOpen] = useState(false);
@@ -44,19 +45,26 @@ const autocompleteUI = ({ options = {}, onSelect, location, style = {} }) => {
44
45
  const textInputRef = useRef(null);
45
46
 
46
47
  const config = { ...defaultAutocompleteOptions, ...options };
48
+ const style = config.style || {};
47
49
 
48
50
  const fetchResults = useCallback(
49
51
  async (searchQuery) => {
50
52
  if (searchQuery.length < config.threshold) return;
51
53
 
52
- const params = { query: searchQuery, limit: config.limit };
54
+ const { limit, layers, countryCode } = config;
55
+ const params = { query: searchQuery, limit, layers, countryCode };
53
56
 
54
- if (location && location.latitude && location.longitude) {
55
- params.near = location;
57
+ if (config.near && config.near.latitude && config.near.longitude) {
58
+ params.near = config.near;
56
59
  }
57
60
 
58
61
  try {
59
62
  const result = await Radar.autocomplete(params);
63
+
64
+ if (config.onResults && typeof config.onResults === "function") {
65
+ config.onResults(result.addresses);
66
+ }
67
+
60
68
  setResults(result.addresses);
61
69
  setIsOpen(true);
62
70
  } catch (error) {
@@ -93,8 +101,8 @@ const autocompleteUI = ({ options = {}, onSelect, location, style = {} }) => {
93
101
  setQuery(item.formattedAddress);
94
102
  setIsOpen(false);
95
103
 
96
- if (typeof onSelect === "function") {
97
- onSelect(item);
104
+ if (typeof config.onSelection === "function") {
105
+ config.onSelection(item);
98
106
  }
99
107
  };
100
108
 
@@ -129,7 +137,7 @@ const autocompleteUI = ({ options = {}, onSelect, location, style = {} }) => {
129
137
  >
130
138
  <View style={styles.addressContainer}>
131
139
  <View style={styles.pinIconContainer}>
132
- {config.showPin ? (
140
+ {config.showMarkers ? (
133
141
  <Image source={MARKER_ICON} style={styles.pinIcon} />
134
142
  ) : null}
135
143
  </View>
@@ -219,6 +227,8 @@ const autocompleteUI = ({ options = {}, onSelect, location, style = {} }) => {
219
227
  <TouchableOpacity
220
228
  style={styles.inputContainer}
221
229
  onPress={() => {
230
+ if (config.disabled) return;
231
+
222
232
  setIsOpen(true);
223
233
  // Set the focus on the other textinput after it opens
224
234
  setTimeout(() => {
Binary file
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "React Native module for Radar, the leading geofencing and location tracking platform",
4
4
  "homepage": "https://radar.com",
5
5
  "license": "Apache-2.0",
6
- "version": "3.8.3",
6
+ "version": "3.8.4",
7
7
  "main": "js/index.js",
8
8
  "files": [
9
9
  "android",
package/js/ui/README.md DELETED
@@ -1,157 +0,0 @@
1
- ## Example usage
2
-
3
- We provide UI elements for autocomplete & maps to make building easy.
4
-
5
- ### Adding an address autocomplete
6
-
7
- Adding an address search autocomplete is straightforward. Our `<Autocomplete>` element is comprised of a TextInput and Flatlist with the results.
8
-
9
- The example below provides optional `location` and `onSelect` props to the component. Providing a location will improve autocomplete result quality. Without it, the API utilizes the IP address location to rank results.
10
-
11
- ```
12
- import { View } from 'react-native';
13
- import { useState, useEffect } from 'react';
14
- import Radar, { Autocomplete } from 'react-native-radar';
15
-
16
- export default function App() {
17
- const [location, setLocation] = useState(null);
18
-
19
- useEffect(() => {
20
- Radar.initialize('prj_live_pk_...');
21
-
22
- Radar.trackOnce().then((result) => {
23
- setLocation({
24
- latitude: result.location.latitude,
25
- longitude: result.location.longitude,
26
- });
27
- });
28
- }, []);
29
-
30
- const onSelect = (selectedAddress) => {
31
- // Do something with the selected address
32
- }
33
-
34
- return (
35
- <View style={{ marginTop: 50}}>
36
- <Autocomplete location={location} onSelect={onSelect} />
37
- </View>
38
- );
39
- }
40
-
41
- ```
42
-
43
- ### Adding a map
44
-
45
- If you're using the Map element, you'll need to install [Maplibre React Native](https://github.com/maplibre/maplibre-react-native), which `react-native-radar` has an optional peer dependency.
46
- ```
47
- npm install @maplibre/maplibre-react-native
48
- ```
49
-
50
- Then make sure to complete required [platform specific installation steps](https://github.com/maplibre/maplibre-react-native/blob/main/docs/GettingStarted.md#review-platform-specific-info) as well.
51
-
52
-
53
- We've taken care of linking the map tile server to the map, so all you need to do is make sure you've initialized the Radar SDK and use `<Map>`. Here's a minimal example:
54
-
55
- ```
56
- import {View} from 'react-native';
57
- import Radar, { Map } from 'react-native-radar';
58
- import MapLibreGL from '@maplibre/maplibre-react-native';
59
-
60
-
61
- // A quirk of Map Libre requires us to set their deprecated access token to null
62
- MapLibreGL.setAccessToken(null);
63
-
64
- export default function App() {
65
-
66
- useEffect(() => {
67
- Radar.initialize('prj_live_pk_...');
68
- }, []);
69
-
70
- return (
71
- <View style={{ width: '100%', height: '95%'}}>
72
- <Map />
73
- </View>
74
- );
75
- }
76
- ```
77
-
78
- And here's how you might add a custom pin to the map and control the camera:
79
- ```
80
- // ... rest of your file
81
-
82
- const [cameraConfig, setCameraConfig] = useState({
83
- triggerKey: Date.now(),
84
- centerCoordinate: [-73.9911, 40.7342],
85
- animationMode: 'flyTo',
86
- animationDuration: 600,
87
- zoomLevel: 12,
88
- });
89
-
90
- const onRegionDidChange = (event) => {
91
- // handle region change
92
- }
93
-
94
- const mapOptions = {
95
- onRegionDidChange: onRegionDidChange,
96
- }
97
-
98
- const onSelect = (selectedAddress) => {
99
- // Do something with the selected address
100
- }
101
-
102
- const pointsCollection = {
103
- type: "FeatureCollection",
104
- features: [{
105
- type: "Feature",
106
- properties: {
107
- _id: '123',
108
- },
109
- geometry: {
110
- type: "Point",
111
- coordinates: [-73.9911, 40.7342]
112
- }
113
- }]
114
- };
115
-
116
- const onPressIcon = (event) => {
117
- // do something with the symbol, such as scrolling to the geofence
118
- // associated with the icon in the list
119
- }
120
-
121
- return (
122
- <View style={{ width: '100%', marginTop: '10%', height: '90%'}}>
123
- <Map mapOptions={mapOptions}>
124
- <MapLibreGL.Camera
125
- {...cameraConfig}
126
- />
127
- <MapLibreGL.Images
128
- images={{
129
- icon: require('./assets/marker.png'),
130
- }}
131
- />
132
- <MapLibreGL.ShapeSource
133
- id="points"
134
- shape={pointsCollection}
135
- onPress={onPressIcon}
136
- >
137
-
138
- <MapLibreGL.SymbolLayer
139
- id="symbol"
140
- style={{
141
- iconImage: 'icon',
142
- iconSize: [
143
- 'interpolate',
144
- ['linear'],
145
- ['zoom'],
146
- 0, 0.2, // Adjust the icon size for zoom level 0
147
- 12, 0.4, // Adjust the icon size for zoom level 12
148
- 22, 0.8, // Adjust the icon size for zoom level 22
149
- ],
150
- iconAllowOverlap: true,
151
- }}
152
- />
153
- </MapLibreGL.ShapeSource>
154
- </Map>
155
- </View>
156
- );
157
- ```