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

Mobile: Add quick actions #2247

Merged
merged 27 commits into from
Feb 18, 2020
Merged

Conversation

devonzuegel
Copy link
Contributor

@devonzuegel devonzuegel commented Dec 31, 2019

This adds the ability to quick-add notes and to-dos with force touch directly from your homescreen. Demo:

quick-actions demo -- small

To build this, you may need to follow the directions in here to link the native QuickActions library:
https://facebook.github.io/react-native/docs/linking-libraries-ios.html#content

Next steps to complete this PR:

  • Null notebook bug: Notes get added without being associated properly to a notebook. For illustration, here you can see that they show up in All notes but not in the single notebook (i.e. the only option):

    👉 UPDATE: This only happens if you have no notebooks (which almost only happens in a test environment). I'm going to consider that fine, since they still show up in All notes. @laurent22 lmk if you disagree though! We could consider (a) not showing the quick-actions when there's no notebook to add a note/to-do to, (b) forcing the user to create a notebook before completing the quick-action (I don't love this one), or (c) something else entirely.

  • New note screen bug: The first time you create a note from the quick-action menu, it works perfectly. But if you do it again immediately later, it re-opens the page to that first note you made rather than creating an entirely new note. If you navigate around enough (which I think changes the redux state sufficiently or something), then it'll work again.

    Interestingly, there's no conflict between new notes and new to-dos. In other words, if you create a new note via quick-action and then a new to-do immediately after, you don't see this problem. But you do see it if you do two successive notes or two successive to-dos.

    👉 UPDATE: I believe I fixed this bug by adding this line, but I'm not quite sure why the fix worked a and it's hacky, so I'd love someone's eyes on it to (a) make sure it's actually a fix and (b) potentially suggest something less hacky.

  • Android testing: I still haven't been able to successfully set up Android on my machine, so I'd love for someone to test this on theirs and report back before we merge!

@devonzuegel devonzuegel changed the title Mobile quick actions Mobile: Add quick actions Dec 31, 2019
@devonzuegel devonzuegel marked this pull request as ready for review January 1, 2020 00:14
@devonzuegel
Copy link
Contributor Author

This is ready for review and Android testing :)

@gerroon
Copy link

gerroon commented Jan 1, 2020

I will be happy to test it if there is an apk for it.

@devonzuegel devonzuegel force-pushed the mobile-quick-actions branch from 52fe4ac to 2024fb1 Compare January 6, 2020 22:03
Comment on lines 1 to 24

import {DeviceEventEmitter} from 'react-native';
import QuickActions from 'react-native-quick-actions';
const { _ } = require('lib/locale.js');

export default (dispatch, folderId) => {
QuickActions.setShortcutItems([
{type: 'New note', title: _('New note'), icon: 'Compose'},
{type: 'New to-do', title: _('New to-do'), icon: 'Add'},
]);

DeviceEventEmitter.addListener('quickActionShortcut', data => {
// This dispatch is to momentarily go back to reset state, similar to what
// happens in onJoplinLinkClick_(). Easier to just go back, then go to the
// note since the Note screen doesn't handle reloading a different note.
//
// This hack is necessary because otherwise you get this problem:
// The first time you create a note from the quick-action menu, it works
// perfectly. But if you do it again immediately later, it re-opens the
// page to that first note you made rather than creating an entirely new
// note. If you navigate around enough (which I think changes the redux
// state sufficiently or something), then it'll work again.
dispatch({type: 'NAV_BACK'});

Copy link
Owner

@laurent22 laurent22 Jan 6, 2020

Choose a reason for hiding this comment

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

Please could you move this file outside of "lib"?

Also would you be ok with converting it to TypeScript? I think it should be relatively easy if you follow these steps:

  • Rename the file to QuickAction.ts
  • Add the generated "QuickAction.js" to .gitignore and .eslintignore
  • Run npm run tsc from the root, which might display a few errors related to types. I don't know if you are familiar with TypeScript, but most likely you'll need to set the type of the function parameters. So dispatch:Function, folderId:string, data:any. Then try again npm run tsc.

Other than that, I think the file should pass the TypeScript compilation, if not please let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please could you move this file outside of "lib"?

Sure thing! I just moved it up one level, under ReactNativeClient/.

Also would you be ok with converting it to TypeScript?

Yep, just pushed that change and after some fiddling it seems to compile just fine. Excited to see the project transitioning towards Typescript!

Comment on lines 8 to 9
{type: 'New note', title: _('New note'), icon: 'Compose'},
{type: 'New to-do', title: _('New to-do'), icon: 'Add'},
Copy link
Owner

Choose a reason for hiding this comment

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

Here it should be:

		{type: 'New note', title: _('New note'), icon: 'Compose', userInfo: { url: "" }},
		{type: 'New to-do', title: _('New to-do'), icon: 'Add', userInfo: { url: "" }},

Due to this bug: jordanbyron/react-native-quick-actions#90

Also please add a command and link to that issue so that if we add more actions we don't forget to add the empty userinfo key.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing, I added a comment with a link to the issue. I wasn't quite sure what you meant by "command" (maybe typo of "comment"?), so lmk if I missed something.

@laurent22
Copy link
Owner

laurent22 commented Jan 6, 2020

I've tested on Android and it works great 👍 The only thing is that you need to add the userinfo key I mentioned in the comments due to a bug in the quick-actions package.

image

@devonzuegel
Copy link
Contributor Author

Sorry I've been really busy at work so I haven't had time to look at the feedback yet! I'll do this as soon as I have a moment free.

@devonzuegel
Copy link
Contributor Author

All righty, thanks for your patience! I believe I've resolved all outstanding feedback. Cheers.

@tessus
Copy link
Collaborator

tessus commented Jan 27, 2020

Thanks for the update. There are 2 QuickActions.ts files though. I think you have to delete the one in lib.

@laurent22 we also have to add a tsc target to the package.json file and add it to the CI pipeline. Currently a react-native run-android fails, because the ts files are not compiled....

@devonzuegel
Copy link
Contributor Author

Thanks for the update. There are 2 QuickActions.ts files though. I think you have to delete the one in lib.

Thanks, fixed

@laurent22 we also have to add a tsc target to the package.json file and add it to the CI pipeline. Currently a react-native run-android fails, because the ts files are not compiled....

Anything I can do here, or does the Android version need to be buildable on my machine for me to be helpful?

@tessus
Copy link
Collaborator

tessus commented Feb 9, 2020

Thanks for the update.

Anything I can do here, or does the Android version need to be buildable on my machine for me to be helpful?

I don't think so. I believe @laurent22 has to add something to the build process.

But there are a few conflicts, which have to be resolved, before we can merge.

@laurent22
Copy link
Owner

Sorry I missed the comments from 2 weeks ago. I think it's good to merge once the conflicts are fixed. For pluginAssets/index you can get the latest from master by the way.

@laurent22
Copy link
Owner

Hmm no in fact you can delete pluginAssets/index as it's no longer in the tree.

@tessus
Copy link
Collaborator

tessus commented Feb 11, 2020

@devonzuegel ok, so the only thing that is missing is fixing the conflicts. then we can merge.

@devonzuegel
Copy link
Contributor Author

Had some trouble trying to resolve merge conflicts today. The ios app now won't build, so I must've done something wrong in resolving the conflicts.

Sorry this PR has been dragging on so long, I'll try to get it over the line soon.

@tessus
Copy link
Collaborator

tessus commented Feb 17, 2020

@devonzuegel yep, don't worry about it, things like that can happen.

I think that one thing stands out. We removed the share extension, since we upgraded to reaact-native 0.61. But due to the conflict resolving it's there again. Maybe this is the reason for the compile errors.

@laurent22
Copy link
Owner

The build doesn't work because RN has been upgraded recently and the iOS app in particular is built differently (it now auto-links native packages, and uses Podfiles, which is much better, but also a bit of troubles during the transition).

It's going to be hard to fix so the simplest is to merge the pull request, then I'm going to re-link the packages afterwards.

@laurent22 laurent22 merged commit eeb9999 into laurent22:master Feb 18, 2020
@devonzuegel devonzuegel deleted the mobile-quick-actions branch February 23, 2020 01:07
@devonzuegel
Copy link
Contributor Author

Okay cool! As long as it's building for you then I'm happy. I'm just afraid I may have broken more things by resolving the merge conflicts... Lmk if I can help at all, as I'd hate to create more work for you if I did screw up.

@laurent22
Copy link
Owner

No problem, I've merged it the other day and fixed the build afterwards, so it will be in the next Android and iOS releases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile All mobile platforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants