Skip to content

Commit

Permalink
feat(text-props): ✨ added pass props to two text
Browse files Browse the repository at this point in the history
user can pass native props to texts
  • Loading branch information
BLOCKMATERIAL committed Oct 31, 2023
1 parent f6084a7 commit 4633066
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/component/truncated_text_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ if (
}

export const TruncatedTextView = (props: TruncatedTextViewProps) => {
const { style, tailTextStyle, containerStyle } = props;
const {
style,
tailTextStyle,
containerStyle,
textPropsRoot,
textPropsChild,
} = props;
const {
text: fullText,
lineHeight = DEFAULT_LINE_HEIGHT,
Expand Down Expand Up @@ -129,6 +135,7 @@ export const TruncatedTextView = (props: TruncatedTextViewProps) => {
style={[style, { lineHeight }]}
numberOfLines={isExpanded ? 0 : numberOfLines}
onTextLayout={_handleTextLayout}
{...textPropsRoot}
>
{fullText}
{_shouldShowTailView && '\n'}
Expand All @@ -149,6 +156,7 @@ export const TruncatedTextView = (props: TruncatedTextViewProps) => {
<Text
style={[styles.tailText, tailTextStyle, { lineHeight }]}
onPress={_handlePress}
{...textPropsChild}
>
{isExpanded ? expandedText : collapsedText}
</Text>
Expand Down
12 changes: 11 additions & 1 deletion src/types/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { StyleProp, TextStyle, ViewStyle } from 'react-native';
import type { StyleProp, TextStyle, TextProps, ViewStyle } from 'react-native';

export type TruncatedTextViewProps = {
/**
Expand Down Expand Up @@ -60,4 +60,14 @@ export type TruncatedTextViewProps = {
* Whether to enable layout animation, default value is true
*/
enableLayoutAnimation?: boolean;

/**
* Apply text props to root text
*/
textPropsRoot?: TextProps;

/**
* Apply text props to child text
*/
textPropsChild?: TextProps;
};

0 comments on commit 4633066

Please sign in to comment.