Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Messenger] Add mobile props to choose between web link or app link #357

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ import {
| **All** | **`children`** (string/element): React node<br />**`url`** (string): URL of the shared page | **`disabled`** (bool): Disables click action and adds "disabled" class<br/>**`disabledStyle`** (object, default=`{ opacity: 0.6 }`): Disabled style<br/>**`windowWidth`, `windowHeight`** (number, different default for all share buttons): opened window dimensions<br />**`beforeOnClick`** (`() => Promise`/`() => void`): Takes a function that returns a Promise to be fulfilled before calling `onClick`. If you do not return promise, `onClick` is called immediately.<br/>**`openShareDialogOnClick`** (boolean): Open dialog on click. Defaults to `true` except on EmailShareButton<br/>**`onShareWindowClose`** (`() => void`): Takes a function to be called after closing share dialog.<br/>**`resetButtonStyle`** (boolean, default=`true`): Reset `button` element style. Preferred to be set to `false` if you want to customize the button style. |
| EmailShareButton | - | **`subject`** (string): Title of the shared page<br/>**`body`** (string): Email, will be prepended to the url.<br/>**`separator`** (string, default=`" "`): Separates body from the url |
| FacebookShareButton | - | **`quote`** (string): A quote to be shared along with the link.<br/>**`hashtag`** (string): A hashtag specified by the developer to be added to the shared content. People will still have the opportunity to remove this hashtag in the dialog. The hashtag should include the hash symbol. |
| FacebookMessengerShareButton | **`appId`** (string): Facebook application id | **`redirectUri`** (string): The URL to redirect to after sharing (default: the shared url).<br />**`to`** (string): A user ID of a recipient. Once the dialog comes up, the sender can specify additional people as recipients. |
| FacebookMessengerShareButton | **`appId`** (string): Facebook application id | **`redirectUri`** (string): The URL to redirect to after sharing (default: the shared url).<br />**`to`** (string): A user ID of a recipient. Once the dialog comes up, the sender can specify additional people as recipients.<br />**`mobile`** (boolean): when `true` the link will be `fb-messenger://share` when `false` it will be `https://www.facebook.com/dialog/send`. |
| HatenaShareButton | - | **`title`** (string): Title of the shared page |
| InstapaperShareButton | - | **`title`** (string): Title of the shared page<br/>**`description`** (string): Description of the shared page |
| LinkedinShareButton | - | **`title`** (string): Title of the shared page<br/>**`summary`** (string): Description of the shared page<br/>**`source`** (string): Source of the content (e.g. your website or application name) |
Expand Down
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
"node": ">=6.9.0",
"npm": ">=5.0.0"
},
"files": [
"lib/**/*",
"es/**/*"
],
"files": ["lib/**/*", "es/**/*"],
"scripts": {
"build": "npm run lint && npm run build:commonjs && npm run build:es",
"build:commonjs": "rimraf ./lib && tsc -p . --outDir ./lib --module commonjs",
Expand All @@ -22,6 +19,7 @@
"run-demos": "webpack-dev-server --hot --config webpack.demo.config.js --progress",
"lint": "eslint --ext .js,.jsx,.ts,.tsx ./src ./demo",
"prepublishOnly": "npm run build",
"prepare": "npm run build",
"start": "npm run run-demos"
},
"keywords": [
Expand Down
8 changes: 6 additions & 2 deletions src/FacebookMessengerShareButton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ type Options = {
/** A user ID of a recipient. Once the dialog comes up, the sender can
* specify additional people as recipients. */
to?: string;
/** A boolean used to choose between fb-messenger://share (Mobile)
* and https://www.facebook.com/dialog/send (Desktop) */
mobile?: boolean;
};

function facebookMessengerLink(url: string, { appId, redirectUri, to }: Options) {
function facebookMessengerLink(url: string, { appId, redirectUri, to, mobile }: Options) {
return (
'https://www.facebook.com/dialog/send' +
(mobile ? 'fb-messenger://share' : 'https://www.facebook.com/dialog/send') +
objectToGetParams({
link: url,
redirect_uri: redirectUri || url,
Expand All @@ -31,6 +34,7 @@ const FacebookMessengerShareButton = createShareButton<Options>(
appId: props.appId,
redirectUri: props.redirectUri,
to: props.to,
mobile: props.mobile,
}),
{
windowWidth: 1000,
Expand Down