Skip to content

Commit

Permalink
Merge pull request #27850 from bernhardoj/fix/27396-stacked-avatar-tr…
Browse files Browse the repository at this point in the history
…ansparent

Fix stacked avatar is transparent when long press on Android
  • Loading branch information
MonilBhavsar authored Sep 27, 2023
2 parents 3f337e8 + b9f80f6 commit fff2dd4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/LHNOptionsList/OptionRowLHN.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ function OptionRowLHN(props) {
]}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
accessibilityLabel={translate('accessibilityHints.navigatesToChat')}
needsOffscreenAlphaCompositing={props.optionItem.icons.length >= 2}
>
<View style={sidebarInnerRowStyle}>
<View style={[styles.flexRow, styles.alignItemsCenter]}>
Expand Down
14 changes: 13 additions & 1 deletion src/components/OpacityView.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Animated, {useAnimatedStyle, useSharedValue, withTiming} from 'react-nati
import PropTypes from 'prop-types';
import variables from '../styles/variables';
import * as StyleUtils from '../styles/StyleUtils';
import shouldRenderOffscreen from '../libs/shouldRenderOffscreen';

const propTypes = {
/**
Expand All @@ -27,11 +28,15 @@ const propTypes = {
* @default 0.5
*/
dimmingValue: PropTypes.number,

/** Whether the view needs to be rendered offscreen (for Android only) */
needsOffscreenAlphaCompositing: PropTypes.bool,
};

const defaultProps = {
style: [],
dimmingValue: variables.hoverDimValue,
needsOffscreenAlphaCompositing: false,
};

function OpacityView(props) {
Expand All @@ -48,7 +53,14 @@ function OpacityView(props) {
}
}, [props.shouldDim, props.dimmingValue, opacity]);

return <Animated.View style={[opacityStyle, ...StyleUtils.parseStyleAsArray(props.style)]}>{props.children}</Animated.View>;
return (
<Animated.View
style={[opacityStyle, ...StyleUtils.parseStyleAsArray(props.style)]}
needsOffscreenAlphaCompositing={shouldRenderOffscreen ? props.needsOffscreenAlphaCompositing : undefined}
>
{props.children}
</Animated.View>
);
}

OpacityView.displayName = 'OpacityView';
Expand Down
1 change: 1 addition & 0 deletions src/components/OptionRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ class OptionRow extends Component {
accessibilityRole={CONST.ACCESSIBILITY_ROLE.BUTTON}
hoverDimmingValue={1}
hoverStyle={this.props.hoverStyle}
needsOffscreenAlphaCompositing={this.props.option.icons.length >= 2}
>
<View style={sidebarInnerRowStyle}>
<View style={[styles.flexRow, styles.alignItemsCenter]}>
Expand Down
11 changes: 8 additions & 3 deletions src/components/Pressable/PressableWithFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import OpacityView from '../OpacityView';
import variables from '../../styles/variables';
import useSingleExecution from '../../hooks/useSingleExecution';

const omittedProps = ['wrapperStyle'];
const omittedProps = ['wrapperStyle', 'needsOffscreenAlphaCompositing'];

const PressableWithFeedbackPropTypes = {
...GenericPressablePropTypes.pressablePropTypes,
Expand All @@ -27,6 +27,9 @@ const PressableWithFeedbackPropTypes = {
* Used to locate this view from native classes.
*/
nativeID: propTypes.string,

/** Whether the view needs to be rendered offscreen (for Android only) */
needsOffscreenAlphaCompositing: propTypes.bool,
};

const PressableWithFeedbackDefaultProps = {
Expand All @@ -35,10 +38,11 @@ const PressableWithFeedbackDefaultProps = {
hoverDimmingValue: variables.hoverDimValue,
nativeID: '',
wrapperStyle: [],
needsOffscreenAlphaCompositing: false,
};

const PressableWithFeedback = forwardRef((props, ref) => {
const propsWithoutWrapperStyles = _.omit(props, omittedProps);
const propsWithoutWrapperProps = _.omit(props, omittedProps);
const {isExecuting, singleExecution} = useSingleExecution();
const [isPressed, setIsPressed] = useState(false);
const [isHovered, setIsHovered] = useState(false);
Expand All @@ -49,11 +53,12 @@ const PressableWithFeedback = forwardRef((props, ref) => {
shouldDim={Boolean(!isDisabled && (isPressed || isHovered))}
dimmingValue={isPressed ? props.pressDimmingValue : props.hoverDimmingValue}
style={props.wrapperStyle}
needsOffscreenAlphaCompositing={props.needsOffscreenAlphaCompositing}
>
<GenericPressable
ref={ref}
// eslint-disable-next-line react/jsx-props-no-spreading
{...propsWithoutWrapperStyles}
{...propsWithoutWrapperProps}
disabled={isDisabled}
isExecuting={isExecuting}
onHoverIn={() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const propTypes = {

/** Used to apply styles to the Pressable */
style: stylePropTypes,

/** Whether the view needs to be rendered offscreen (for Android only) */
needsOffscreenAlphaCompositing: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -59,6 +62,7 @@ const defaultProps = {
withoutFocusOnSecondaryInteraction: false,
activeOpacity: 1,
enableLongPressWithHover: false,
needsOffscreenAlphaCompositing: false,
};

export {propTypes, defaultProps};

0 comments on commit fff2dd4

Please sign in to comment.