Skip to content

Commit

Permalink
🐛 Y starting point cropped the line
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinmagrez committed Jul 17, 2024
1 parent 4d2053e commit 8e8519e
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/components/divider/Divider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import { StyleSheet, ViewStyle } from 'react-native';
import { useTheme } from '../../styles/themes';
import * as Svg from 'react-native-svg';

export interface Props {
export interface DividerProps {
style?: ViewStyle;
orientation?: 'vertical' | 'horizontal';
dashed?: boolean;
}

export const Divider = ({ style, orientation = 'horizontal', dashed = false }: Props) => {
export const Divider = ({ style, orientation = 'horizontal', dashed = false }: DividerProps) => {
const theme = useTheme();
const [lineLength, setLineLength] = useState(0);

Expand All @@ -27,11 +27,15 @@ export const Divider = ({ style, orientation = 'horizontal', dashed = false }: P
const paddingBottom = getPadding(style, 'paddingBottom');
const paddingLeft = getPadding(style, 'paddingLeft');
const paddingRight = getPadding(style, 'paddingRight');
const heigh = isRow ? paddingTop + paddingBottom + strokeWidth : '100%';
const width = !isRow ? paddingLeft + paddingRight + strokeWidth : '100%';
const computedHeight = paddingTop + paddingBottom + strokeWidth;
const computedWidth = paddingLeft + paddingRight + strokeWidth;
return (
<Svg.Svg
style={{ height: heigh, width: width }}
style={
isRow
? { height: computedHeight, width: '100%' }
: { height: '100%', width: computedWidth }
}
onLayout={(event) => {
const { width, height } = event.nativeEvent.layout;
setLineLength(isRow ? width : height);
Expand All @@ -41,10 +45,10 @@ export const Divider = ({ style, orientation = 'horizontal', dashed = false }: P
stroke={styles.line.color}
strokeWidth={strokeWidth}
strokeDasharray={`5, ${dashed ? '3' : '0'}`}
x1={isRow ? 0 : paddingLeft}
y1={isRow ? paddingTop : 0}
x2={isRow ? lineLength : paddingLeft}
y2={isRow ? paddingTop : lineLength}
x1={isRow ? 0 : paddingLeft + computedWidth / 2}
y1={isRow ? paddingTop + computedHeight / 2 : 0}
x2={isRow ? lineLength : paddingLeft + computedWidth / 2}
y2={isRow ? paddingTop + computedHeight / 2 : lineLength}
/>
</Svg.Svg>
);
Expand Down

0 comments on commit 8e8519e

Please sign in to comment.