Skip to content
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
Merged
Show file tree
Hide file tree
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 Aug 15, 2023
6d0190c
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Aug 16, 2023
104f0f4
remove auto hide after out of focus
bernhardoj Aug 16, 2023
7dfcf17
remove unused import
bernhardoj Aug 16, 2023
93fe8c3
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Aug 18, 2023
0fd41e9
add comment and SELECTION_SCRAPER_HIDDEN_ELEMENT dataset
bernhardoj Aug 18, 2023
6b6f267
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Aug 21, 2023
95045a5
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Aug 23, 2023
1734b16
show hidden message button on a flagged attachment
bernhardoj Aug 23, 2023
83c629e
change default onpress to undefined
bernhardoj Aug 23, 2023
d5b8130
use view if it's not pressable
bernhardoj Aug 23, 2023
4dbf950
add safe area padding bottom
bernhardoj Aug 23, 2023
e7956b3
add bg
bernhardoj Aug 23, 2023
8863e79
rename jsdoc param
bernhardoj Aug 23, 2023
dce6721
created new style
bernhardoj Aug 23, 2023
fc337d6
created new style
bernhardoj Aug 23, 2023
4202190
lint
bernhardoj Aug 23, 2023
4d41062
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Aug 28, 2023
8d22119
Merge with 'main' branch
bernhardoj Sep 3, 2023
e850d52
share the attachment visibilty state through context
bernhardoj Sep 4, 2023
3f396d6
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Sep 4, 2023
0b586f4
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Sep 6, 2023
619af69
memoize context value
bernhardoj Sep 6, 2023
f151ae0
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Sep 7, 2023
c315df5
use prev state to update
bernhardoj Sep 7, 2023
fe07eba
move the optimization up to the context
bernhardoj Sep 7, 2023
0315c87
rename variable
bernhardoj Sep 7, 2023
7244223
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Sep 11, 2023
31385c3
Merge branch 'main' into fix/22915-hide-attachment-in-carousel
bernhardoj Sep 11, 2023
b9ef612
use ref instead of state to prevent unnecessary rerender
bernhardoj Sep 11, 2023
ab4d5f3
optimize the code
bernhardoj Sep 11, 2023
9a0755c
update comment
bernhardoj Sep 12, 2023
4df91a2
simplify code
bernhardoj Sep 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions src/components/Attachments/AttachmentCarousel/CarouselItem.js
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(() => {
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor

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 in componentWillUnmount !?

Copy link
Contributor Author

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

const viewabilityConfig = {
// To facilitate paging through the attachments, we want to consider an item "viewable" when it is
// more than 95% visible. When that happens we update the page index in the state.
itemVisiblePercentThreshold: 95,
};

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 tested moving the logic to componentWillUnmount

I don't think the CarouselItem is unmounted when we swipe it, except the attachment is out of the flat list window size.

I think that's because updatating state doesn’t works in componentWillUnmount

if the component is unmounted, there is no use to update the state because the state is also gone

I think we either keep the attachment visible until the next re-render or keep the attachment visible

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?

Copy link
Contributor Author

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)
image

2 (button in center)
image

(button horizontal and vertical margin is 16)

@fedirjh sure, I will test the zooming later

Copy link
Contributor Author

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? 👆

Copy link
Contributor

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 :

Screenshot 2023-08-22 at 7 23 55 PM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me too!

Copy link
Contributor Author

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.

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;
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function extractAttachmentsFromReport(report, reportActions, source) {
source: tryResolveUrlFromApiRoot(expensifySource || attribs.src),
isAuthTokenRequired: Boolean(expensifySource),
file: {name: attribs[CONST.ATTACHMENT_ORIGINAL_FILENAME_ATTRIBUTE]},
isHidden: attribs['data-hidden'] === 'true',
});
},
});
Expand All @@ -38,7 +39,10 @@ function extractAttachmentsFromReport(report, reportActions, source) {
if (!ReportActionsUtils.shouldReportActionBeVisible(action, key)) {
return;
}
htmlParser.write(_.get(action, ['message', 0, 'html']));
const decision = _.get(action, ['message', 0, 'moderationDecision', 'decision'], '');
const isHidden = decision === CONST.MODERATION.MODERATOR_DECISION_PENDING_HIDE || decision === CONST.MODERATION.MODERATOR_DECISION_HIDDEN;
const html = _.get(action, ['message', 0, 'html'], '').replace('/>', `data-hidden="${isHidden}" />`);
htmlParser.write(html);
});
htmlParser.end();

Expand Down
10 changes: 4 additions & 6 deletions src/components/Attachments/AttachmentCarousel/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import _ from 'underscore';
import * as DeviceCapabilities from '../../../libs/DeviceCapabilities';
import styles from '../../../styles/styles';
import CarouselActions from './CarouselActions';
import AttachmentView from '../AttachmentView';
import withWindowDimensions from '../../withWindowDimensions';
import CarouselButtons from './CarouselButtons';
import extractAttachmentsFromReport from './extractAttachmentsFromReport';
Expand All @@ -15,6 +14,7 @@ import withLocalize from '../../withLocalize';
import compose from '../../../libs/compose';
import useCarouselArrows from './useCarouselArrows';
import useWindowDimensions from '../../../hooks/useWindowDimensions';
import CarouselItem from './CarouselItem';

const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();
const viewabilityConfig = {
Expand Down Expand Up @@ -130,17 +130,15 @@ function AttachmentCarousel({report, reportActions, source, onNavigate}) {
* @param {String} item.source
* @param {Object} item.file
* @param {String} item.file.name
* @param {Boolean} item.isHidden
* @returns {JSX.Element}
*/
const renderItem = useCallback(
({item}) => (
<AttachmentView
source={item.source}
file={item.file}
isAuthTokenRequired={item.isAuthTokenRequired}
<CarouselItem
item={item}
isFocused={activeSource === item.source}
onPress={() => canUseTouchScreen && setShouldShowArrows(!shouldShowArrows)}
isUsedInCarousel
/>
),
[activeSource, setShouldShowArrows, shouldShowArrows],
Expand Down
11 changes: 4 additions & 7 deletions src/components/Attachments/AttachmentCarousel/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import {withOnyx} from 'react-native-onyx';
import AttachmentCarouselPager from './Pager';
import styles from '../../../styles/styles';
import CarouselButtons from './CarouselButtons';
import AttachmentView from '../AttachmentView';
import ONYXKEYS from '../../../ONYXKEYS';
import {propTypes, defaultProps} from './attachmentCarouselPropTypes';
import extractAttachmentsFromReport from './extractAttachmentsFromReport';
import useCarouselArrows from './useCarouselArrows';
import CarouselItem from './CarouselItem';

function AttachmentCarousel({report, reportActions, source, onNavigate, onClose}) {
const {attachments, initialPage, initialActiveSource, initialItem} = useMemo(() => extractAttachmentsFromReport(report, reportActions, source), [report, reportActions, source]);
Expand Down Expand Up @@ -64,17 +64,14 @@ function AttachmentCarousel({report, reportActions, source, onNavigate, onClose}

/**
* Defines how a single attachment should be rendered
* @param {{ isAuthTokenRequired: Boolean, source: String, file: { name: String } }} item
* @param {{ isAuthTokenRequired: Boolean, source: String, file: { name: String }, isHidden: Boolean }} item
* @returns {JSX.Element}
*/
const renderItem = useCallback(
({item}) => (
<AttachmentView
source={item.source}
file={item.file}
isAuthTokenRequired={item.isAuthTokenRequired}
<CarouselItem
item={item}
isFocused={activeSource === item.source}
isUsedInCarousel
onPress={() => setShouldShowArrows(!shouldShowArrows)}
/>
),
Expand Down
Loading