From 25ccfbfa34cdca44c5323c4cd5717622bb91980e Mon Sep 17 00:00:00 2001 From: Gautier Date: Tue, 13 Oct 2020 15:02:24 +0200 Subject: [PATCH 1/2] [Facebook Messenger] Add mobile props to choose between web link or app link --- README.md | 2 +- src/FacebookMessengerShareButton.ts | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index d87ef90b..3d01ad37 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ import { | **All** | **`children`** (string/element): React node
**`url`** (string): URL of the shared page | **`disabled`** (bool): Disables click action and adds "disabled" class
**`disabledStyle`** (object, default=`{ opacity: 0.6 }`): Disabled style
**`windowWidth`, `windowHeight`** (number, different default for all share buttons): opened window dimensions
**`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.
**`openShareDialogOnClick`** (boolean): Open dialog on click. Defaults to `true` except on EmailShareButton
**`onShareWindowClose`** (`() => void`): Takes a function to be called after closing share dialog.
**`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
**`body`** (string): Email, will be prepended to the url.
**`separator`** (string, default=`" "`): Separates body from the url | | FacebookShareButton | - | **`quote`** (string): A quote to be shared along with the link.
**`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).
**`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).
**`to`** (string): A user ID of a recipient. Once the dialog comes up, the sender can specify additional people as recipients.
**`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
**`description`** (string): Description of the shared page | | LinkedinShareButton | - | **`title`** (string): Title of the shared page
**`summary`** (string): Description of the shared page
**`source`** (string): Source of the content (e.g. your website or application name) | diff --git a/src/FacebookMessengerShareButton.ts b/src/FacebookMessengerShareButton.ts index 7cf5b8c6..5ae1a0cd 100644 --- a/src/FacebookMessengerShareButton.ts +++ b/src/FacebookMessengerShareButton.ts @@ -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, @@ -31,6 +34,7 @@ const FacebookMessengerShareButton = createShareButton( appId: props.appId, redirectUri: props.redirectUri, to: props.to, + mobile: props.mobile, }), { windowWidth: 1000, From 391b3e06cfc387d2916de36621d386ad82ff7481 Mon Sep 17 00:00:00 2001 From: Gautier Date: Tue, 13 Oct 2020 15:20:35 +0200 Subject: [PATCH 2/2] Add prepare to scripts --- package.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 89d78a99..e5653b04 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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": [