Skip to content

Commit

Permalink
Create index.tsx
Browse files Browse the repository at this point in the history
  • 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.
60 changes: 60 additions & 0 deletions index.tsx
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;

0 comments on commit c8b5331

Please sign in to comment.