Skip to content

Commit

Permalink
Merge pull request #43270 from software-mansion-labs/@szymczak/stop-h…
Browse files Browse the repository at this point in the history
…ighligting-mention-rooms

Stop highlighting report mentions in non policy rooms in the Composer
  • Loading branch information
rlinoz authored Jun 10, 2024
2 parents b52a303 + 0c8ed5f commit d8d528d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/components/Composer/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function Composer(
// On Android the selection prop is required on the TextInput but this prop has issues on IOS
selection,
value,
isGroupPolicyReport = false,
...props
}: ComposerProps,
ref: ForwardedRef<TextInput>,
Expand All @@ -36,7 +37,7 @@ function Composer(
const {isFocused, shouldResetFocus} = useResetComposerFocus(textInput);
const textContainsOnlyEmojis = useMemo(() => EmojiUtils.containsOnlyEmojis(value ?? ''), [value]);
const theme = useTheme();
const markdownStyle = useMarkdownStyle(value);
const markdownStyle = useMarkdownStyle(value, !isGroupPolicyReport ? ['mentionReport'] : []);
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

Expand Down
3 changes: 2 additions & 1 deletion src/components/Composer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,15 @@ function Composer(
isReportActionCompose = false,
isComposerFullSize = false,
shouldContainScroll = false,
isGroupPolicyReport = false,
...props
}: ComposerProps,
ref: ForwardedRef<TextInput | HTMLInputElement>,
) {
const textContainsOnlyEmojis = useMemo(() => EmojiUtils.containsOnlyEmojis(value ?? ''), [value]);
const theme = useTheme();
const styles = useThemeStyles();
const markdownStyle = useMarkdownStyle(value);
const markdownStyle = useMarkdownStyle(value, !isGroupPolicyReport ? ['mentionReport'] : []);
const StyleUtils = useStyleUtils();
const textRef = useRef<HTMLElement & RNText>(null);
const textInput = useRef<AnimatedMarkdownTextInputRef | null>(null);
Expand Down
3 changes: 3 additions & 0 deletions src/components/Composer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type ComposerProps = TextInputProps & {

/** Should make the input only scroll inside the element avoid scroll out to parent */
shouldContainScroll?: boolean;

/** Indicates whether the composer is in a group policy report. Used for disabling report mentioning style in markdown input */
isGroupPolicyReport?: boolean;
};

export type {TextSelection, ComposerProps};
35 changes: 30 additions & 5 deletions src/hooks/useMarkdownStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,25 @@ import FontUtils from '@styles/utils/FontUtils';
import variables from '@styles/variables';
import useTheme from './useTheme';

function useMarkdownStyle(message: string | null = null): MarkdownStyle {
function useMarkdownStyle(message: string | null = null, excludeStyles: Array<keyof MarkdownStyle> = []): MarkdownStyle {
const theme = useTheme();
const emojiFontSize = containsOnlyEmojis(message ?? '') ? variables.fontSizeOnlyEmojis : variables.fontSizeNormal;

const markdownStyle = useMemo(
// this map is used to reset the styles that are not needed - passing undefined value can break the native side
const nonStylingDefaultValues: Record<string, string | number> = useMemo(
() => ({
color: theme.text,
backgroundColor: 'transparent',
marginLeft: 0,
paddingLeft: 0,
borderColor: 'transparent',
borderWidth: 0,
}),
[theme],
);

const markdownStyle = useMemo(() => {
const styling = {
syntax: {
color: theme.syntax,
},
Expand Down Expand Up @@ -59,9 +72,21 @@ function useMarkdownStyle(message: string | null = null): MarkdownStyle {
color: theme.mentionText,
backgroundColor: theme.mentionBG,
},
}),
[theme, emojiFontSize],
);
};

if (excludeStyles.length) {
excludeStyles.forEach((key) => {
const style: Record<string, unknown> = styling[key];
if (style) {
Object.keys(style).forEach((styleKey) => {
style[styleKey] = nonStylingDefaultValues[styleKey] ?? style[styleKey];
});
}
});
}

return styling;
}, [theme, emojiFontSize, excludeStyles, nonStylingDefaultValues]);

return markdownStyle;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,6 +775,7 @@ function ComposerWithSuggestions(
onLayout={onLayout}
onScroll={hideSuggestionMenu}
shouldContainScroll={Browser.isMobileSafari()}
isGroupPolicyReport={isGroupPolicyReport}
/>
</View>

Expand Down

0 comments on commit d8d528d

Please sign in to comment.