Skip to content

Commit

Permalink
refactor: store wrapper in component
Browse files Browse the repository at this point in the history
  • Loading branch information
BeeMargarida committed May 23, 2023
1 parent c07527c commit 4678f93
Showing 1 changed file with 36 additions and 45 deletions.
81 changes: 36 additions & 45 deletions src/components/PressableWithDelayToggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,57 +77,48 @@ function PressableWithDelayToggle(props) {
props.onPress();
};

const children = (
<Tooltip
containerStyles={styles.flexRow}
text={props.isDelayButtonStateComplete ? props.tooltipTextChecked : props.tooltipText}
>
<Text
suppressHighlighting
style={[...props.textStyles, styles.mr1]}
>
{props.isDelayButtonStateComplete && props.textChecked ? props.textChecked : props.text}
</Text>
<Pressable
ref={props.innerRef}
focusable
accessibilityLabel={props.isDelayButtonStateComplete ? props.tooltipTextChecked : props.tooltipText}
onPress={updatePressState}
>
{({hovered, pressed}) => (
<>
{props.icon && (
<Icon
src={props.isDelayButtonStateComplete ? props.iconChecked : props.icon}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed, props.isDelayButtonStateComplete))}
style={props.iconStyles}
width={variables.iconSizeSmall}
height={variables.iconSizeSmall}
/>
)}
</>
)}
</Pressable>
</Tooltip>
);

// Due to limitations in RN regarding the vertical text alignment of non-Text elements,
// for elements that are supposed to be inline, we need to use a Text element instead
// of a Pressable
return props.inline ? (
<Text
style={[...props.styles, styles.flexRow]}
onPress={updatePressState}
>
{children}
</Text>
) : (
<Pressable
const PressableView = props.inline ? Text : Pressable;

return (
<PressableView
style={[...props.styles, styles.flexRow]}
onPress={updatePressState}
>
{children}
</Pressable>
<Tooltip
containerStyles={styles.flexRow}
text={props.isDelayButtonStateComplete ? props.tooltipTextChecked : props.tooltipText}
>
<Text
suppressHighlighting
style={[...props.textStyles, styles.mr1]}
>
{props.isDelayButtonStateComplete && props.textChecked ? props.textChecked : props.text}
</Text>
<Pressable
ref={props.innerRef}
focusable
accessibilityLabel={props.isDelayButtonStateComplete ? props.tooltipTextChecked : props.tooltipText}
onPress={updatePressState}
>
{({hovered, pressed}) => (
<>
{props.icon && (
<Icon
src={props.isDelayButtonStateComplete ? props.iconChecked : props.icon}
fill={StyleUtils.getIconFillColor(getButtonState(hovered, pressed, props.isDelayButtonStateComplete))}
style={props.iconStyles}
width={variables.iconSizeSmall}
height={variables.iconSizeSmall}
/>
)}
</>
)}
</Pressable>
</Tooltip>
</PressableView>
);
}

Expand Down

0 comments on commit 4678f93

Please sign in to comment.