Repository navigation
Add attachment picker to Expensify Chat - #463
Conversation
| } | ||
|
|
||
| const ImagePicker = { | ||
| showImagePicker(options, callback) { |
There was a problem hiding this comment.
Since this const is an object with just one property, I think the object is unnecessary. This should just be:
const ImagePicker = (options, callback) => ....
There was a problem hiding this comment.
Ended up adding one more property here, but this is good to know 👍
| updateComment(newComment) { | ||
| this.setState({ | ||
| comment: newComment, | ||
| onAttachmentButtonTapped(e) { |
There was a problem hiding this comment.
Rename to uploadAttachment() (methods should be named for what they do, not what they handle)
| e.preventDefault(); | ||
| } | ||
|
|
||
| const reportID = this.props.reportID; |
| this.setState({ | ||
| comment: newComment, | ||
| onAttachmentButtonTapped(e) { | ||
| if (e) { |
There was a problem hiding this comment.
I don't think there is a case where there wouldn't be an event, would there?
|
This is mostly done, I just need to work around the upload issue on 0.63+ so this runs without a local fix. Going to try to change the RN version to 0.62.2 which was the last working version before this issue. After a quick |
| const propTypes = { | ||
| // The URL to open | ||
| href: PropTypes.string.isRequired, | ||
| href: PropTypes.string, |
There was a problem hiding this comment.
This was causing a warning on iOS/Android, so I updated it to match web
|
This is off WIP and ready for review. I've added some context in the description for why I opted to use |
|
|
||
| const ImagePicker = { | ||
| showImagePicker(options, callback) { | ||
| const {files} = input; |
There was a problem hiding this comment.
This destructuring really isn't valuable IMO since it's only referenced once.
| input.value = ''; | ||
| } | ||
|
|
||
| function onfocus() { |
There was a problem hiding this comment.
We have been avoiding nested functions in this code, so I would recommend just using an anonymous function when the event listener is added.
| showImagePicker(options, callback) { | ||
| const {files} = input; | ||
|
|
||
| // Clear previously saved files |
There was a problem hiding this comment.
Rather than having to deal with previously saved files, and also ensuring that the onFocus event is removed, I think it would simplify the code a little bit and prevent side-effects if the input was created and destroyed every time showImagePicker() is called.
| body.removeEventListener('focus', onfocus, true); | ||
|
|
||
| // Add a 500 millisecond delay here to ensure input.files is set before checking it | ||
| _.delay(() => { |
There was a problem hiding this comment.
I've been looking at this, trying to figure out why the delay is necessary. My gut tells me that it shouldn't be necessary, and the comment above doesn't really explain why input.files wouldn't be set. Maybe listening to the change event would be better? I'd love to see you find a way to remove this delay completely.
There was a problem hiding this comment.
Sounds good, I'll have a look and see if I can get it working without a delay
| /** | ||
| * Handle the attachment icon being tapped | ||
| * | ||
| * @param {SyntheticEvent} [e] |
There was a problem hiding this comment.
| * @param {SyntheticEvent} [e] | |
| * @param {SyntheticEvent} e |
Looks like it's required
| showImagePicker(options, callback) { | ||
| const input = document.createElement('input'); | ||
| input.type = 'file'; | ||
| input.onchange = function () { |
There was a problem hiding this comment.
I updated this to use the onchange event which simplified this a ton, the only caveat being that we don't know when the user hits cancel since this event doesn't fire on cancel. However, we aren't looking to take any specific actions on cancel, so I think this is fine.
I did some testing with other events as well and I wasn't able to find a good solution that was able to tell if the user canceled without adding some sort of delay. There were a few StackOverflow posts that used jQuery and claimed that the onChange event fired on cancel, but it didn't work in testing.
|
Updated and re-tested, this is ready for another look. I also confirmed that the image picker and take photo functionality work on my iOS device (@AndrewGable tested on an Android device). |
|
Experiencing two issues.
Both can be seen in this video. To Reproduce
|
|
Created an issue here and assigned myself to investigate |
|
The above was on Desktop v.62. I just tested on web (after clearing cookies) and had the exact same issues |
|
Just a heads up, but that issue with the spinner not disappearing is almost certainly caused by the same thing being discussed in #466 which requires a pretty extensive fix. |
|
Ah thanks for the info, that makes sense as I didn't see anything obvious in my additions that would be causing that. I'll close the spinner issue and leave a note to only reopen if we can reproduce after #466 is merged. |
Add attachment picker to Expensify Chat
@tgolen @AndrewGable will you please review this?
Fixes #87
Details
This PR adds support for uploading images on iOS/Android, and files on web.
This issue still exists on React Native version 0.63+, so to fix this I've added the patch-package dependency to allow us to apply the 1 line fix for this issue rather than dealing with reverting the RN version to 0.62.2, which requires that we manually manage pods in the podfile instead of using
use_react_native!(:path => config["reactNativePath"])to manage all of them. Once the fix for the RN issue is merged, we can simply remove thepatch-packageline in package.json, and remove thepatchdirectory.Tests