-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Hide flagged attachment in attachment carousel #24564
Merged
amyevans
merged 33 commits into
Expensify:main
from
bernhardoj:fix/22915-hide-attachment-in-carousel
Sep 12, 2023
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
f53d3dc
hide flagged attachment in carousel
bernhardoj 6d0190c
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj 104f0f4
remove auto hide after out of focus
bernhardoj 7dfcf17
remove unused import
bernhardoj 93fe8c3
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj 0fd41e9
add comment and SELECTION_SCRAPER_HIDDEN_ELEMENT dataset
bernhardoj 6b6f267
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj 95045a5
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj 1734b16
show hidden message button on a flagged attachment
bernhardoj 83c629e
change default onpress to undefined
bernhardoj d5b8130
use view if it's not pressable
bernhardoj 4dbf950
add safe area padding bottom
bernhardoj e7956b3
add bg
bernhardoj 8863e79
rename jsdoc param
bernhardoj dce6721
created new style
bernhardoj fc337d6
created new style
bernhardoj 4202190
lint
bernhardoj 4d41062
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj 8d22119
Merge with 'main' branch
bernhardoj e850d52
share the attachment visibilty state through context
bernhardoj 3f396d6
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj 0b586f4
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj 619af69
memoize context value
bernhardoj f151ae0
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj c315df5
use prev state to update
bernhardoj fe07eba
move the optimization up to the context
bernhardoj 0315c87
rename variable
bernhardoj 7244223
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj 31385c3
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj b9ef612
use ref instead of state to prevent unnecessary rerender
bernhardoj ab4d5f3
optimize the code
bernhardoj 9a0755c
update comment
bernhardoj 4df91a2
simplify code
bernhardoj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
src/components/Attachments/AttachmentCarousel/CarouselItem.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React, {useState, useEffect} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import CONST from '../../../CONST'; | ||
import styles from '../../../styles/styles'; | ||
import useLocalize from '../../../hooks/useLocalize'; | ||
import PressableWithoutFeedback from '../../Pressable/PressableWithoutFeedback'; | ||
import Text from '../../Text'; | ||
import Button from '../../Button'; | ||
import AttachmentView from '../AttachmentView'; | ||
|
||
const propTypes = { | ||
/** Attachment required information such as the source and file name */ | ||
item: PropTypes.shape({ | ||
isAuthTokenRequired: PropTypes.bool, | ||
source: PropTypes.string, | ||
file: PropTypes.shape({name: PropTypes.string}), | ||
isHidden: PropTypes.bool, | ||
}).isRequired, | ||
|
||
/** Whether the attachment is currently being viewed in the carousel */ | ||
isFocused: PropTypes.bool.isRequired, | ||
|
||
/** onPress callback */ | ||
onPress: PropTypes.func, | ||
}; | ||
|
||
const defaultProps = { | ||
onPress: () => {}, | ||
}; | ||
|
||
function CarouselItem({item, isFocused, onPress}) { | ||
const {translate} = useLocalize(); | ||
const [isHidden, setIsHidden] = useState(item.isHidden); | ||
|
||
useEffect(() => { | ||
if (isFocused) { | ||
return; | ||
} | ||
// When the attachment is out of focus, we want to hide the attachment back | ||
setIsHidden(item.isHidden); | ||
}, [isFocused, item.isHidden]); | ||
|
||
if (isHidden) { | ||
return ( | ||
<PressableWithoutFeedback | ||
style={[styles.w100, styles.h100, styles.alignItemsCenter, styles.justifyContentCenter, styles.ph4]} | ||
onPress={onPress} | ||
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON} | ||
accessibilityLabel={item.file.name || translate('attachmentView.unknownFilename')} | ||
> | ||
<Text style={[styles.textLabelSupporting, styles.textAlignCenter, styles.lh20]}>{translate('moderation.flaggedContent')}</Text> | ||
<Button | ||
small | ||
style={[styles.mt2]} | ||
onPress={() => setIsHidden(false)} | ||
> | ||
<Text | ||
style={styles.buttonSmallText} | ||
selectable={false} | ||
> | ||
{translate('moderation.revealMessage')} | ||
</Text> | ||
</Button> | ||
</PressableWithoutFeedback> | ||
); | ||
} | ||
|
||
return ( | ||
<AttachmentView | ||
source={item.source} | ||
file={item.file} | ||
isAuthTokenRequired={item.isAuthTokenRequired} | ||
isFocused={isFocused} | ||
onPress={onPress} | ||
isUsedInCarousel | ||
/> | ||
); | ||
} | ||
|
||
CarouselItem.propTypes = propTypes; | ||
CarouselItem.defaultProps = defaultProps; | ||
|
||
export default CarouselItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 just remove this hook? it's causing this little bug on native/ mWeb Chrome. The attachment is getting hidden before the navigation
CleanShot.2023-08-16.at.13.22.46-converted.mp4
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.
Open the flagged attachment and try to swipe to the next attachment,then cancel the gesture and you can notice that the attachment is hidden.
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.
I think we either keep the attachment visible until the next re-render or keep the attachment visible and implement the hide button similar to comments
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.
I tested moving the logic to
componentWillUnmount
, it fixes this bug, but it introduces another bug, sometimes the attachment gets hidden after the next preview. I think that's because updatating state doesn’t works incomponentWillUnmount
!?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 actually have the viewability config here to update the focus state only when the attachment is 95% visible
App/src/components/Attachments/AttachmentCarousel/index.js
Lines 20 to 24 in 7f13cdd
but somehow this didn't work correctly.
If this works correctly, I think the hook is fine even though it will still revert to hidden when we swipe 95%.
I don't think the CarouselItem is unmounted when we swipe it, except the attachment is out of the flat list window size.
if the component is unmounted, there is no use to update the state because the state is also gone
I think this is the best choice for now. If someone later reported a bug to hide the attachment back when navigating to another attachment, then we can reintroduce the hook but also fix the viewability issue of the flatlist. What do you think?
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.
@shawnborton Ah, okay. Which one do you prefer?
1 (button full width)
2 (button in center)
(button horizontal and vertical margin is 16)
@fedirjh sure, I will test the zooming later
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.
@shawnborton any preference on the button view above? 👆
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.
I think the Centered button makes sense, It aligns with the hide button :
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 for me too!
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.
Great, thanks for the confirmation.
@fedirjh there is an issue with the image zooming, pdf is fine, will try to fix it.