Closed isagoico closed 2 years ago
Triggered auto assignment to @Luke9389 (Engineering
), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
Triggered auto assignment to @adelekennedy (External
), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
@Luke9389 whoops, I'm a couple days late on this but no bites so far. Going to double the job
Whoops, this has to be internal. External contributors have no way of testing push notifications locally.
@adelekennedy please take down the Upwork job
@roryabraham thank you! Is this something I could have spotted and missed? (I want to make sure I'm following procedure)
@adelekennedy I think you followed procedure just fine. Push notifications just happen to be one of those things that we've found external contributors can't work on.
@Luke9389 the reason is because iOS push notifications can't be tested on a simulator, and you can't build the mobile app to a physical device unless you add the device to our mobile provisioning profile in the App Store.
Dude, nice catch. Sorry about that! Will make note of this for the future. Actually... do you know if we have a list of topics that need to be internal? Maybe it's not necessary, idk.
do you know if we have a list of topics that need to be internal?
I am not aware of such a list
Yea I searched SO and didn't see one. Do you think it's necessary? What else would go on there aside from notifications? "Anything requiring Web-E changes". Seems like this may not be needed...
The jobs been closed 💀
Now that this is internal, I'm gonna unassign from this.
This issue has not been updated in over 15 days. eroding to Monthly issue.
P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!
Yesterday I tested opening notifications when the app is in the background on a physical IOS device. For some reason the call to Linking.openURL does not work. Opening the deep link to report 185 on the simulator with xcrun simctl openurl booted new-expensify://r/185
also did not work. I think there may be an issue with the structure of the linking config.
However, I did find that replacing Linking.openURL
with Navigation.navigate(ROUTES.getReportRoute(reportID));
ended up working, at least when the app is only in the background. I'm going to test that solution on a deployment build on my IOS device so that I can see if opening the notification works when the app has not been started.
@neil-marcellini Thanks for working through this, I know firsthand how challenging it can be to test.
Opening the deep link to report 185 on the simulator with xcrun simctl openurl booted new-expensify://r/185 also did not work.
This is weird ... this is probably the key to solving this issue. Have you tried running xcrun simctl openurl ...
when running the app in a simulator instead of on a physical device? Is it possible that your xcrun
command is not properly targeting your physical device?
However, I did find that replacing Linking.openURL with Navigation.navigate(ROUTES.getReportRoute(reportID)); ended up working, at least when the app is only in the background. I'm going to test that solution on a deployment build on my IOS device so that I can see if opening the notification works when the app has not been started.
Honestly, my recommendation would be to not go down this route until you figure out why deeplinking isn't working, because I know from experience that Navigation.navigate
almost certainly won't work if you're waking the app from a push notification when it's completely closed.
Of course, you can choose to approach it differently and it's probably valuable for you do get practice running a deployment build on your device. It's up to you and I'm here if you need any support.
Have you tried running xcrun simctl openurl ... when running the app in a simulator instead of on a physical device?
Yes that's what I did. As with tapping on a notification, it opens the list of reports but not the report itself. Maybe the problem is that the drawer is open and is covering the page beneath? I'll see if I can verify that.
@roryabraham I tried editing Navigation.getDefaultDrawerState
to always return 'closed' to see if the drawer was covering the report when it is deep linked to. Once I made that change deep linking to a report worked. Why is the default drawer state set to 'open' on small screens? Could we change the default? Or could we change the default drawer state when handling the deep link?
@neil-marcellini Great investigation. We already have a check in place here to see if we tapped a notification before the navigation container was ready, and if we did we set the default drawer state to closed. If seems that's just not working in the case when the app is already open because Navigation.setDidTapNotification
does nothing if the navigation container is already ready.
I suggest we change this callback like so:
// Open correct report when push notification is clicked
PushNotification.onSelected(PushNotification.TYPE.REPORT_COMMENT, ({reportID}) => {
+ if (Navigation.isReady()) {
+ Navigation.navigate(ROUTES.getReportRoute(reportID))
+ } else {
+ // Navigation container is not yet ready, use deeplinking to open to correct report instead
Navigation.setDidTapNotification();
Linking.openURL(`${CONST.DEEPLINK_BASE_URL}${ROUTES.getReportRoute(reportID)}`);
+ }
});
That way, we use Navigation.navigate
as the default, which will work if the app was just backgrounded. But we use deeplinking if we need to (i.e: app was just killed)
Ok, that sounds like a good plan. I'll implement this and test it out. My only concern is what if we want to handle deep links from sources other than notifications while the app is open? For example maybe we have a link to a specific report in an email? In that case it feels like we should have the logic you specified above in a callback that handles all incoming deep links. What do you think? Maybe that's a project for the future?
In that case it feels like we should have the logic you specified above in a callback that handles all incoming deep links.
That's a good point – it might be nice to have a more inherent solution. It could also be a pretty tricky as I don't think there's a straightforward way to handle this. I've done some research and here's a rough sketch of what I've come up with. It needs to be worked through and tested and I'm not sure it will work:
Override getStateFromPath
in the linkingConfig as described here, and set up the following logic:
import {getStateFromPath} from '@react-navigation/native';
const OVERRIDE_DRAWER_STATE_ROUTES = [
{
regex: /report\/\d\/?/,
drawerState: 'closed',
},
];
let currentDeeplinkURL = null;
Linking.addEventListener('url', ({url}) => currentDeeplinkURL = url);
...
export default {
prefixes: [...],
config: {...},
getStateFromPath: (path, config) => {
if (Linking.getInitialURL() === path || currentDeeplinkURL === path) {
if (currentDeeplinkURL) {
// Reset deeplink URL
currentDeeplinkURL = null;
}
for (let override of OVERRIDE_DRAWER_STATE_ROUTES) {
if (override.regex.test(path)) {
Navigation.setDrawerState(override.drawerState);
break;
}
}
}
return getStateFromPath(path, config);
}
}
In Navigation.js, implement the following:
let initialDrawerState = null;
...
function setDrawerState(state) {
if (!_.contains(['open', 'closed'], state)) {
Log.hmmm(`Attempting to set invalid drawer state ${state}`);
return;
}
if (navigationRef.isReady()) {
if (state === 'open') {
openDrawer();
} else {
closeDrawer();
}
} else {
initialDrawerState = state;
}
}
...
function getDefaultDrawerState() {
if (!_.isNull(initialDrawerState)) {
return initialDrawerState;
}
return isSmallScreenWidth ? 'open' : 'closed';
}
And that might work – if you deeplink to a specific report, we'll:
It's definitely a weird implementation, and I'm curious for input from others.
FWIW a better implementation would be to add a feature to react-navigation such that the linking config has two new fields:
willHandleDeeplink
– pass this function and it will be called with the url of the deeplink before any navigation occurs.didHandleDeeplink
– pass this function and it will be called with the url of the deeplink after the navigation occurs.That could help resolve some potential race conditions with the above implementation. For example, this might be possible with the proposal I wrote above (not sure):
closed
, and dispatch the closeDrawer
action.defaultDrawerState
has been reset.Anyways, it would be great to get this nailed down to make deep-link handling easier in the future, but if things aren't working out we could always just fix the problem at hand with this simple solution for now. cc @parasharrajat if you have any opinions on this discussion.
Oh, actually @parasharrajat wrestled with this problem a while back and we decided that his proposal was too complicated to be worth it: https://github.com/Expensify/App/issues/5027#issuecomment-951417341. If we really want to get this deep-link drawer state settled we might need a react-navigation feature request of some kind, maybe the willHandleDeeplink
event handler I suggested above. 🤔
Hmm, https://github.com/Expensify/App/issues/6079#issuecomment-1026367170 This might not work for all platforms. The problem I was trying to solve was a little different but covers this issue as well. URL for home page (LHN) and report page is the same which creates a challenge for us. How to decide what should be shown to the user? LHN or report?
Drawer usage history state to manage open and closed state and when you open the app directly from URL, there is no History API state. We need a way to create a proper/complete navigation state via URL.
What I tried was to add a param and change its value whenever the Drawer status changes. I tried LinkingConfig
but it is limited and does give us full control. It is mostly there for you to create the initial state from the URL but when you interact with the app it does not have any effect on the state (I don't remember exactly if this was the case but there was a limitation). So to get full control over the navigation state and url generation, I customized DrawerRouter.
This could be a good feature in DrawerRouter if we can manage the Drawer state from url. Even if there is a way to manage it with configuration, I haven't found one.
Maybe we should gather our thoughts a bit and create a feature request in react-navigation?
In the meantime @neil-marcellini I would recommend taking an easier route to fix this issue and going with this simpler suggestion.
@roryabraham I'm still having trouble installing a release build on my IOS device. I also tried following these instructions but I wasn't sure if that actually installs a production build.
This issue is still occurring, and now it occurs on all platforms, so I'm not sure if #7633 fixed the problem for IOS. See the slack conversation here
I'm going to drop this one so that someone with more react navigation experience can take it. Also, for whoever takes it next, it would be great to have a way to locally test notifications opened when the app is in the background.
Keeping notes:
npm install && cd ios && pod install
npm run ios -- --device "ag"
("ag" is my iPhone's name)index.js
AIRSHIP_KEY_EXPENSIFY_CASH
and AIRSHIP_SECRET_EXPENSIFY_CASH
in dev config./script/clitools.sh push:reportComment
Still not receiving pushes locally
Interestingly - If I send the notification to OldDot, I get the message, so thinking it has something to do with newDot specifically
Trying to use an account that I am not signed into on web to make sure it's not getting ignored
Ok so I am able to reproduce the bug and get push notifications to work via the TestFlight, but still not from a local build.
Ok finally got local notifications working, looks like I didn't need to do step 4 here
Ok from my testing the PushNotification.onSelected
callback never fires when the user hits the notification.
Ok so PushNotification.onSelected
is being fired, but I was running this code: https://github.com/Expensify/App/issues/6079#issuecomment-1026300333
But Navigation.isReady()
was crashing 🤔
Ok so seeing Navigation.navigate(ROUTES.getReportRoute(reportID));
fail with the error: DEBUG [hmmm] [Navigation] navigate failed because navigation ref was not yet ready - {"route":"r/63481527"}
so we definitely do need some sort of check to see if the navigation is "ready".
@roryabraham I've now found your comment here: https://github.com/react-navigation/react-navigation/issues/9170#issuecomment-898831026
I think I am in a loop!
Ok I opened a PR that seems to work for all the cases I can throw at it: https://github.com/Expensify/App/pull/8353
Let me know what you think @roryabraham!
PR in preview
Still reproducible according to QA here.
@kavimuru coming from https://github.com/Expensify/App/issues/7901#issuecomment-1092169844
Can you please be more specific? I watched the iOS video and from 2:14 to the end it looks like the notification worked, but I didn't see any other notifications tapped.
@kavimuru can you test again to see if you can reproduce? If so, can you provide details?
I've been testing this myself on my device and was unable to reproduce.
I just tested on iOS v1.1.52-0 and it opened to the correct chat. (side note... iOS has been hella slow/laggy the past couple weeks, at least).
I think this is fixed. If there is a regression found let's open a new issue.
@AndrewGable Open a new ticket https://github.com/Expensify/App/issues/9179
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Action Performed:
Expected Result:
User should be taken to correct chat.
Actual Result:
Some of the time, the user is not taken to correct chat.
Workaround:
Can the user still use Expensify without this being fixed? Have you informed them of the workaround?
Get taken to the wrong chat and then go click the correct one.
Platform:
Where is this issue occurring?
Version Number: 1.1.10-0
Reproducible in staging?: Yes Reproducible in production?: Yes
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos: Any additional supporting documentation
Expensify/Expensify Issue URL:
Issue reported by: @roryabraham Slack conversation: https://expensify.slack.com/archives/C01GTK53T8Q/p1635210815095800
View all open jobs on GitHub