react-native-spotlight-search
Version:
A React Native module for iOS that provides Spotlight search functionality.
39 lines (35 loc) • 1.27 kB
JavaScript
import {NativeModules, NativeEventEmitter, Platform} from 'react-native';
const {SpotlightSearch} = NativeModules;
const spotlightEventEmitter = new NativeEventEmitter(SpotlightSearch);
const EVENT_ITEM_TAPPED = 'spotlightSearchItemTapped';
const nullFunc = () => {};
export default {
getInitialSearchItem: Platform.select({
ios: SpotlightSearch?.getInitialSearchItem,
android: nullFunc
}),
indexItem: Platform.select({
ios: (item) => SpotlightSearch?.indexItem(item),
android: nullFunc
}),
indexItems: Platform.select({
ios: (items) => SpotlightSearch?.indexItems(items),
android: nullFunc
}),
deleteItemsWithIdentifiers: Platform.select({
ios: (ids) => SpotlightSearch?.deleteItemsWithIdentifiers(ids),
android: nullFunc
}),
deleteItemsInDomains: Platform.select({
ios: (domains) => SpotlightSearch?.deleteItemsInDomains(domains),
android: nullFunc
}),
deleteAllItems: Platform.select({
ios: () => SpotlightSearch?.deleteAllItems(),
android: nullFunc
}),
searchItemTapped: Platform.select({
ios: (callback) => spotlightEventEmitter?.addListener(EVENT_ITEM_TAPPED, callback),
android: nullFunc
}),
}