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

Feature/new task #1195

Merged
merged 3 commits into from May 5, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions android/src/main/java/cl/json/social/ShareIntent.java
Expand Up @@ -98,6 +98,10 @@ public int compare(HashMap<String, String> map, HashMap<String, String> map2) {
public void open(ReadableMap options) throws ActivityNotFoundException {
this.options = options;

if (ShareIntent.hasValidKey("isNewTask", options) && options.getBoolean("isNewTask")) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

What about openNewIntent?

Suggested change
if (ShareIntent.hasValidKey("isNewTask", options) && options.getBoolean("isNewTask")) {
if (ShareIntent.hasValidKey("openNewIntent", options) && options.getBoolean("openNewIntent")) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the reason it's called isNewTask is because it's specifically using the flag that forces the system to put any activity started as a result of the Intent in a new task, I was just reading up on it in response to seeing this PR:

https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_NEW_TASK - it's clearly called "new task" and the whole tasks / back stack / user navigation flow uses "Task" as a term of art that is related to - but not the same as "new intent".

All of our shares are new Intents, but this makes the new Intent also put the new Activity in it's own separate history backstack which alters back behavior in specific ways

https://developer.android.com/guide/components/activities/tasks-and-back-stack#IntentFlagsForTasks

I think it's named fine. I guess what I'm having trouble with is deciding if this should actually be the default or not! Honestly it seems like it should be the default now that I read about it deeply. When submitter @SpiriaJWF says "app", in Android terms what that means is not what's in your APK, it means "one task with a backstack of Activities" - that single task with it's backstack is what shows up in the recents switcher if I understand correctly? So this isNewTask behavior means that the Activity started as a result of a share will be a fresh "app" in the recents, running on it's own with it's own independent history now.

I also noticed we set FLAG_ACTIVITY_NO_HISTORY which will interact with this as well, maybe not in a great way

chooser.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);

By setting that currently, it means that after the share, if the user hits the home button or uses recents to do anything outside of the activity opened for the share, the activity just goes poof, which is odd. And it might be the root of why we don't get share results, according to the docs

Copy link
Collaborator

Choose a reason for hiding this comment

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

Note that this may only really be visible as a "mixed" (shared Activity as top item in your app's backstack inside the same task) app experience if the app wasn't already started in it's own Task prior to the share. Concretely, if Whatsapp was not open (as if! it's always open, but kill it for testing), then if you share to whatsapp you may see whatsapp pop up as the top activity on your mobile. Not sure if that example is perfect because whatsapp may define in it's Manifest that it always gets a separate task (it should really), but the same test can be tried with different share targets and I bet at least some of them will open up inside your app. Maybe @SpiriaJWF has a concrete example of an app that ends up in the react-native app's task as top activity on backstack?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice catch @mikehardy! I think I made confusion with the Intent + Tasks here.

Also, as you mentioned it can be annoying to have the behavior of "destroying" the app that was open when the user presses the back button. What do you think if you give at try changing:

 chooser.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); 

To a more "user-friendly" behavior using FLAG_ACTIVITY_NEW_TASK? I didn't have time to read properly about the differences between these two, but it might be a good idea to give it a try. 😄

this.getIntent().addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}

if (ShareIntent.hasValidKey("subject", options)) {
this.getIntent().putExtra(Intent.EXTRA_SUBJECT, options.getString("subject"));
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Expand Up @@ -101,6 +101,7 @@ export interface ShareOptions {
filenames?: string[];
saveToFiles?: boolean;
activityItemSources?: ActivityItemSource[];
isNewTask?: boolean;
MateusAndrade marked this conversation as resolved.
Show resolved Hide resolved
}

export type ActivityType =
Expand Down
1 change: 1 addition & 0 deletions website/docs/share-open.mdx
Expand Up @@ -51,6 +51,7 @@ You can customize the call to `Share.open` passing the following parameters:
| filenames | Array[string] | Array of filename for base64 urls array in Android | ✅ | ✅ | 🚫 | ❓ |
| activityItemSources | Array[Object] | Array of activity item sources. Each items should conform to [ActivityItemSource](#activityitemsource) specification. [Example](#example-activityitemsources). | ✅ | 🚫 | ✅ | ❓ |
| useInternalStorage | boolean | Store the temporary file in the internal storage cache (Android only) | ✅ | ✅ | 🚫 | 🚫 |
| isNewTask | boolean | Open intent as a new task. "failOnCancel" will not work. | ✅ | ✅ | 🚫 | ❓ |
MateusAndrade marked this conversation as resolved.
Show resolved Hide resolved

## Sharing a base64 file format

Expand Down