Skip to content

Commit

Permalink
feat: gap between the tailView and main content, a callbeck on expand…
Browse files Browse the repository at this point in the history
…ed status changed
  • Loading branch information
Lohen Yumnam authored and Lohen Yumnam committed Dec 11, 2023
1 parent 0959120 commit c98d42f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/component/truncated_text_view.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback, useMemo } from 'react';
import React, { useCallback, useEffect, useMemo } from 'react';
import {
LayoutAnimation,
NativeSyntheticEvent,
Expand Down Expand Up @@ -33,6 +33,8 @@ export const TruncatedTextView = (props: TruncatedTextViewProps) => {
containerStyle,
textPropsRoot,
textPropsChild,
numberOfLineGapOnExpanded = 1,
onChangeExpandedStatus,
} = props;
const {
text: fullText,
Expand Down Expand Up @@ -116,6 +118,10 @@ export const TruncatedTextView = (props: TruncatedTextViewProps) => {
numberOfLines,
]);

useEffect(() => {
onChangeExpandedStatus?.(isExpanded);
}, [isExpanded, onChangeExpandedStatus]);

// this will hide the text view if the text is empty
if (!fullText) return <View />;

Expand All @@ -140,7 +146,9 @@ export const TruncatedTextView = (props: TruncatedTextViewProps) => {
{...textPropsRoot}
>
{fullText}
{_shouldShowTailView && '\n'}
{_shouldShowTailView &&
'\n'.repeat(numberOfLineGapOnExpanded) +
`${numberOfLineGapOnExpanded === 1 ? '‎ ' : ''}`}
</Text>

{_shouldShowTailView && (
Expand All @@ -153,6 +161,9 @@ export const TruncatedTextView = (props: TruncatedTextViewProps) => {
{
left: seeMorePosition,
},
isExpanded &&
numberOfLineGapOnExpanded === 1 &&
styles.expandedTailTextContainer,
]}
>
<Text
Expand All @@ -178,10 +189,15 @@ const styles = StyleSheet.create({
bottom: 0,
},
container: {
backgroundColor: 'white',
// backgroundColor: 'white',
backgroundColor: 'lightblue',

This comment has been minimized.

Copy link
@younes0

younes0 Jan 10, 2024

Contributor

@lohenyumnam why setting backgroundColor ?

},
tailText: {
color: 'black',
fontWeight: 'bold',
},

expandedTailTextContainer: {
margin: -4,
},
});
11 changes: 11 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,15 @@ export type TruncatedTextViewProps = {
* Apply text props to child text
*/
textPropsChild?: TextProps;

/**
* Number of Line Gap between the Tail Text and the main content
* @default is 1
*/
numberOfLineGapOnExpanded?: number;

/**
* Called when expanded status changed
*/
onChangeExpandedStatus?: (isExpanded: boolean) => void;
};

0 comments on commit c98d42f

Please sign in to comment.