All Projects → ombori → react-native-search-api

ombori / react-native-search-api

Licence: MIT License
The SearchApi module gives you a general React Native interface to interact with the iOS Search API, Core Spotlight.

Programming Languages

objective c
16641 projects - #2 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-native-search-api

rafagas
Daily geospatial links curated by Raf Roset
Stars: ✭ 17 (-51.43%)
Mutual labels:  history
iwata-asks-downloader
Tool to download Iwata Asks interviews (none of which are stored in this repo)
Stars: ✭ 17 (-51.43%)
Mutual labels:  history
chrome-meme-search
A Chrome extension that lets you make spotlight search for memes.
Stars: ✭ 14 (-60%)
Mutual labels:  spotlight
ultra-router
Router for component-based web apps. Pair with React or <BYOF />.
Stars: ✭ 35 (+0%)
Mutual labels:  history
bitcoin-development-history
Data and a example for a open source timeline of the history of Bitcoin development
Stars: ✭ 27 (-22.86%)
Mutual labels:  history
hstdb
Better history management for zsh. Based on ideas from https://github.com/larkery/zsh-histdb.
Stars: ✭ 25 (-28.57%)
Mutual labels:  history
fornalder
Visualize long-term trends in collections of Git repositories.
Stars: ✭ 80 (+128.57%)
Mutual labels:  history
jRouting
Great routing mechanism for client-side web applications
Stars: ✭ 16 (-54.29%)
Mutual labels:  history
MultiLamp
Android library to showcase/highlight the multiple views on same overlay
Stars: ✭ 235 (+571.43%)
Mutual labels:  spotlight
mlstm4reco
Multiplicative LSTM for Recommendations
Stars: ✭ 21 (-40%)
Mutual labels:  spotlight
WorldSim
2D tile-based sandbox RPG with procedurally generated fantasy world simulator 🌏
Stars: ✭ 19 (-45.71%)
Mutual labels:  history
programming-history
Inspired by Cajori’s A History of Mathematical Notations, and/or TV Tropes.
Stars: ✭ 44 (+25.71%)
Mutual labels:  history
History-Disabler-for-Chromium
Disable all browsing history in Chromium browsers.
Stars: ✭ 29 (-17.14%)
Mutual labels:  history
UndoRedo.js
A powerful and simple JavaScript library provides a history for undo/redo functionality. Just like a time machine! 🕐
Stars: ✭ 19 (-45.71%)
Mutual labels:  history
arvis
Extendable cross-platform launcher that aims to help you run, edit, create any workflow simply
Stars: ✭ 39 (+11.43%)
Mutual labels:  spotlight
MapMoves
View your Moves app and Arc app/LocoKit location history summary on map
Stars: ✭ 35 (+0%)
Mutual labels:  history
star-history
The missing star history graph of GitHub repos - https://star-history.com
Stars: ✭ 2,869 (+8097.14%)
Mutual labels:  history
svelte-previous
A Svelte store that remembers previous values
Stars: ✭ 46 (+31.43%)
Mutual labels:  history
ItroublveTSC
Official Source of ItroublveTSC, totally open source. No virus or anything. Feel free to have a look :)
Stars: ✭ 82 (+134.29%)
Mutual labels:  history
meet-the-fans
Query and Visualize the network graph of your GitHub repositories, followers, stargazers, and forks.
Stars: ✭ 22 (-37.14%)
Mutual labels:  history

React Native Search Api module

The SearchApi module gives you a general React Native interface to interact with the iOS Search API, Core Spotlight.

For more information about iOS Search APIs, see https://developer.apple.com/ios/search/.

Installation

Automatic part

  1. npm install react-native-search-api --save
  2. react-native link

Manual part

To the top of your AppDelegate.m add the following line:

#import "RCTSearchApiManager.h"

In your AppDelegate implementation add the following:

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler {
    return [RCTSearchApiManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
}

Usage

Subscribe to the search item open events in your components like this:

componentDidMount() {
    <...>
    SearchApi.addOnSpotlightItemOpenEventListener(this.handleOnSpotlightItemOpenEventListener);
    SearchApi.addOnAppHistoryItemOpenEventListener(this.handleOnAppHistoryItemOpenEventListener);
}

To prevent memory leaks don't forget to unsubscribe:

componentWillUnmount() {
    <...>
    SearchApi.removeOnSpotlightItemOpenEventListener(this.handleOnSpotlightItemOpenEventListener);
    SearchApi.removeOnAppHistoryItemOpenEventListener(this.handleOnAppHistoryItemOpenEventListener)
}

Generally you should be interested whether the app was started using the search, therefore consider using the following two methods:

// For the spotlight item:
SearchApi.getInitialSpotlightItem().then(result => {
    if (result) {
        console.log('Started with a spotlight item!')
    }
})
// For the app history item:
SearchApi.getInitialAppHistoryItem().then(result => {
    if (result) {
        console.log('Started with an app history item!')
    }
})

In order to create a new spotlight item, use indexSpotlightItem or indexSpotlightItems:

SearchApi.indexSpotlightItem(item).then(result => {
    console.log('Success');
}).catch(err => {
    console.log('Error: ' + err);
});

To add new items to the app history, use createUserActivity:

SearchApi.indexAppHistoryItem(item).then(result => {
    console.log('Success');
    that.setState({labelText: 'Success'});
}).catch(err => {
    console.log('Error: ' + err);
    that.setState({labelText: ('Error: ' + err)});
});

The parameters, that items may specify are listed below:

Search item keys

Dictionaries, passed to create spotlight and app history items have some common and some specific keys, here is the list of all possible keys.

Common keys

title: string

Title of the item. Required for both item types.

contentDescription: string

Description of the item. Optional.

keywords: Array

An array of keywords, assigned to the search item. Optional.

thumbnail: string|int|object

Thumbnail to be presented in the search results. The same format as source in the Image component. Optional.

Examples:

var localItem = {
  <...>,
  thumbnail: require('/react-native/img/favicon.png')
};
var remoteItem = {
  <...>,
  thumbnail: {uri: 'https://facebook.github.io/react-native/docs/assets/favicon.png'}
};

Please refer to documentation for more details.

Spotlight-specific keys

uniqueIdentifier: string

The unique identifier of the spotlight item, passed later on during the item opening event. Required.

domain: string

The domain for the spotlight item. Optional.

App history-specific keys

userInfo: Object

A dictionary, passed later on during the item opening event. Required.

eligibleForPublicIndexing: boolean

A flag, that when set to true allows to add the item to the public index. Optional.

expirationDate: Date

Expiration date of the user activity item. Optional.

webpageURL: string

URL of the page, representing the same content on the app's website.

Credits

© 2017 PresenceKit by Ombori AB

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].