-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
53 lines (40 loc) · 964 Bytes
/
index.js
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
// @flow
import { NativeModules } from 'react-native';
const { RNReverseGeocode } = NativeModules;
type Location = {|
+latitude: number,
+longitude: number,
|};
type Address = {|
name: string,
address: string,
location: Location,
|};
type Result = $ReadOnlyArray<Address>;
type Region = {|
...Location,
+latitudeDelta: number,
+longitudeDelta: number,
|};
type Callback = (err: string, res: Result) => void;
const debounce = (fn, time, ...args) => {
let timeout;
return () => {
const functionCall = () => fn.apply(this, args);
clearTimeout(timeout);
timeout = setTimeout(functionCall, time);
};
};
const searchForLocations = (
searchText: string,
region: Region,
callback: Callback,
debounceMs: number = 200,
) => {
debounce(
RNReverseGeocode.searchForLocations(searchText, region, callback),
debounceMs,
);
};
const SearchForLocations = { searchForLocations };
export default SearchForLocations;