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/CustomStylesForChildrenProvider.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 CustomStylesForChildrenContextType = StyleProp<ViewStyle & TextStyle> | null;

const CustomStylesForChildrenContext = React.createContext<CustomStylesForChildrenContextType>(null);

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

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

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

CustomStylesForChildrenProvider.displayName = 'CustomStylesForChildrenProvider';

export default CustomStylesForChildrenProvider;
export {CustomStylesForChildrenContext};
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 CustomStylesForChildrenProvider from './CustomStylesForChildrenProvider';
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}
<CustomStylesForChildrenProvider style={needsStrikeThrough ? [styles.offlineFeedback.deleted, styles.userSelectNone] : null}>{children}</CustomStylesForChildrenProvider>
</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 {CustomStylesForChildrenContext} from './CustomStylesForChildrenProvider';

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(CustomStylesForChildrenContext);

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