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 13, 2016
1 parent 3a1f20e commit b776746
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 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
12 changes: 8 additions & 4 deletions src/android/io/branch/BranchSDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
return false;
}
} else if (action.equals("showShareSheet")) {
if (args.length() == 3) {
this.showShareSheet(args.getInt(0), args.getJSONObject(1), args.getJSONObject(2));
if (args.length() == 4) {
this.showShareSheet(args.getInt(0), args.getJSONObject(1), args.getJSONObject(2), args.getString(3));

return true;
} else {
Expand Down Expand Up @@ -466,12 +466,16 @@ 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: ")
if (shareText.length() == 0) {
shareText = "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 = '';
}

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 b776746

Please sign in to comment.