-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28008 from software-mansion-labs/ts-migration/Com…
…poserUtils [TS migration] Migrate 'ComposerUtils' lib to TypeScript
- Loading branch information
Showing
15 changed files
with
63 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import debounce from 'lodash/debounce'; | ||
import * as Report from '../actions/Report'; | ||
|
||
/** | ||
* Save draft report comment. Debounced to happen at most once per second. | ||
*/ | ||
const debouncedSaveReportComment = debounce((reportID: string, comment = '') => { | ||
Report.saveReportComment(reportID, comment); | ||
}, 1000); | ||
|
||
export default debouncedSaveReportComment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import GetNumberOfLines from './types'; | ||
|
||
/** | ||
* Get the current number of lines in the composer | ||
*/ | ||
const getNumberOfLines: GetNumberOfLines = (lineHeight, paddingTopAndBottom, scrollHeight) => Math.ceil((scrollHeight - paddingTopAndBottom) / lineHeight); | ||
|
||
export default getNumberOfLines; |
13 changes: 4 additions & 9 deletions
13
...s/ComposerUtils/getNumberOfLines/index.js → ...s/ComposerUtils/getNumberOfLines/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,12 @@ | ||
import GetNumberOfLines from './types'; | ||
|
||
/** | ||
* Get the current number of lines in the composer | ||
* | ||
* @param {Number} maxLines | ||
* @param {Number} lineHeight | ||
* @param {Number} paddingTopAndBottom | ||
* @param {Number} scrollHeight | ||
* | ||
* @returns {Number} | ||
*/ | ||
function getNumberOfLines(maxLines, lineHeight, paddingTopAndBottom, scrollHeight) { | ||
const getNumberOfLines: GetNumberOfLines = (lineHeight, paddingTopAndBottom, scrollHeight, maxLines = 0) => { | ||
let newNumberOfLines = Math.ceil((scrollHeight - paddingTopAndBottom) / lineHeight); | ||
newNumberOfLines = maxLines <= 0 ? newNumberOfLines : Math.min(newNumberOfLines, maxLines); | ||
return newNumberOfLines; | ||
} | ||
}; | ||
|
||
export default getNumberOfLines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type GetNumberOfLines = (lineHeight: number, paddingTopAndBottom: number, scrollHeight: number, maxLines?: number) => number; | ||
|
||
export default GetNumberOfLines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
type ComposerProps = { | ||
isFullComposerAvailable: boolean; | ||
setIsFullComposerAvailable: (isFullComposerAvailable: boolean) => void; | ||
}; | ||
|
||
export default ComposerProps; |
6 changes: 3 additions & 3 deletions
6
...serUtils/updateIsFullComposerAvailable.js → ...serUtils/updateIsFullComposerAvailable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
10 changes: 4 additions & 6 deletions
10
...Utils/updateNumberOfLines/index.native.js → ...Utils/updateNumberOfLines/index.native.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,21 @@ | ||
import lodashGet from 'lodash/get'; | ||
import styles from '../../../styles/styles'; | ||
import updateIsFullComposerAvailable from '../updateIsFullComposerAvailable'; | ||
import getNumberOfLines from '../getNumberOfLines'; | ||
import UpdateNumberOfLines from './types'; | ||
|
||
/** | ||
* Check the current scrollHeight of the textarea (minus any padding) and | ||
* divide by line height to get the total number of rows for the textarea. | ||
* @param {Object} props | ||
* @param {Event} e | ||
*/ | ||
function updateNumberOfLines(props, e) { | ||
const updateNumberOfLines: UpdateNumberOfLines = (props, event) => { | ||
const lineHeight = styles.textInputCompose.lineHeight; | ||
const paddingTopAndBottom = styles.textInputComposeSpacing.paddingVertical * 2; | ||
const inputHeight = lodashGet(e, 'nativeEvent.contentSize.height', null); | ||
const inputHeight = event?.nativeEvent?.contentSize?.height ?? null; | ||
if (!inputHeight) { | ||
return; | ||
} | ||
const numberOfLines = getNumberOfLines(lineHeight, paddingTopAndBottom, inputHeight); | ||
updateIsFullComposerAvailable(props, numberOfLines); | ||
} | ||
}; | ||
|
||
export default updateNumberOfLines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import UpdateNumberOfLines from './types'; | ||
|
||
const updateNumberOfLines: UpdateNumberOfLines = () => {}; | ||
|
||
export default updateNumberOfLines; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import {NativeSyntheticEvent, TextInputContentSizeChangeEventData} from 'react-native'; | ||
import ComposerProps from '../types'; | ||
|
||
type UpdateNumberOfLines = (props: ComposerProps, event: NativeSyntheticEvent<TextInputContentSizeChangeEventData>) => void; | ||
|
||
export default UpdateNumberOfLines; |