-
-
Notifications
You must be signed in to change notification settings - Fork 655
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
[android] Handle receiving shares from other apps #4196
Conversation
2f74afe
to
6f0a971
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @agrawal-d for the swift revisions!
Code comments below. Now I'll go play with the UI at this version...
override fun onNewIntent(intent: Intent){ | ||
handleIntentForSharing(intent) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, well spotted! Thanks for the docs reference, too.
src/nav/navReducer.js
Outdated
// Dont switch to main UI if sharing screen is on. | ||
if (state.routes.find(route => route.routeName === 'sharing')) { | ||
return state; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the chat thread you started for this question, I think I figured out the mystery of what's happening here (and why notifications don't have the same trouble), and found a cleaner solution. (And more complete! This one still leaves it the case that the sharing UI will briefly try to render in a situation where the state it has is bogus.)
android/app/src/main/java/com/zulipmobile/sharing/SharingModule.kt
Outdated
Show resolved
Hide resolved
try{ | ||
promise.resolve(initialSharedData) | ||
}catch(e:Exception){ | ||
promise.resolve(null) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm.
I'm skeptical when I see a pattern like this -- it looks like trying to shut up an error without understanding it.
In particular this description in the commit message seems like a contradiction:
Catching this exception and returning null fixes this error. This
does not change the behaviour of this function because the error
only happens when the map is re-read - and we never actually re-read
the initialSharedData map, we only ever read it once.
Doesn't the fact that we're seeing the error appear indicate that we do actually re-read the Map in question?
Or another way of looking at basically the same point: if the behavior of the function isn't affected by this change, then why are we making the change? It's certainly not simplifying or clarifying the code. If this change causes those red-screen errors with "Map already consumed" to stop appearing, then that's very much a change in the behavior of the function.
// Intent is reused after quitting, skip it. | ||
if((getIntent().flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY)!=0){ | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, that is wacky that it behaves that way! Good find.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took me several hours to figure this out, I tried a lot of different things 😰
Observations from playing with the UI:
|
src/sharing/ShareToPm.js
Outdated
@@ -169,7 +153,7 @@ class ShareToPm extends React.Component<Props, State> { | |||
|
|||
if (choosingRecipients) { | |||
return ( | |||
<Modal> | |||
<Modal onRequestClose={this.handleModalClose}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharing: Handle hardware back button when selecting PM recipients.
Use modal's 'onRequestClose' to hide the user selection screen when
the back button is pressed while choosing recipients in the share to
PM tab.
Hmm, did this not work in the previous version? Certainly good to fix so that this works.
I'm less happy about relying completely on the back button here. It's acceptable as a temporary workaround because we only support this flow in the first place on Android -- but that won't work when in the future we offer sharing on iOS as well. And in the UX of this even on Android: everywhere else in the app (including other uses of this user-picker widget!), when it's possible and natural to go back, we have a "back" icon at the top left of the screen that offers that. It feels like a glitch for that to be missing here.
Just merged 5 of these commits! Looking closer at the rest... |
OK, after some investigation in chat, ended up sending #4204 which I think will resolve at least a bit of the oddness that we've both been seeing on versions of this branch. Want to try it on top of that and see? For anything that that branch does fix, another way to avoid the issue is to not rely on |
Thanks, @gnprice! I posted a comment on your PR thread: #4204 (comment) |
(Rebased, after having merged #4204 .) |
I reproduce the issue you describe at that comment. Let's debug in chat. |
OK, merged three more commits: (One of them comes from squashing two of the commits from the branch.) That leaves just two others outstanding: I'd really like to fix the double-initialization issue before turning this on for everyone -- i.e. the issue where we can end up with two different Android activities, and two different React component trees, in the same process and talking to the same JS engine and the same Redux store. Made some debugging progress in that chat thread linked above, and suggested a possible solution (but you should confirm whether it seems to actually work 😉 ). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comments below on the remaining commit, other than the one enabling the feature.
@@ -1,6 +1,7 @@ | |||
package com.zulipmobile.sharing | |||
|
|||
import com.facebook.react.bridge.* | |||
import java.lang.Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now redundant
fun getInitialSharedContent(promise: Promise) { | ||
promise.resolve(initialSharedData) | ||
initialSharedData = null | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is certainly plausible code now. I wonder if it's clearly the behavior we really want, though. Why are we ending up trying twice to get the initial shared data? What's the situation where that happens?
Thanks, @gnprice! I've updated the PR. |
3d61180
to
e662d9b
Compare
This one looks like some kind of rebase error, perhaps -- the description and contents don't match: commit 4394d6c6d745610c1bb79fb86fe844aedbfa7885
Author: Divyanshu Agrawal <agrawal.divyanshu@outlook.com>
Date: Mon Jul 20 12:39:33 2020 +0530
sharing: Switch to 'react-navigation-tabs' for creating tab bars.
Since the RN 0.60 upgrade, using `createMaterialTopTabNavigator`
exported by 'react-navigation' causes an error - that
'ViewPagerAndroid has been removed from React Native'. Switching to
the one exported by 'react-navigation-tabs' fixes this.
---
src/sharing/SharingScreen.js | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/sharing/SharingScreen.js b/src/sharing/SharingScreen.js
index e69303d76..12a74206c 100644
--- a/src/sharing/SharingScreen.js
+++ b/src/sharing/SharingScreen.js
@@ -71,7 +71,12 @@ class SharingScreen extends PureComponent<Props> {
}
return (
- <Screen canGoBack={false} title="Share on Zulip" shouldShowLoadingBanner={false}>
+ <Screen
+ canGoBack={false}
+ title="Share on Zulip"
+ shouldShowLoadingBanner={false}
+ keyboardShouldPersistTaps="always"
+ >
<SharingTopTabNavigator navigation={navigation} />
</Screen>
); |
For the "Exit the process when the activity is destroyed" commit, I'm concerned about collateral damage and don't want to make that change before better understanding what's happening in the problem we're trying to solve. I have some questions in chat to help you debug more fully. |
Since the RN 0.60 upgrade, using `createMaterialTopTabNavigator` exported by 'react-navigation' causes an error - that 'ViewPagerAndroid has been removed from React Native'. Switching to the one exported by 'react-navigation-tabs' fixes this.
This feature was marked as experimental because of several small bugs. These have been fixed in the preceeding commits. So, remove the comment that disables it. Fixes: zulip#117
This fixes the 'double initialization' bug.
This resolves the 'Map already consumed' bug.
This was superseded by #4514. Thanks again @agrawal-d for your work on this! |
Fixes: #117
Continuation of work done in #4124
Resolves several issues pointed out by @gnprice in #4124.
Unresolved issues:
back button appears in user picker screen for 'Share to PM'.(Fixed!)