Skip to content

Commit

Permalink
Merge pull request #15 from juniorklawa/feat/rest-props
Browse files Browse the repository at this point in the history
Feat/rest props
  • Loading branch information
juniorklawa authored May 26, 2021
2 parents 8d4fff9 + f1c005f commit e806340
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"size",
"responsive"
],
"version": "1.0.18",
"version": "1.1.0",
"description": "React Native component for Android and iOS that provides several ways to resize text within a certain dimension/parent.",
"homepage": "https://github.com/juniorklawa/react-native-auto-size-text",
"main": "lib/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/__snapshots__/AutoSizeText.spec.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
exports[`AutoSizeText snapshot AutoSizeText renders correctly 1`] = `
<Text
adjustsFontSizeToFit={true}
mode="max_lines"
numberOfLines={3}
onTextLayout={[Function]}
style={
Expand Down
5 changes: 3 additions & 2 deletions src/components/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@ import { AutoSizeTextProps } from '../types';
const Group = (props: AutoSizeTextProps) => {
const [maxSize] = React.useState<number>(1000);

const { children, style } = props;
const { children, style, ...rest } = props;

return (
<Text
adjustsFontSizeToFit
testID='group'
adjustsFontSizeToFit
numberOfLines={maxSize}
style={[
style,
{
fontSize: maxSize,
},
]}
{...rest}
>
{children}
</Text>
Expand Down
3 changes: 2 additions & 1 deletion src/components/MaxLines.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { NativeSyntheticEvent, Text, TextLayoutEventData } from 'react-native';
import { AutoSizeTextProps } from '../types';

const MaxLines = (props: AutoSizeTextProps) => {
const { fontSize, children, style, numberOfLines } = props;
const { fontSize, children, style, numberOfLines, ...rest } = props;

const [currentFont, setCurrentFont] = React.useState<number>(
fontSize as number
Expand All @@ -27,6 +27,7 @@ const MaxLines = (props: AutoSizeTextProps) => {
fontSize: currentFont,
},
]}
{...rest}
onTextLayout={handleResizing}
>
{children}
Expand Down
10 changes: 9 additions & 1 deletion src/components/MinFontSize.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import {
import { AutoSizeTextProps } from '../types';

const MinFontSize = (props: AutoSizeTextProps) => {
const { fontSize, children, style, numberOfLines, minFontSize } = props;
const {
fontSize,
children,
style,
numberOfLines,
minFontSize,
...rest
} = props;

const [currentFont, setCurrentFont] = React.useState(fontSize);
const handleResizing = (e: NativeSyntheticEvent<TextLayoutEventData>) => {
Expand Down Expand Up @@ -41,6 +48,7 @@ const MinFontSize = (props: AutoSizeTextProps) => {
fontSize: currentFont,
},
]}
{...rest}
onTextLayout={handleResizing}
>
{children}
Expand Down
2 changes: 2 additions & 0 deletions src/components/OverflowReplacement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const OverflowReplacement = (props: AutoSizeTextProps) => {
style,
numberOfLines,
overflowReplacement,
...rest
} = props;
const [currentText, setCurrentText] = React.useState<string>('');

Expand All @@ -32,6 +33,7 @@ const OverflowReplacement = (props: AutoSizeTextProps) => {
fontSize: fontSize,
},
]}
{...rest}
onTextLayout={handleResizing}
>
{currentText ? currentText : children}
Expand Down
3 changes: 2 additions & 1 deletion src/components/PresetFontSizes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
import { AutoSizeTextProps } from '../types';

const PresetFontSizes = (props: AutoSizeTextProps) => {
const { fontSizePresets, children, style, numberOfLines } = props;
const { fontSizePresets, children, style, numberOfLines, ...rest } = props;
const [currentFont, setCurrentFont] = React.useState<number>(
fontSizePresets![0] as number
);
Expand Down Expand Up @@ -46,6 +46,7 @@ const PresetFontSizes = (props: AutoSizeTextProps) => {
},
]}
onTextLayout={handleResizing}
{...rest}
>
{children}
</Text>
Expand Down
10 changes: 9 additions & 1 deletion src/components/StepGranularity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import {
import { AutoSizeTextProps } from '../types';

const StepGranularity = (props: AutoSizeTextProps) => {
const { fontSize, children, style, numberOfLines, granularity } = props;
const {
fontSize,
children,
style,
numberOfLines,
granularity,
...rest
} = props;
const [currentFont, setCurrentFont] = React.useState(fontSize);
const handleResizing = (e: NativeSyntheticEvent<TextLayoutEventData>) => {
const { lines } = e.nativeEvent;
Expand All @@ -35,6 +42,7 @@ const StepGranularity = (props: AutoSizeTextProps) => {
},
]}
onTextLayout={handleResizing}
{...rest}
>
{children}
</Text>
Expand Down

0 comments on commit e806340

Please sign in to comment.