From 7652068e14dbd201cf7d75238d6dc94f91b92242 Mon Sep 17 00:00:00 2001 From: Lohen Date: Sat, 18 Mar 2023 13:08:00 +0530 Subject: [PATCH] feat: enableTailView option, by default its set to true, --- example/src/App.tsx | 11 +++++++++++ src/component/truncated_text_view.tsx | 10 +++++++++- src/types/types.ts | 5 +++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/example/src/App.tsx b/example/src/App.tsx index f79f03e..cea3c70 100644 --- a/example/src/App.tsx +++ b/example/src/App.tsx @@ -46,6 +46,17 @@ export default function App() { containerStyle={styles.textContainer} enableOnPressToggle={false} /> + + diff --git a/src/component/truncated_text_view.tsx b/src/component/truncated_text_view.tsx index 9d5d015..9206944 100644 --- a/src/component/truncated_text_view.tsx +++ b/src/component/truncated_text_view.tsx @@ -35,6 +35,7 @@ export const TruncatedTextView = (props: TruncatedTextViewProps) => { enableLayoutAnimation = true, collapsedText = '.. See more', expandedText = '.. See Less', + enableTailView = true, } = props; const { @@ -92,13 +93,20 @@ export const TruncatedTextView = (props: TruncatedTextViewProps) => { }, [_numberOfLine, enableShowLess, isExpanded, numberOfLines]); const _shouldShowTailView = useMemo(() => { + if (!enableTailView) return false; + if (numberOfLines === 0) return false; return Platform.select({ ios: _shouldShowTailViewIOS, android: _shouldShowTailViewAndroid, }); - }, [_shouldShowTailViewAndroid, _shouldShowTailViewIOS, numberOfLines]); + }, [ + _shouldShowTailViewAndroid, + _shouldShowTailViewIOS, + enableTailView, + numberOfLines, + ]); // this will hide the text view if the text is empty if (!fullText) return ; diff --git a/src/types/types.ts b/src/types/types.ts index a857ada..ba2f9ad 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -36,6 +36,11 @@ export type TruncatedTextViewProps = { */ enableShowLess?: boolean; + /** + * Whether to enable the See more & show less functionality, default value is true + */ + enableTailView?: boolean; + /** * The tail text to be displayed when collapsed, default value is ".. See more" */