Image Web/Desktop: Add support for http headers#34505
Image Web/Desktop: Add support for http headers#34505Beamanator merged 9 commits intoExpensify:mainfrom
Conversation
- Introduced `BaseImage` component that branches between native and web implementations.
- **Native**: Utilizes `FastImage` directly.
- **Web**: Minor adjustments made to the `onLoad` event signature for compatibility.
- Eliminated `Image/index.native.js` as both native and web components now leverage a unified high-level implementation for image loading and rendering.
(cherry picked from commit 2aa37d2)
(cherry picked from commit 19b605e)
This patch focuses on resolving issues encountered with avatar image loading, specifically addressing the challenges related to CORS (Cross-Origin Resource Sharing) errors. Changes: - Removed the `isAuthTokenRequired` flag from the `AttachmentModal` component in various files, including `ProfilePage.js`, `RoomHeaderAvatars.js`, and `DetailsPage.js`. This change is crucial for loading of avatar images that are hosted externally. Rationale: - The primary purpose of this modification is to streamline the loading process for avatars by removing the unnecessary inclusion of authentication tokens in requests for external images. This approach aligns with standard practices for handling externally hosted content and aims to enhance compatibility and performance. - Raised a question here as whether there are cases of avatar images that need authentication: https://github.com/Expensify/App/pull/24425/files#r1404352872 This update is expected to resolve the CORS errors associated with avatar image loading, thereby improving the overall functionality and user experience in our application. (cherry picked from commit cc49208)
(cherry picked from commit 1182c7d)
- Adapt to `expo-image` deprecation of `event.nativeEvent` usage. - Directly use the event object as recommended. - Ensure compatibility with components using the `onLoad` prop.
|
@0xmiroslav Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
|
Is this exact same PR as #13036? All new files should be written in TS. Let's do that |
It has slight changes, so it's not exact.
Allright |
cb435b5 to
d51126f
Compare
|
Author checklist is failing |
I had a little bit of trouble running the Android build, but resolved it today and added screenshots. ✔️ Ready for review |
|
@Beamanator can you please generate adhoc build? |
|
@Beamanator this PR will conflict with #31296. Should we hold this or continue? |
|
@0xmiroslav good idea, I just triggered that build |
Good call, but I think that's fine - whichever gets merged first won't have to deal with merge conflicts :D |
|
@blazejkustra or @fabioh8010 can you please review this PR in TS aspect? 3 new files are added. |
|
🧪🧪 Use the links below to test this adhoc build on Android, iOS, Desktop, and Web. Happy testing! 🧪🧪 |
blazejkustra
left a comment
There was a problem hiding this comment.
Just an idea, we could merge this PR with Ts migration and merge as one. Left one comment
src/components/Image/types.ts
Outdated
| type ImageProps = { | ||
| /** Event called with image dimensions when image is loaded */ | ||
| onLoad?: (event: {nativeEvent: {width: number; height: number}}) => void; | ||
| }; |
There was a problem hiding this comment.
ImageProps are missing some props, you can copy them from here
There was a problem hiding this comment.
Thank you for pointing out the ImageProps. I've reviewed the reference from here and appreciate your suggestion. However, I have some reservations about incorporating these types into my current Pull Request, as they seem tangential to the specific change I'm introducing:
- History of Changes: The file you referenced has undergone several revisions. Directly copying it might inadvertently overwrite its existing history, leading to potential misattribution of changes.
- Irrelevant Props: Some of the props, such as
isAuthTokenRequired, are not relevant to theBaseImagecomponent. Including them could introduce unnecessary complexity or errors. - Platform Specificity: The
BaseImagecomponent is tailored for specific platforms. Using the fullImagePropscould lead to compatibility issues between Expo and React Native Web image, given their differences.
Given these concerns, I propose two alternatives:
- Option A: We could remove the
types.tsfile from this Pull Request and defer its introduction to the other PR, maintaining clarity and separation of concerns. - Option B: Alternatively, we could rename the type to
BaseImagePropsand limit its scope to only include essential props likeonLoad, ensuring compatibility and relevance to the current changes.
I believe either approach would maintain the integrity and focus of the Pull Request while addressing the need for proper typing. I'm open to further discussion on this matter.
There was a problem hiding this comment.
@kidroca Thank you for your perspective on this one! And I agree with you. Both options sounds good to me, although I'm more inclined to option B.
There was a problem hiding this comment.
I've pushed an update that implements option B
yes, I thought the same. |
fabioh8010
left a comment
There was a problem hiding this comment.
LGTM besides @blazejkustra comments!
|
I will need to take this over again as @0xmiroslav is no longer C+ |
|
Please fix conflict |
# Conflicts: # src/components/RoomHeaderAvatars.js # src/pages/ProfilePage.js
✔️ Done |
|
👋 assigned you @aimane-chnaif |
This comment was marked as resolved.
This comment was marked as resolved.
Reviewer Checklist
Screenshots/VideosAndroid: Nativeandroid.movAndroid: mWeb Chromemchrome.moviOS: Nativeios.moviOS: mWeb Safarimsafari.movMacOS: Chrome / Safariweb.movMacOS: Desktopdesktop.mov |
aimane-chnaif
left a comment
There was a problem hiding this comment.
Hopefully pass staging this time 🙏
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/Beamanator in version: 1.4.35-0 🚀
|
|
🚀 Deployed to production by https://github.com/mountiny in version: 1.4.35-7 🚀
|


Details
This PR refactors the
Imagecomponent, aligning the web/desktop and native implementations for better consistency and maintainability.Changes:
Introduced
BaseImageComponent:src/components/Image/BaseImage.tsxonLoadevent, it ensures that both web and native platforms have the same signature.Native Implementation Update:
src/components/Image/BaseImage.native.tsxexpo-image, with a slight adjustment for theonLoadprop, to make it's interface uniform.Unified Image Component for Web/Desktop and Native:
src/components/Image/index.jsImagecomponent has been refactored to use the newBaseImage.Removed Redundant Native Specific Implementation:
src/components/Image/index.native.jsPatch for
react-native-webpatches/react-native-web+0.19.9+005+image-header-support.patchFixed Issues
$ #12603
PROPOSAL: N/A
Tests
Verify the Image component works on all platforms
X-Chat-Attachment-Tokenheader.X-Chat-Attachment-Tokenvalue changes.Offline tests
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel so the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop