Skip to content

Commit

Permalink
fix(android): instagram direct share plain text (#1383)
Browse files Browse the repository at this point in the history
* fix(android): instagram direct share plain text

* fix(android): instagram direct share plain text - update example
  • Loading branch information
TimP4w committed Apr 14, 2023
1 parent 51a606d commit f2aed9a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
28 changes: 20 additions & 8 deletions android/src/main/java/cl/json/social/InstagramShare.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ public InstagramShare(ReactApplicationContext reactContext) {
public void open(ReadableMap options) throws ActivityNotFoundException {
super.open(options);

if (!ShareIntent.hasValidKey("type", options)) {
Log.e("RNShare", "No type provided");
return;
}
String type = options.getString("type");

if (type.startsWith("text")) {
this.openInstagramIntentChooserForText(chooserTitle);
return;
}

if (!ShareIntent.hasValidKey("url", options)) {
Log.e("RNShare", "No url provided");
return;
Expand All @@ -39,16 +50,10 @@ public void open(ReadableMap options) throws ActivityNotFoundException {
return;
}


if (!ShareIntent.hasValidKey("type", options)) {
Log.e("RNShare", "No type provided");
return;
}
String type = options.getString("type");
String extension = this.getExtension(type);
Boolean isImage = type.startsWith("image");

this.openInstagramIntentChooser(url, chooserTitle, isImage, extension);
this.openInstagramIntentChooserForMedia(url, chooserTitle, isImage, extension);
}

protected void openInstagramUrlScheme(String url) {
Expand All @@ -63,7 +68,14 @@ private String getExtension(String url) {
return ext[ext.length -1];
}

protected void openInstagramIntentChooser(String url, String chooserTitle, Boolean isImage, String extension) {
protected void openInstagramIntentChooserForText(String chooserTitle) {
this.getIntent().setPackage(PACKAGE);
this.getIntent().setType("text/plain");
this.getIntent().setAction(Intent.ACTION_SEND);
super.openIntentChooser();
}

protected void openInstagramIntentChooserForMedia(String url, String chooserTitle, Boolean isImage, String extension) {
Boolean shouldUseInternalStorage = ShareIntent.hasValidKey("useInternalStorage", options) && options.getBoolean("useInternalStorage");
ShareFile shareFile = isImage
? new ShareFile(url, "image/" + extension, "image", shouldUseInternalStorage, this.reactContext)
Expand Down
6 changes: 4 additions & 2 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ const App = () => {

const shareToInstagramDirect = async () => {
const shareOptions = {
message: encodeURI('Checkout the great search engine: https://google.com'),
message: encodeURI(
'Checkout the great search engine: https://google.com',
),
social: Share.Social.INSTAGRAM,
type: 'text/plain',
};

try {
Expand All @@ -219,7 +222,6 @@ const App = () => {
backgroundImage: images.image1,
social: Share.Social.INSTAGRAM_STORIES,
appId: '219376304', //instagram appId

};

try {
Expand Down

0 comments on commit f2aed9a

Please sign in to comment.