-
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 #42801 from ShridharGoel/magic-lhn
Align inline icons with text in Android LHN
- Loading branch information
Showing
2 changed files
with
84 additions
and
29 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 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,39 @@ | ||
/** | ||
* TextBlock component splits a given text into individual words and displays | ||
* each word within a Text component. | ||
*/ | ||
import React, {memo, useMemo} from 'react'; | ||
import type {StyleProp, TextStyle} from 'react-native'; | ||
import Text from './Text'; | ||
|
||
type TextBlockProps = { | ||
/** The color of the text */ | ||
color?: string; | ||
|
||
/** Styles to apply to each text word */ | ||
textStyles?: StyleProp<TextStyle>; | ||
|
||
/** The full text to be split into words */ | ||
text: string; | ||
}; | ||
|
||
function TextBlock({color, textStyles, text}: TextBlockProps) { | ||
const words = useMemo(() => text.match(/(\S+\s*)/g) ?? [], [text]); | ||
|
||
return ( | ||
<> | ||
{words.map((word) => ( | ||
<Text | ||
color={color} | ||
style={textStyles} | ||
> | ||
{word} | ||
</Text> | ||
))} | ||
</> | ||
); | ||
} | ||
|
||
TextBlock.displayName = 'TextBlock'; | ||
|
||
export default memo(TextBlock); |