-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Júlíus Guðni
committed
Jun 14, 2022
1 parent
8411a39
commit c8b5331
Showing
1 changed file
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import { StyleSheet, Text, View } from 'react-native'; | ||
|
||
export type Props = { | ||
lines?: number; | ||
footerStyle?: any; | ||
readMoreText: string; | ||
readLessText: string; | ||
children?: React.ReactNode; | ||
style: any; | ||
}; | ||
|
||
const SimpleReadMore: React.FC<Props> = ({ | ||
lines, | ||
footerStyle, | ||
readMoreText, | ||
readLessText, | ||
children, | ||
style, | ||
}) => { | ||
const [showAll, setShowAll] = React.useState( | ||
false | ||
); | ||
return ( | ||
<View> | ||
<Text numberOfLines={!showAll ? lines : 0} style={style}> | ||
{children} | ||
</Text> | ||
<ShowMore style={footerStyle} readMore={readMoreText} readLess={readLessText} showAll={showAll} setShowAll={setShowAll} /> | ||
</View> | ||
); | ||
}; | ||
|
||
const ShowMore = (props: { showAll: any; setShowAll: any; style: any; readMore: string; readLess: string; }) => { | ||
const { showAll, setShowAll, style, readMore, readLess } = props; | ||
|
||
if (showAll == false) { | ||
return ( | ||
<Text style={(style) ? style : styles.defaultStyle} onPress={() => { setShowAll(true) }}> | ||
{readMore ? readMore : "Read more"} | ||
</Text> | ||
); | ||
} else { | ||
return ( | ||
<Text style={(style) ? style : styles.defaultStyle} onPress={() => { setShowAll(false) }}> | ||
{readLess ? readLess : "Read less"} | ||
</Text> | ||
) | ||
} | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
defaultStyle: { | ||
color: 'black', | ||
marginTop: 6, | ||
} | ||
}); | ||
|
||
|
||
export default SimpleReadMore; |