Skip to content

Commit

Permalink
Merge pull request #43622 from tienifr/fix/42673
Browse files Browse the repository at this point in the history
fix: badge is not crossed out when deleted offline
  • Loading branch information
youssef-lr authored Jun 21, 2024
2 parents 221117c + d98c013 commit 9b0c53c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
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

0 comments on commit 9b0c53c

Please sign in to comment.