Skip to content

Commit

Permalink
Added Instagram support
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy committed Jun 1, 2018
1 parent b3cdb7a commit 50968ac
Show file tree
Hide file tree
Showing 5 changed files with 198 additions and 5 deletions.
46 changes: 44 additions & 2 deletions README.md
Expand Up @@ -107,7 +107,7 @@ Youtube(video)

---

Opens a Twitter
Opens Twitter

```js
Twitter(user)
Expand All @@ -118,7 +118,7 @@ Twitter(user)

---

Opens a Facebook
Opens Facebook

```js
Facebook(user)
Expand All @@ -129,6 +129,48 @@ Facebook(user)

---

Opens Instagram User, Media, Camera, App, Location and Tag

```js
Instagram(user)
```
| Parameter | Description | Default |
|---|---|---|
|**`user`**|A string that contains the Instagram User Id that should be open.| Required|

```js
InstagramMedia(media)
```
| Parameter | Description | Default |
|---|---|---|
|**`user`**|A string that contains the Instagram Media Id that should be open.| Required|

```js
InstagramLocation(location)
```
| Parameter | Description | Default |
|---|---|---|
|**`user`**|A string that contains the Instagram Location Id that should be open.| Required|

```js
InstagramTag(tag)
```
| Parameter | Description | Default |
|---|---|---|
|**`user`**|A string that contains the Instagram Tag Id that should be open.| Required|

```js
InstagramApp()
```
Opens the Instagram App.

```js
InstagramCamera()
```
Opens the Instagram Camera.

---

`Only iOS`
Launch Facetime

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "react-native-openanything",
"version": "0.0.3",
"version": "0.0.4",
"description": "Open anything in React Native, like phone, email, sms, web address, iMessage (iOS only), etc.",
"main": "src/index.js",
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion src/index.js
Expand Up @@ -11,5 +11,6 @@ import {Twitter} from './twitter'
import {Youtube} from './youtube';
import {Facetime} from './facetime';
import {Facebook} from './facebook';
import {Instagram, InstagramMedia, InstagramApp, InstagramCamera, InstagramTag, InstagramLocation} from './instagram';

export {Call, Email, Text, Web, Launch, Supported, Open, Map, Twitter, Youtube, Facetime, Facebook}
export {Call, Email, Text, Web, Launch, Supported, Open, Map, Twitter, Youtube, Facetime, Facebook, Instagram, InstagramMedia, InstagramApp, InstagramCamera, InstagramTag, InstagramLocation}
132 changes: 132 additions & 0 deletions src/instagram.js
@@ -0,0 +1,132 @@
'use strict';

/**
* Supported Deep Links based on https://www.instagram.com/developer/mobile-sharing/iphone-hooks/
*/

import {
Platform
} from 'react-native';

import {
Launch,
LaunchString
} from './launcher';

import _ from 'lodash';

/**
* @type {string}
*/
const INSTAGRAM_APP = 'instagram://app';

/**
* @type {string}
*/
const INSTAGRAM_CAMERA = 'instagram://camera';

/**
* @type {string}
*/
const INSTAGRAM_MEDIA = 'instagram://media?id=';

/**
* @type {string}
*/
const INSTAGRAM_USER = 'instagram://user?username=';

/**
* @type {string}
*/
const INSTAGRAM_LOCATION = 'instagram://location?id=';

/**
* @type {string}
*/
const INSTAGRAM_TAG = 'instagram://tag?name=';



/**
* Launches a Instagram User profile request
* @param user
* @returns {Promise}
*/
const Instagram = (user) =>
{
return LaunchString('user', INSTAGRAM_USER + user);
}


/**
* Launches a Instagram Media request
* @param media
* @returns {Promise}
*/
const InstagramMedia = (media) =>
{
return LaunchString('media', INSTAGRAM_MEDIA + media);
}


/**
* Launches a Instagram Location request
* @param location
* @returns {Promise}
*/
const InstagramLocation = (location) =>
{
return LaunchString('location', INSTAGRAM_LOCATION + location);
}


/**
* Launches a Instagram Tag request
* @param tag
* @returns {Promise}
*/
const InstagramTag = (tag) =>
{
return LaunchString('tag', INSTAGRAM_TAG + tag);
}


/**
* Launches the Instagram App
* @returns {Promise}
*/
const InstagramApp = () =>
{
return new Promise((resolve, reject) => {

Launch(INSTAGRAM_CAMERA).then(() => resolve()).catch(error => reject(error));
});
}


/**
* Launches the Instagram Camera
* @returns {Promise}
*/
const InstagramCamera = () =>
{
return new Promise((resolve, reject) => {

Launch(INSTAGRAM_CAMERA).then(() => resolve()).catch(error => reject(error));
});
}




/**
* @exports
*/
export {
Instagram,
InstagramMedia,
InstagramApp,
InstagramCamera,
InstagramTag,
InstagramLocation
}
20 changes: 19 additions & 1 deletion src/launcher.js
Expand Up @@ -33,7 +33,7 @@ const Open = (url) =>
/**
* Launches a requested url
* @param url
* @constructor
* @returns {Promise}
*/
const Launch = (url) =>
{
Expand All @@ -50,11 +50,29 @@ const Launch = (url) =>
});
}


/**
* Launches a request url based on a string
* param @name
* param @url
* @returns {Promise}
*/
const LaunchString = (name, url) =>
{
return new Promise((resolve, reject) => {

if (!_.isString(name)) reject('The provided ' + name + ' must be a string');

Launch(url).then(() => resolve()).catch(error => reject(error));
});
}

/**
* @exports
*/
export {
Launch,
LaunchString,
Supported,
Open
};

1 comment on commit 50968ac

@yasir720
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i've been trying to use this to open a instagram profile and have been having troubles with it. i posted it in the issues. i was wondering if you could maybe help me out with this. the user name for the profile is runaway.app and the id is 4546306012

Capture

Please sign in to comment.