Skip to content

Commit

Permalink
[FEAT] Added custom share text option.
Browse files Browse the repository at this point in the history
  • Loading branch information
Renemari Padillo committed Apr 15, 2016
1 parent a64a090 commit ad5c2a5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ The Branch iOS SDK includes a wrapper on the UIActivityViewController, that will
| $blackberry_url | `string` | The URL for Blackberry
| $windows_phone_url | `string` | The URL for Windows phone

**shareText**: `string` - Custom share text

##### Usage
```js
branchUniversalObj.showShareSheet({
Expand All @@ -456,6 +458,8 @@ branchUniversalObj.showShareSheet({
}, {
// put your control parameters here
"$desktop_url" : "http://desktop-url.com",
}, {
'Custom share text: '
});
```

Expand Down
10 changes: 7 additions & 3 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,11 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
cordova.getThreadPool().execute(r);
return true;
} else if (action.equals("showShareSheet")) {
if (args.length() != 3) {
if (args.length() == 4) {
this.showShareSheet(args.getInt(0), args.getJSONObject(1), args.getJSONObject(2), args.getString(3));

return true;
} else {
callbackContext.error(String.format("Parameter mismatched. 3 is required but %d is given", args.length()));
return false;
}
Expand Down Expand Up @@ -449,12 +453,12 @@ private void createBranchUniversalObject(JSONObject options, CallbackContext cal
* @param options A {@link JSONObject} value to set URL options.
* @param controlParams A {@link JSONObject} value to set the URL control parameters.
*/
private void showShareSheet(int instanceIdx, JSONObject options, JSONObject controlParams) throws JSONException
private void showShareSheet(int instanceIdx, JSONObject options, JSONObject controlParams, String shareText) throws JSONException
{

Log.d(LCAT, "start showShareSheet()");

ShareSheetStyle shareSheetStyle = new ShareSheetStyle(this.activity, "Check this out!", "This stuff is awesome: ")
ShareSheetStyle shareSheetStyle = new ShareSheetStyle(this.activity, "Check this out!", shareText)
.setCopyUrlStyle(this.activity.getResources().getDrawable(android.R.drawable.ic_menu_send), "Copy", "Added to clipboard")
.setMoreOptionStyle(this.activity.getResources().getDrawable(android.R.drawable.ic_menu_search), "Show More")
.addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK)
Expand Down
2 changes: 1 addition & 1 deletion testbed/www/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function ShowShareSheet()
console.log('Channel selected: ' + JSON.stringify(res));
});

branchUniversalObj.showShareSheet(properties, controlParams);
branchUniversalObj.showShareSheet(properties, controlParams, 'Custom Text');

}

Expand Down
11 changes: 9 additions & 2 deletions www/branch.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ Branch.prototype.createBranchUniversalObject = function (options) {
*
* @param (Object) options
* @param (Object) controlParameters
* @param (String) shareText [OPTIONAL]
*
* @return (Promise)
*
Expand Down Expand Up @@ -276,9 +277,13 @@ Branch.prototype.createBranchUniversalObject = function (options) {
* | $windows_phone_url | String | Kindle Fire URL |
* -------------------------------------------------------
*/
obj.showShareSheet = function (options, controlParameters) {
obj.showShareSheet = function (options, controlParameters, shareText) {

return execute('showShareSheet', [obj.instanceId, options, controlParameters]);
if ( ! shareText) {
shareText = 'This stuff is awesome: ';
}

return execute('showShareSheet', [obj.instanceId, options, controlParameters, shareText]);

};

Expand Down Expand Up @@ -333,7 +338,9 @@ Branch.prototype.createBranchUniversalObject = function (options) {
* List item on Spotlight (iOS Only).
*/
obj.listOnSpotlight = function () {

return execute('listOnSpotlight');

};

resolve(obj);
Expand Down

0 comments on commit ad5c2a5

Please sign in to comment.