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

[FEAT] Added custom share text option. #99

Merged
merged 1 commit into from
Apr 16, 2016
Merged
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should expose the title as well instead of hard coding it to "Check this out!"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I supposed, however iOS doesn't have a functionality to modify the share title text according to @jestoniyap . So atm I disregarded the modification of the title, though I can still add the functionality for Android but not on iOS. If it's okay with you.

.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