-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fix Opened offline attachment directed to conversation page on online #49832
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
Fix Opened offline attachment directed to conversation page on online #49832
Conversation
…tachment replaced / deleted
… index is similar
…x/48173-dismiss-when-no-attachment-with-same-page-index
…x/48173-dismiss-when-no-attachment-with-same-page-index
Co-authored-by: Abdelhafidh Belalia <16493223+s77rt@users.noreply.github.com>
s77rt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+Run prettier
| let initialPage = targetAttachments.findIndex(compareImage); | ||
| const prevInitialPage = attachments.findIndex(compareImage); | ||
|
|
||
| // If no matching attachment is found in targetAttachments but found in attachments, update initialPage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is explaining the what not the why. Let's remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
|
||
| // Dismiss the modal when deleting an attachment during its display in preview. | ||
| if (initialPage === -1 && attachments.find(compareImage)) { | ||
| // If no matching attachment with the same index, dismiss the modal |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same ^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| let initialPage = targetAttachments.findIndex(compareImage); | ||
| const prevInitialPage = attachments.findIndex(compareImage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| let initialPage = targetAttachments.findIndex(compareImage); | |
| const prevInitialPage = attachments.findIndex(compareImage); | |
| let attachmentIndex = targetAttachments.findIndex(compareImage); | |
| const prevAttachmentIndex = attachments.findIndex(compareImage); |
I feel that this naming is more correct. findIndex returns an index and not a page. The index is used as the page id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| const prevInitialPage = attachments.findIndex(compareImage); | ||
|
|
||
| // If no matching attachment is found in targetAttachments but found in attachments, update initialPage | ||
| if (initialPage === -1 && prevInitialPage !== -1 && targetAttachments[prevInitialPage]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid comparing with -1 and instead just access the attachment array directly
if (!targetAttachments[attachmentIndex] && targetAttachments[prevAttachmentIndex])There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
…x/48173-dismiss-when-no-attachment-with-same-page-index
| let attachmentIndex = targetAttachments.findIndex(compareImage); | ||
| const prevAttachmentIndex = attachments.findIndex(compareImage); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NAB. Another naming clarity. targetAttachments is confusing.
- targetAttachments -> newAttachments
- attachmentIndex -> newIndex
- prevAttachmentIndex -> index
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Reviewer Checklist
Screenshots/VideosAndroid: Nativeandroid.movAndroid: mWeb Chromemweb-chrome.moviOS: Nativeios.moviOS: mWeb Safarimweb-safari.movMacOS: Chrome / Safariweb.movMacOS: Desktopdesktop.mov |
|
@wildan-m Can you check why on native the attachment changes after getting online? ios.movandroid.mov |
…x/48173-dismiss-when-no-attachment-with-same-page-index
that's pretty weird. @s77rt do you know how to make metro keep logging the log after re-connect? |
…x/48173-dismiss-when-no-attachment-with-same-page-index
|
@s77rt I've created this simple reproduction step, even without scrolling from reanimated, the pager view itself can't properly work if we replace the pager items without re-mounting. Kapture.2024-10-01.at.10.31.56.mp4I think we don't need to report the issue as there are similar issues open. Minimum reproducible codeimport React from 'react';
import { useState } from 'react';
import { Button, SafeAreaView, Text, View, StyleSheet } from 'react-native';
import PagerView from 'react-native-pager-view';
const ids = ['1', '2', '3'];
function getNewArray() {
const newArray = [...ids];
newArray[2] = Math.random().toString(36).substring(7); // Generate a random string
return newArray;
}
export const BasicPagerViewExample = () => {
const [pagesContent, setPagesContent] = useState<string[]>(getNewArray());
const [page, setPage] = useState<number>(2);
console.log(pagesContent);
return (
<SafeAreaView style={{ flex: 1 }}>
<Text style={{ textAlign: 'center' }}>{pagesContent.length}</Text>
<PagerView orientation="horizontal" style={{ flex: 1, backgroundColor: 'yellow' }} initialPage={page}
onPageSelected={(e) => {
console.log('onPageSelected ~ e.nativeEvent.position:', e.nativeEvent.position);
}}
>
{pagesContent.map((content) => (
<View key={content} style={{ flex: 1,backgroundColor: 'green' }}>
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' , backgroundColor:'red'}}>
<Text style={{ fontSize: 30 }}>{content}</Text>
</View>
</View>
))}
</PagerView>
<Button
title={'Replace third page content'}
onPress={() => {
setPagesContent(getNewArray());
setPage(2);
}}
/>
</SafeAreaView>
);
};
export default BasicPagerViewExample
|
|
@wildan-m In main if we follow the same steps in native, the attachment will get dismissed, but now it will change to another one? Is that correct? If so I think we should fix the other bug separately since it's not a true regression (the flow is already broken on main) |
correct
@s77rt that's ok, another option is to temporarily implement the component's key solution until upstream fix resolved. I believe the upstream issue is not a simple fix since many people experience it and the mentioned similar issues is open for a long time. |
|
@wildan-m We should not go with workarounds. Fixing this upstream should be the way to go. For now can yoo please revert the recent changed and fix conflicts? |
…x/48173-dismiss-when-no-attachment-with-same-page-index
@s77rt I think we can't avoid comparing to -1 after this new eslint rule applied, access array using at(-1) will get the last array item |
| const index = attachments.findIndex(compareImage); | ||
|
|
||
| // If no matching attachment with the same index, dismiss the modal | ||
| if (newIndex === -1 && newAttachments.at(index)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to check if index is not -1 too otherwise newAttachments.at(index) may be truthy (please fix same in other places)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
…x/48173-dismiss-when-no-attachment-with-same-page-index
rlinoz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good, I just have a couple of questions
rlinoz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works well, thanks!
|
✋ 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/rlinoz in version: 9.0.45-1 🚀
|
|
🚀 Deployed to production by https://github.com/thienlnam in version: 9.0.45-4 🚀
|
Details
Fix offline attachment opening directly to online conversation page. New dismissal behavior confirmed here: #48173 (comment)
Fixed Issues
$ #48173
PROPOSAL: #48173 (comment) (Alternative 3)
Tests
Note
There is a known issue in the native platform where the attachment index incorrectly switches even after setting it correctly #49832 (comment). This is a known upstream issue that should be addressed separately #49832 (comment).
Offline tests
Same as test
QA Steps
Same as test
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodSTYLE.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 and/or tagged@Expensify/designso 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
Kapture.2024-09-27.at.14.02.17.mp4
Android: mWeb Chrome
Kapture.2024-09-27.at.14.05.10.mp4
iOS: Native
Kapture.2024-09-27.at.11.02.28.mp4
iOS: mWeb Safari
Kapture.2024-09-27.at.13.31.57.mp4
MacOS: Chrome / Safari
Kapture.2024-09-27.at.10.41.52.mp4
MacOS: Desktop
Kapture.2024-09-27.at.14.06.18.mp4