-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Hide flagged attachment in attachment carousel #24564
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
Merged
amyevans
merged 33 commits into
Expensify:main
from
bernhardoj:fix/22915-hide-attachment-in-carousel
Sep 12, 2023
Merged
Changes from all commits
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
This file contains hidden or 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
115 changes: 115 additions & 0 deletions
115
src/components/Attachments/AttachmentCarousel/CarouselItem.js
This file contains hidden or 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,115 @@ | ||
import React, {useContext, useState} from 'react'; | ||
import {View} from 'react-native'; | ||
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'; | ||
import SafeAreaConsumer from '../../SafeAreaConsumer'; | ||
import ReportAttachmentsContext from '../../../pages/home/report/ReportAttachmentsContext'; | ||
|
||
const propTypes = { | ||
/** Attachment required information such as the source and file name */ | ||
item: PropTypes.shape({ | ||
/** Report action ID of the attachment */ | ||
reportActionID: PropTypes.string, | ||
|
||
/** Whether source URL requires authentication */ | ||
isAuthTokenRequired: PropTypes.bool, | ||
|
||
/** The source (URL) of the attachment */ | ||
source: PropTypes.string, | ||
|
||
/** Additional information about the attachment file */ | ||
file: PropTypes.shape({ | ||
/** File name of the attachment */ | ||
name: PropTypes.string, | ||
}), | ||
|
||
/** Whether the attachment has been flagged */ | ||
hasBeenFlagged: 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: undefined, | ||
}; | ||
|
||
function CarouselItem({item, isFocused, onPress}) { | ||
const {translate} = useLocalize(); | ||
const {isAttachmentHidden} = useContext(ReportAttachmentsContext); | ||
// eslint-disable-next-line es/no-nullish-coalescing-operators | ||
const [isHidden, setIsHidden] = useState(isAttachmentHidden(item.reportActionID) ?? item.hasBeenFlagged); | ||
|
||
const renderButton = (style) => ( | ||
<Button | ||
small | ||
style={style} | ||
onPress={() => setIsHidden(!isHidden)} | ||
> | ||
<Text | ||
style={styles.buttonSmallText} | ||
selectable={false} | ||
dataSet={{[CONST.SELECTION_SCRAPER_HIDDEN_ELEMENT]: true}} | ||
> | ||
{isHidden ? translate('moderation.revealMessage') : translate('moderation.hideMessage')} | ||
</Text> | ||
</Button> | ||
); | ||
|
||
if (isHidden) { | ||
const children = ( | ||
<> | ||
<Text style={[styles.textLabelSupporting, styles.textAlignCenter, styles.lh20]}>{translate('moderation.flaggedContent')}</Text> | ||
{renderButton([styles.mt2])} | ||
</> | ||
); | ||
return onPress ? ( | ||
<PressableWithoutFeedback | ||
style={[styles.attachmentRevealButtonContainer]} | ||
onPress={onPress} | ||
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGEBUTTON} | ||
accessibilityLabel={item.file.name || translate('attachmentView.unknownFilename')} | ||
> | ||
{children} | ||
</PressableWithoutFeedback> | ||
) : ( | ||
<View style={[styles.attachmentRevealButtonContainer]}>{children}</View> | ||
); | ||
} | ||
|
||
return ( | ||
<View style={[styles.flex1]}> | ||
<View style={[styles.flex1]}> | ||
<AttachmentView | ||
source={item.source} | ||
file={item.file} | ||
isAuthTokenRequired={item.isAuthTokenRequired} | ||
isFocused={isFocused} | ||
onPress={onPress} | ||
isUsedInCarousel | ||
/> | ||
</View> | ||
|
||
{item.hasBeenFlagged && ( | ||
<SafeAreaConsumer> | ||
{({safeAreaPaddingBottomStyle}) => <View style={[styles.appBG, safeAreaPaddingBottomStyle]}>{renderButton([styles.m4, styles.alignSelfCenter])}</View>} | ||
</SafeAreaConsumer> | ||
)} | ||
</View> | ||
); | ||
} | ||
|
||
CarouselItem.propTypes = propTypes; | ||
CarouselItem.defaultProps = defaultProps; | ||
|
||
export default CarouselItem; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,42 @@ | ||
import React, {useEffect, useMemo, useRef} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import useCurrentReportID from '../../../hooks/useCurrentReportID'; | ||
|
||
const ReportAttachmentsContext = React.createContext(); | ||
|
||
const propTypes = { | ||
/** Rendered child component */ | ||
children: PropTypes.node.isRequired, | ||
}; | ||
|
||
function ReportAttachmentsProvider(props) { | ||
const currentReportID = useCurrentReportID(); | ||
const hiddenAttachments = useRef({}); | ||
|
||
useEffect(() => { | ||
// We only want to store the attachment visibility for the current report. | ||
// If the current report ID changes, clear the ref. | ||
hiddenAttachments.current = {}; | ||
}, [currentReportID]); | ||
|
||
const contextValue = useMemo( | ||
() => ({ | ||
isAttachmentHidden: (reportActionID) => hiddenAttachments.current[reportActionID], | ||
updateHiddenAttachments: (reportActionID, value) => { | ||
hiddenAttachments.current = { | ||
...hiddenAttachments.current, | ||
[reportActionID]: value, | ||
}; | ||
}, | ||
}), | ||
[], | ||
); | ||
|
||
return <ReportAttachmentsContext.Provider value={contextValue}>{props.children}</ReportAttachmentsContext.Provider>; | ||
} | ||
|
||
ReportAttachmentsProvider.propTypes = propTypes; | ||
ReportAttachmentsProvider.displayName = 'ReportAttachmentsProvider'; | ||
|
||
export default ReportAttachmentsContext; | ||
export {ReportAttachmentsProvider}; |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.