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
Upload custom files of any type. #3490
Conversation
3f06c37
to
13abcbc
Compare
Further Note: Please read the commit messages (they have some points of concern addressed in them). |
Thanks @ishammahajan ! I especially appreciate all the clear explanations. 😄 As I said just now over on the issue (#3184), I'd like to set aside for now iCloud or other iOS versions of this feature, and focus on the Android case. So, perhaps that simplifies things! We just need to ensure we don't break anything on iOS. On this particular third-party library, it concerns me a little that the README has screenshots and copious description for the iOS case, and just a bare code snippet for Android. Makes me suspect that they're primarily focused on the iOS case. Can you say more about how the UX is on Android? Some screenshots might be helpful, too. |
Ah, I have an alternative solution for this! 😉 Take a look at 0c52f4a, acb979c, and b8010de . With that style, we can use the names we think best, and not have to change the name to avoid this kind of name collision. |
Meanwhile I just pushed the first commit from this branch, as cab9cb5 -- thanks for that fix! I wonder if we should do the same even when the menu isn't expanded, when there's only placeholder text or perhaps when the compose box isn't focused. Here's a max-length stream name, on an emulated Nexus 5 with display and font zoom cranked up to max: |
(Propagating priority from the issue.) |
I think that is because the setup process is much more complicated for iOS than for Android. Primarily that is because of Apple 'protecting' their users. Android has very little in terms of security when choosing files (which is to say they have a good understanding of where protection is necessary).
The UX on android would be what files app you have/use for viewing the different files on your device. Here's the code they use to achieve it. Note the Meanwhile, here's the UI found on my OnePlus device. |
13abcbc
to
22f471a
Compare
Hmm. I think a followup to this issue would be to add progress bars to uploads -- both images and files (since I have noticed while adding large files it appears to take very long to do so, while giving no indication that the upload has started). |
BTW this would be more helpful as a link 🙂 -- then I can read the text normally in my browser, complete with Ctrl+F, copy-paste, browsing to neighboring files, etc. |
Generally this looks good! Thanks for that tweak on the renames, as well as the added information above. I think the remaining things before merge are
Then:
|
These changes actually do enable uploads for iOS. I don't know what the UI redirected towards is supposed to be though (this is on iOS 12.0). Here's the recording. Would you please test this on your physical device as well? I think it will work and it's preferable that we don't disable the specific features on iOS.
Sure, thanks! 😄
Ah, I'll just push another commit which does this in this PR itself, then.
Yup, although I don't think I will be able to do that. Someone with admin privilege is needed if I'm not wrong. |
Hmm, I see -- in that recording, it looks like there's some non-iCloud UI that this leads to, so it might actually function properly already. What I'd thought you were saying earlier is that this wouldn't work at all on iOS until we do the additional steps necessary to interact with iCloud. OK, I'll play with it on my iPhone. Won't get to it today, though. |
c7e3ad3 compose box: Keep
|
Well, during development I made the false assumption that someone would tap the button only when the compose box was in focus. I'll go fix that in a jiffy. |
c7e3ad3
to
7192b44
Compare
7192b44 compose box: Keep
|
7192b44
to
0d59686
Compare
Thanks for the review! :)
I see the problem, and I think I'll just remove this commit for now. How does just
I think I remember one recent issue where a user was asking for custom file uploads from iOS. It might have been sharing from another app, I don't really remember. Tried finding it and couldn't. Perhaps they were asking for another feature altogether.
That makes sense, given the time constraint I'm facing in my university. I've removed iOS support using basic platform checking. |
0d59686
to
4682fbb
Compare
This gets minor updates to various libdefs, and adds an autogenerated libdef for `prop-types` because in the recent 5b6014e we added that to our dependencies. (We don't actually *use* it, which is why we hadn't previously noticed its absence from the libdefs.)
These are used in only one place; move them there, making both that code and the styles easier to understand.
I'm sorry, but this is still not ready for merge. First, in this version it doesn't actually work! The icon never appears, because this condition is always false:
The value is Moreover, if the spelling were fixed, that would make it show up only on iOS -- the reverse of the intent. Then when it doesn't show up, the menu is still widened to make room for it -- so there's a buggy-looking blank space. So it looks like you didn't really test this version, either on iOS or on Android. OK, that's not too hard to fix once it's debugged, and I fixed it. I fixed a few other issues, and was about to merge a version of it. Then I noticed that running tests was extremely noisy -- if I run
Looking at the library's source, it decides at import time to emit this warning when the native module isn't present. The native module is indeed not present, because that's part of Jest doing its work so quickly. Then it emits it inside a We can't accept that level of warning noise as routine -- it makes it much too hard to spot a new warning. I'm going to try to merge as much of this as I can, given the work I just did to clean it up. |
`uploadImage` has been changed to the more appropriate `uploadFile` since it uploads every file and not only images. Appropriately, in `fetchActions.js`, the function calling `uploadFile` has been replaced by just the default export of `api` (convenience added in b8010de in an effort to solve a similar problem encountered before). Also changed `handleImageUpload` to `handleImagePicker` for that is the more accurate version of what the function is doing.
`react-native-document-picker` is a library used to pick documents from the device memory or the cloud services connected to the device. This commit adds the dependency for this package, and links it. Based on the guide at: react-native-documents/document-picker#94 [greg: cut Xcode config; ran `yarn update-libdefs` to pick up an autogenerated libdef in flow-typed/.]
Adding support for upload of custom files on Android has been a feature long awaited by users. This commit adds the feature. Fixes zulip#3184. [greg: squashed and fixed per-platform logic; fixed menu size to vary accordingly]
The `react-native-document-picker` and `react-native-image-picker` libraries are separately authored and maintained, and have chosen different APIs. In the parent commit, we took responses from the former and rearranged them to look like responses from the latter, in order to pass them to the handler we'd previously written for the latter. Instead, factor out just the bit that's actually in common, and handle the DocumentPicker responses in a way that's natural for that library's API. This also saves us from the common Promise API mistake of invoking `.catch()` on the return value of `.then` when we really only intend to handle errors from the original Promise. As written, this code would invoke `this.handleImagePickerResponse` a second time if for some reason there was an exception thrown when we called it the first time. Also the annotation `error: string` on the `catch` handler's parameter isn't true; drop it. (Indeed it it were true, `DocumentPicker.isCancel` wouldn't work at all.)
Replace the autogenerated libdef with one based on looking through the (short) source code of the implementation. Moreover, on doing so we find a type error! The `name` property may not be present in the response. Adjust the logic to handle that.
This library prints an obnoxious warning right at import time, if its native module isn't present. (Actually worse: at import time it calls `setTimeout` with a callback to print the warning.) Running under Jest, the native module is of course not present. As a result, we were getting a flood of this warning on every `tools/test` run. Work around the obnoxious warning by deferring import to inside the handler where we're about to actually invoke the library.
4682fbb
to
b20dbcf
Compare
OK, merged! Thanks again for all your work on this PR. I was able to work around the obnoxious repeating warning by moving the Do take a look at the other commits in the series as well. |
🎉 About the testing, I had updated the PR locally, but because of another bug I was trying to resolve (which was the
That's a little confusing at first. Makes sense though.
I have done that now, thanks for the help :) |
That's a good insight, thanks!
I wonder if we should add a comment here explaining this (in case the git blame gets overwritten for this piece). |
Sure, good thought, thanks -- done, as c61702e.
Though when you are looking in the history to see how and why something happened, I would highly recommend skimming through |
In 33f4b41 (the CocoaPods commit), we sectioned off a "Pods we need that depend on React Native" list. First, we accumulated these dependencies one by one as we observed build failures caused by their absence. (It's self-evident that we did this, at least, but I'm fairly certain we also went down a list in the Xcode UI of libraries that were linked.) Then, we checked this list in the Podfile against a search of libraries in node_modules with a "podspec" file that declared a dependency on React Native. From that commit: """ We also added a number of dependencies that depend on React Native (react-native-image-picker, etc.). `grep -Rlw 'React' --include=\*.podspec node_modules/` verified that they do indeed depend on the 'React' pod, which is React Native. """ Now, while working on the RN v0.60.0 upgrade, I decided to re-check that list with a more precise search: ``` grep -Rl dependency.*React --include=\*.podspec --exclude="node_modules/react-native/*" node_modules ``` -- we were looking for non-RN libraries that have a podspec with a line like `s.dependency 'React'`. The results of this search are much cleaner. It (a) excludes podspec files in `react-native`, and (b) excludes offhand, code-comment mentions of React. (b) didn't change the result set at all, but (a) reduced a lot of noise. Following cb87f90, there's a result from `@unimodules` which we can ignore; that's handled by `use_unimodules!`. I re-checked that everything in that list in our Podfile matched one of these search results; so far, so good. But with this cleaner result set, I had the idea to check the reverse: that each item in the result set (except the irrelevant `@unimodules` one) was represented in that list in the Podfile. Two results were not: `react-native-document-picker` and `react-native-screens`. I verified that, in fact, we weren't linking either of these before the CocoaPods commit. But it's best to mark this explicitly, with my (new, alas) knowledge that we're excluding them intentionally. Some background on why we didn't link them -- On iOS, there are currently no uses of `react-native-document-picker`; it's only imported in `src/compose/ComposeMenu.js`, and there, only to enable file uploads on Android. See d9bbb5e, and the discussion at zulip#3490, where it looks like we explicitly decided *not* to link it on iOS -- some stuff in `project.pbxproj` was auto-generated, as we'd expect before CocoaPods, and Greg removed it as unnecessary. Piecing together the `react-native-screens` story was more interesting, and it resulted in filing #M4111. See also discussion in chat at https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.3A.20r-n-screens.20.2F.20r-n-document-picker/near/877096. We haven't really known what this library can do for us, but now we sort of do. Anyway, we explicitly decided not to link it during work on 0d2066f; see https://chat.zulip.org/#narrow/stream/48-mobile/topic/Windows.20build/near/794533; that will change during work on zulip#4111.
In 33f4b41 (the CocoaPods commit), we sectioned off a "Pods we need that depend on React Native" list. First, we accumulated these dependencies one by one as we observed build failures caused by their absence. (It's self-evident that we did this, at least, but I'm fairly certain we also went down a list in the Xcode UI of libraries that were linked.) Then, we checked this list in the Podfile against a search of libraries in node_modules with a "podspec" file that declared a dependency on React Native. From that commit: """ We also added a number of dependencies that depend on React Native (react-native-image-picker, etc.). `grep -Rlw 'React' --include=\*.podspec node_modules/` verified that they do indeed depend on the 'React' pod, which is React Native. """ Now, while working on the RN v0.60.0 upgrade, I decided to re-check that list with a more precise search: ``` grep -Rl dependency.*React --include=\*.podspec --exclude="node_modules/react-native/*" node_modules ``` -- we were looking for non-RN libraries that have a podspec with a line like `s.dependency 'React'`. The results of this search are much cleaner. It (a) excludes podspec files in `react-native`, and (b) excludes offhand, code-comment mentions of React. (b) didn't change the result set at all, but (a) reduced a lot of noise. Following cb87f90, there's a result from `@unimodules` which we can ignore; that's handled by `use_unimodules!`. I re-checked that everything in that list in our Podfile matched one of these search results; so far, so good. But with this cleaner result set, I had the idea to check the reverse: that each item in the result set (except the irrelevant `@unimodules` one) was represented in that list in the Podfile. Two results were not: `react-native-document-picker` and `react-native-screens`. I verified that, in fact, we weren't linking either of these before the CocoaPods commit. But it's best to mark this explicitly, with my (new, alas) knowledge that we're excluding them intentionally. Some background on why we didn't link them -- On iOS, there are currently no uses of `react-native-document-picker`; it's only imported in `src/compose/ComposeMenu.js`, and there, only to enable file uploads on Android. See d9bbb5e, and the discussion at zulip#3490, where it looks like we explicitly decided *not* to link it on iOS -- some stuff in `project.pbxproj` was auto-generated, as we'd expect before CocoaPods, and Greg removed it as unnecessary. Piecing together the `react-native-screens` story was more interesting, and it resulted in filing #M4111. See also discussion in chat at https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.3A.20r-n-screens.20.2F.20r-n-document-picker/near/877096. We haven't really known what this library can do for us, but now we sort of do. Anyway, we explicitly decided not to link it during work on 0d2066f; see https://chat.zulip.org/#narrow/stream/48-mobile/topic/Windows.20build/near/794533; that will change during work on zulip#4111.
In 33f4b41 (the CocoaPods commit), we sectioned off a "Pods we need that depend on React Native" list. First, we accumulated these dependencies one by one as we observed build failures caused by their absence. (It's self-evident that we did this, at least, but I'm fairly certain we also went down a list in the Xcode UI of libraries that were linked.) Then, we checked this list in the Podfile against a search of libraries in node_modules with a "podspec" file that declared a dependency on React Native. From that commit: """ We also added a number of dependencies that depend on React Native (react-native-image-picker, etc.). `grep -Rlw 'React' --include=\*.podspec node_modules/` verified that they do indeed depend on the 'React' pod, which is React Native. """ Now, while working on the RN v0.60.0 upgrade, I decided to re-check that list with a more precise search: ``` grep -Rl dependency.*React --include=\*.podspec \ --exclude="node_modules/react-native/*" node_modules ``` -- we were looking for non-RN libraries that have a podspec with a line like `s.dependency 'React'`. The results of this search are much cleaner. It (a) excludes podspec files in `react-native`, and (b) excludes offhand, code-comment mentions of React. (b) didn't change the result set at all, but (a) reduced a lot of noise. Following cb87f90, there's a result from `@unimodules` which we can ignore; that's handled by `use_unimodules!`. I re-checked that everything in that list in our Podfile matched one of these search results; so far, so good. But with this cleaner result set, I had the idea to check the reverse: that each item in the result set (except the irrelevant `@unimodules` one) was represented in that list in the Podfile. Two results were not: `react-native-document-picker` and `react-native-screens`. I verified that, in fact, we weren't linking either of these before the CocoaPods commit. But it's best to mark this explicitly, with my (new, alas) knowledge that we're excluding them intentionally. Some background on why we didn't link them -- On iOS, there are currently no uses of `react-native-document-picker`; it's only imported in `src/compose/ComposeMenu.js`, and there, only to enable file uploads on Android. See d9bbb5e, and the discussion at zulip#3490, where it looks like we explicitly decided *not* to link it on iOS -- some stuff in `project.pbxproj` was auto-generated, as we'd expect before CocoaPods, and Greg removed it as unnecessary. Piecing together the `react-native-screens` story was more interesting, and it resulted in filing #M4111. See also discussion in chat [1]. We haven't really known what this library can do for us, but now we sort of do. Anyway, we explicitly decided not to link it during work on 0d2066f; see discussion [2]. That will change during work on zulip#4111. [1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.3A.20r-n-screens.20.2F.20r-n-document-picker/near/877096. [2]: https://chat.zulip.org/#narrow/stream/48-mobile/topic/Windows.20build/near/794533;
In 33f4b41 (the CocoaPods commit), we sectioned off a "Pods we need that depend on React Native" list. First, we accumulated these dependencies one by one as we observed build failures caused by their absence. (It's self-evident that we did this, at least, but I'm fairly certain we also went down a list in the Xcode UI of libraries that were linked.) Then, we checked this list in the Podfile against a search of libraries in node_modules with a "podspec" file that declared a dependency on React Native. From that commit: """ We also added a number of dependencies that depend on React Native (react-native-image-picker, etc.). `grep -Rlw 'React' --include=\*.podspec node_modules/` verified that they do indeed depend on the 'React' pod, which is React Native. """ Now, while working on the RN v0.60.0 upgrade, I decided to re-check that list with a more precise search: ``` grep -Rl dependency.*React --include=\*.podspec \ --exclude="node_modules/react-native/*" node_modules ``` -- we were looking for non-RN libraries that have a podspec with a line like `s.dependency 'React'`. The results of this search are much cleaner. It (a) excludes podspec files in `react-native`, and (b) excludes offhand, code-comment mentions of React. (b) didn't change the result set at all, but (a) reduced a lot of noise. Following cb87f90, there's a result from `@unimodules` which we can ignore; that's handled by `use_unimodules!`. I re-checked that everything in that list in our Podfile matched one of these search results; so far, so good. But with this cleaner result set, I had the idea to check the reverse: that each item in the result set (except the irrelevant `@unimodules` one) was represented in that list in the Podfile. Two results were not: `react-native-document-picker` and `react-native-screens`. I verified that, in fact, we weren't linking either of these before the CocoaPods commit. But it's best to mark this explicitly, with my (new, alas) knowledge that we're excluding them intentionally. Some background on why we didn't link them -- On iOS, there are currently no uses of `react-native-document-picker`; it's only imported in `src/compose/ComposeMenu.js`, and there, only to enable file uploads on Android. See d9bbb5e, and the discussion at zulip#3490, where it looks like we explicitly decided *not* to link it on iOS -- some stuff in `project.pbxproj` was auto-generated, as we'd expect before CocoaPods, and Greg removed it as unnecessary. Piecing together the `react-native-screens` story was more interesting, and it resulted in filing #M4111. See also discussion in chat [1]. We haven't really known what this library can do for us, but now we sort of do. Anyway, we explicitly decided not to link it during work on 0d2066f; see discussion [2]. That will change during work on zulip#4111. [1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.3A.20r-n-screens.20.2F.20r-n-document-picker/near/877096 [2]: https://chat.zulip.org/#narrow/stream/48-mobile/topic/Windows.20build/near/794533
In 33f4b41 (the CocoaPods commit), we sectioned off a "Pods we need that depend on React Native" list. First, we accumulated these dependencies one by one as we observed build failures caused by their absence. (It's self-evident that we did this, at least, but I'm fairly certain we also went down a list in the Xcode UI of libraries that were linked.) Then, we checked this list in the Podfile against a search of libraries in node_modules with a "podspec" file that declared a dependency on React Native. From that commit: """ We also added a number of dependencies that depend on React Native (react-native-image-picker, etc.). `grep -Rlw 'React' --include=\*.podspec node_modules/` verified that they do indeed depend on the 'React' pod, which is React Native. """ Now, while working on the RN v0.60.0 upgrade, I decided to re-check that list with a more precise search: ``` grep -Rl dependency.*React --include=\*.podspec \ --exclude="node_modules/react-native/*" node_modules ``` -- we were looking for non-RN libraries that have a podspec with a line like `s.dependency 'React'`. The results of this search are much cleaner. It (a) excludes podspec files in `react-native`, and (b) excludes offhand, code-comment mentions of React. (b) didn't change the result set at all, but (a) reduced a lot of noise. Following cb87f90, there's a result from `@unimodules` which we can ignore; that's handled by `use_unimodules!`. I re-checked that everything in that list in our Podfile matched one of these search results; so far, so good. But with this cleaner result set, I had the idea to check the reverse: that each item in the result set (except the irrelevant `@unimodules` one) was represented in that list in the Podfile. Two results were not: `react-native-document-picker` and `react-native-screens`. I verified that, in fact, we weren't linking either of these before the CocoaPods commit. But it's best to mark this explicitly, with my (new, alas) knowledge that we're excluding them intentionally. Some background on why we didn't link them -- On iOS, there are currently no uses of `react-native-document-picker`; it's only imported in `src/compose/ComposeMenu.js`, and there, only to enable file uploads on Android. See d9bbb5e, and the discussion at zulip#3490, where it looks like we explicitly decided *not* to link it on iOS -- some stuff in `project.pbxproj` was auto-generated, as we'd expect before CocoaPods, and Greg removed it as unnecessary. Piecing together the `react-native-screens` story was more interesting, and it resulted in filing #M4111. See also discussion in chat [1]. We haven't really known what this library can do for us, but now we sort of do. Anyway, we explicitly decided not to link it during work on 0d2066f; see discussion [2]. That will change during work on zulip#4111. [1]: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/iOS.3A.20r-n-screens.20.2F.20r-n-document-picker/near/877096 [2]: https://chat.zulip.org/#narrow/stream/48-mobile/topic/Windows.20build/near/794533
Adding support for upload of custom files on mobile has been a
feature long avaited by users. This commit adds the feature.
Size of the expanded
ComposeMenu
has been increased by 4/3. SincehandleImagePickerResponse
works for all types of files and notonly image files it has been renamed to
handleFileUpload
, and theupload traffic from
handleFilePicker
has also been redirected tohandleFileUpload
.NOTE: Adequate testing hasn't been done on iOS since I don't own an iOS device. Please test and produce the results here if possible.