Skip to content

Commit

Permalink
[C-5153] Update ComposerInput to not render the display layer unless …
Browse files Browse the repository at this point in the history
…there is highlighted text (#10042)
  • Loading branch information
Kyle-Shanks authored Oct 14, 2024
1 parent e5d827b commit 7d7008c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 16 deletions.
37 changes: 23 additions & 14 deletions packages/mobile/src/components/composer-input/ComposerInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ const useStyles = makeStyles(({ spacing, palette, typography }) => ({
lineHeight: spacing(6),
justifyContent: 'center',
alignItems: 'center',
paddingTop: 0,
paddingTop: 0
},
hideText: {
color: 'transparent'
},
overlayTextContainer: {
Expand Down Expand Up @@ -394,6 +396,14 @@ export const ComposerInput = forwardRef(function ComposerInput(
</TouchableOpacity>
)

const isTextHighlighted = useMemo(() => {
const matches = getMatches(value) ?? []
const timestamps = getTimestamps(value)
const mentions = getUserMentions(value) ?? []
const fullMatches = [...matches, ...mentions, ...timestamps]
return Boolean(fullMatches.length || isAutocompleteActive)
}, [getMatches, getTimestamps, getUserMentions, isAutocompleteActive, value])

const renderDisplayText = useCallback(
(value: string) => {
const matches = getMatches(value) ?? []
Expand Down Expand Up @@ -485,10 +495,8 @@ export const ComposerInput = forwardRef(function ComposerInput(
root: [styles.composeTextContainer, propStyles?.container],
input: [
styles.composeTextInput,
Platform.OS === 'ios' ? { paddingBottom: spacing(1.5) } : null
// {
// maxHeight: hasCurrentlyPlayingTrack ? spacing(70) : spacing(80)
// }
Platform.OS === 'ios' ? { paddingBottom: spacing(1.5) } : null,
isTextHighlighted ? styles.hideText : null
]
}}
onChangeText={handleChange}
Expand All @@ -501,15 +509,16 @@ export const ComposerInput = forwardRef(function ComposerInput(
autoCorrect
TextInputComponent={TextInputComponent}
/>
<View
style={[
styles.overlayTextContainer,
Platform.OS === 'ios' ? { paddingBottom: spacing(1.5) } : null
// { maxHeight: hasCurrentlyPlayingTrack ? spacing(70) : spacing(80) }
]}
>
<Text style={styles.overlayText}>{renderDisplayText(value)}</Text>
</View>
{isTextHighlighted ? (
<View
style={[
styles.overlayTextContainer,
Platform.OS === 'ios' ? { paddingBottom: spacing(1.5) } : null
]}
>
<Text style={styles.overlayText}>{renderDisplayText(value)}</Text>
</View>
) : null}
</>
)
})
25 changes: 23 additions & 2 deletions packages/web/src/components/composer-input/ComposerInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { ChangeEvent, useCallback, useEffect, useRef, useState } from 'react'
import {
ChangeEvent,
useCallback,
useEffect,
useMemo,
useRef,
useState
} from 'react'

import {
useGetCurrentUserId,
Expand Down Expand Up @@ -351,6 +358,20 @@ export const ComposerInput = (props: ComposerInputProps) => {
]
)

const isTextHighlighted = useMemo(() => {
const matches = getMatches(value) ?? []
const timestamps = getTimestamps(value)
const mentions = getUserMentions(value) ?? []
const fullMatches = [...matches, ...mentions, ...timestamps]
return Boolean(fullMatches.length || isUserAutocompleteActive)
}, [
getMatches,
getTimestamps,
getUserMentions,
isUserAutocompleteActive,
value
])

const renderDisplayText = useCallback(
(value: string) => {
const matches = getMatches(value) ?? []
Expand Down Expand Up @@ -471,7 +492,7 @@ export const ComposerInput = (props: ComposerInputProps) => {
showMaxLength={
!!value && value.length > maxLength * MAX_LENGTH_DISPLAY_PERCENT
}
renderDisplayElement={renderDisplayText}
renderDisplayElement={isTextHighlighted ? renderDisplayText : undefined}
grows
{...other}
>
Expand Down

0 comments on commit 7d7008c

Please sign in to comment.