Skip to content

Commit

Permalink
Merge branch 'main' into @chrispader/restructure-styles-and-theme-swi…
Browse files Browse the repository at this point in the history
…tching
  • Loading branch information
Christoph Pader committed Dec 13, 2023
2 parents 541ee35 + 904cf56 commit d76eaef
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 11 deletions.
20 changes: 13 additions & 7 deletions desktop/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dependencies": {
"electron-context-menu": "^2.3.0",
"electron-log": "^4.4.7",
"electron-serve": "^1.0.0",
"electron-serve": "^1.2.0",
"electron-updater": "^6.1.6",
"node-machine-id": "^1.1.12"
},
Expand Down
1 change: 1 addition & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ const CONST = {
BETA_COMMENT_LINKING: 'commentLinking',
POLICY_ROOMS: 'policyRooms',
VIOLATIONS: 'violations',
REPORT_FIELDS: 'reportFields',
},
BUTTON_STATES: {
DEFAULT: 'default',
Expand Down
21 changes: 18 additions & 3 deletions src/components/Composer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import RNTextInput from '@components/RNTextInput';
import Text from '@components/Text';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import withNavigation from '@components/withNavigation';
import useIsScrollBarVisible from '@hooks/useIsScrollBarVisible';
import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -86,6 +87,9 @@ const propTypes = {
/** Whether the sull composer is open */
isComposerFullSize: PropTypes.bool,

/** Should make the input only scroll inside the element avoid scroll out to parent */
shouldContainScroll: PropTypes.bool,

...withLocalizePropTypes,
};

Expand Down Expand Up @@ -113,6 +117,7 @@ const defaultProps = {
checkComposerVisibility: () => false,
isReportActionCompose: false,
isComposerFullSize: false,
shouldContainScroll: false,
};

/**
Expand Down Expand Up @@ -164,6 +169,7 @@ function Composer({
selection: selectionProp,
isReportActionCompose,
isComposerFullSize,
shouldContainScroll,
...props
}) {
const theme = useTheme();
Expand All @@ -180,6 +186,7 @@ function Composer({
const [caretContent, setCaretContent] = useState('');
const [valueBeforeCaret, setValueBeforeCaret] = useState('');
const [textInputWidth, setTextInputWidth] = useState('');
const isScrollBarVisible = useIsScrollBarVisible(textInput, value);

useEffect(() => {
if (!shouldClear) {
Expand Down Expand Up @@ -418,18 +425,26 @@ function Composer({
</View>
);

const inputStyleMemo = useMemo(
() => [
const scrollStyleMemo = useMemo(() => {
if (shouldContainScroll) {
return isScrollBarVisible ? [styles.overflowScroll, styles.overscrollBehaviorContain] : styles.overflowHidden;
}
return [
// We are hiding the scrollbar to prevent it from reducing the text input width,
// so we can get the correct scroll height while calculating the number of lines.
numberOfLines < maxLines ? styles.overflowHidden : {},
];
}, [shouldContainScroll, isScrollBarVisible, maxLines, numberOfLines, styles.overflowHidden, styles.overflowScroll, styles.overscrollBehaviorContain]);

const inputStyleMemo = useMemo(
() => [
StyleSheet.flatten([style, {outline: 'none'}]),
StyleUtils.getComposeTextAreaPadding(numberOfLines, isComposerFullSize),
Browser.isMobileSafari() || Browser.isSafari() ? styles.rtlTextRenderForSafari : {},
scrollStyleMemo,
],

[numberOfLines, maxLines, styles.overflowHidden, styles.rtlTextRenderForSafari, style, StyleUtils, isComposerFullSize],
[numberOfLines, scrollStyleMemo, styles.rtlTextRenderForSafari, style, StyleUtils, isComposerFullSize],
);

return (
Expand Down
7 changes: 7 additions & 0 deletions src/hooks/useIsScrollBarVisible/index.native.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Native doesn't have the DOM, so we just return null.
*
*/
const useIsScrollBarVisible = () => null;

export default useIsScrollBarVisible;
28 changes: 28 additions & 0 deletions src/hooks/useIsScrollBarVisible/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {useCallback, useEffect, useState} from 'react';

const useIsScrollBarVisible = (ref: React.RefObject<HTMLDivElement | HTMLTextAreaElement>, value: string) => {
const [isScrollBarVisible, setIsScrollBarVisible] = useState(false);

const handleResize = useCallback(() => {
if (!ref.current) {
return;
}
const {scrollHeight, clientHeight} = ref.current;
setIsScrollBarVisible(scrollHeight > clientHeight);
}, [ref]);

useEffect(() => {
if (!ref.current || !('ResizeObserver' in (window || {}))) {
return;
}

const resizeObserver = new ResizeObserver(handleResize);
resizeObserver.observe(ref.current);
return () => {
resizeObserver.disconnect();
};
}, [handleResize, ref, value]);
return isScrollBarVisible;
};

export default useIsScrollBarVisible;
5 changes: 5 additions & 0 deletions src/libs/Permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ function canUseCommentLinking(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.BETA_COMMENT_LINKING) || canUseAllBetas(betas);
}

function canUseReportFields(betas: OnyxEntry<Beta[]>): boolean {
return !!betas?.includes(CONST.BETAS.REPORT_FIELDS) || canUseAllBetas(betas);
}

/**
* We're requiring you to be added to the policy rooms beta on dev,
* since contributors have been reporting a number of false issues related to the feature being under development.
Expand Down Expand Up @@ -45,4 +49,5 @@ export default {
canUsePolicyRooms,
canUseLinkPreviews,
canUseViolations,
canUseReportFields,
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import useStyleUtils from '@hooks/useStyleUtils';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import * as Browser from '@libs/Browser';
import canFocusInputOnScreenFocus from '@libs/canFocusInputOnScreenFocus';
import compose from '@libs/compose';
import * as ComposerUtils from '@libs/ComposerUtils';
Expand Down Expand Up @@ -561,6 +562,7 @@ function ComposerWithSuggestions({
setComposerHeight(composerLayoutHeight);
}}
onScroll={hideSuggestionMenu}
shouldContainScroll={Browser.isMobileSafari()}
/>
</View>

Expand Down

0 comments on commit d76eaef

Please sign in to comment.