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

fix: badge is not crossed out when deleted offline #43622

Merged
merged 7 commits into from
Jun 21, 2024
21 changes: 21 additions & 0 deletions src/components/CustomStyleProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React, {useMemo} from 'react';
import type {StyleProp, TextStyle, ViewStyle} from 'react-native';

type CustomStyleContextType = StyleProp<ViewStyle & TextStyle> | null;

const CustomStyleContext = React.createContext<CustomStyleContextType>(null);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use another more meaningful name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think CustomStyle is meaningful enough. Maybe CustomStylesForChildren?

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's keep the current name


type CustomStyleProviderProps = React.PropsWithChildren & {
style: StyleProp<ViewStyle & TextStyle> | null;
};

function CustomStyleProvider({children, style}: CustomStyleProviderProps) {
const value = useMemo(() => style, [style]);

return <CustomStyleContext.Provider value={value}>{children}</CustomStyleContext.Provider>;
}

CustomStyleProvider.displayName = 'CustomStyleProvider';

export default CustomStyleProvider;
export {CustomStyleContext};
3 changes: 2 additions & 1 deletion src/components/OfflineWithFeedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import type * as OnyxCommon from '@src/types/onyx/OnyxCommon';
import type {ReceiptError, ReceiptErrors} from '@src/types/onyx/Transaction';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import CustomStyleProvider from './CustomStyleProvider';
import MessagesRow from './MessagesRow';

/**
Expand Down Expand Up @@ -134,7 +135,7 @@ function OfflineWithFeedback({
style={[needsOpacity ? styles.offlineFeedback.pending : {}, contentContainerStyle]}
needsOffscreenAlphaCompositing={shouldRenderOffscreen ? needsOpacity && needsOffscreenAlphaCompositing : undefined}
>
{children}
<CustomStyleProvider style={needsStrikeThrough ? [styles.offlineFeedback.deleted, styles.userSelectNone] : null}>{children}</CustomStyleProvider>
</View>
)}
{shouldShowErrorMessages && hasErrorMessages && (
Expand Down
5 changes: 4 additions & 1 deletion src/components/Text.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {ForwardedRef} from 'react';
import React from 'react';
import React, {useContext} from 'react';
// eslint-disable-next-line no-restricted-imports
import {Text as RNText, StyleSheet} from 'react-native';
import type {TextProps as RNTextProps, TextStyle} from 'react-native';
Expand All @@ -8,6 +8,7 @@ import type {FontUtilsType} from '@styles/utils/FontUtils';
import FontUtils from '@styles/utils/FontUtils';
import variables from '@styles/variables';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {CustomStyleContext} from './CustomStyleProvider';

type TextProps = RNTextProps &
ChildrenProps & {
Expand All @@ -29,13 +30,15 @@ type TextProps = RNTextProps &

function Text({color, fontSize = variables.fontSizeNormal, textAlign = 'left', children, family = 'EXP_NEUE', style = {}, ...props}: TextProps, ref: ForwardedRef<RNText>) {
const theme = useTheme();
const customStyle = useContext(CustomStyleContext);

const componentStyle: TextStyle = {
color: color ?? theme.text,
fontSize,
textAlign,
fontFamily: FontUtils.fontFamily.platform[family],
...StyleSheet.flatten(style),
...StyleSheet.flatten(customStyle),
};

if (!componentStyle.lineHeight && componentStyle.fontSize === variables.fontSizeNormal) {
Expand Down
Loading