|
1 | | -import {NativeModules, NativeEventEmitter} from 'react-native'; |
| 1 | +import {NativeModules, NativeEventEmitter, Platform} from 'react-native'; |
2 | 2 |
|
3 | 3 | const {SpotlightSearch} = NativeModules; |
4 | | - |
5 | 4 | const spotlightEventEmitter = new NativeEventEmitter(SpotlightSearch); |
6 | 5 |
|
7 | | -SpotlightSearch.searchItemTapped = (callback) => spotlightEventEmitter.addListener('spotlightSearchItemTapped', callback); |
| 6 | +const EVENT_ITEM_TAPPED = 'spotlightSearchItemTapped'; |
| 7 | +const nullFunc = () => {}; |
8 | 8 |
|
9 | | -export default SpotlightSearch; |
| 9 | +export default { |
| 10 | + getInitialSearchItem: Platform.select({ |
| 11 | + ios: SpotlightSearch?.getInitialSearchItem, |
| 12 | + android: nullFunc |
| 13 | + }), |
| 14 | + indexItem: Platform.select({ |
| 15 | + ios: (item) => SpotlightSearch?.indexItem(item), |
| 16 | + android: nullFunc |
| 17 | + }), |
| 18 | + indexItems: Platform.select({ |
| 19 | + ios: (items) => SpotlightSearch?.indexItems(items), |
| 20 | + android: nullFunc |
| 21 | + }), |
| 22 | + deleteItemsWithIds: Platform.select({ |
| 23 | + ios: (ids) => SpotlightSearch?.deleteItemsWithIdentifiers(ids), |
| 24 | + android: nullFunc |
| 25 | + }), |
| 26 | + deleteItemsInDomains: Platform.select({ |
| 27 | + ios: (domains) => SpotlightSearch?.deleteItemsInDomains(domains), |
| 28 | + android: nullFunc |
| 29 | + }), |
| 30 | + deleteAllItems: Platform.select({ |
| 31 | + ios: SpotlightSearch?.deleteAllItems, |
| 32 | + android: nullFunc |
| 33 | + }), |
| 34 | + searchItemTapped: Platform.select({ |
| 35 | + ios: (callback) => spotlightEventEmitter?.addListener(EVENT_ITEM_TAPPED, callback), |
| 36 | + android: nullFunc |
| 37 | + }), |
| 38 | +} |
0 commit comments