Skip to content

Dash - change props names and add api json #2308

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/components/dash/dash.api.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "Dash",
"category": "lists",
"description": "Dashed line Component",
"images": [],
"props": [
{
"name": "vertical",
"type": "boolean",
"description": "Is the dashed line should be vertical"
},
{
"name": "gap",
"type": "number",
"description": "The gap between the dashes",
"default": "6"
},
{
"name": "length",
"type": "number",
"description": "The length of the dashes",
"default": "6"
},
{
"name": "thickness",
"type": "number",
"description": "The thickness of the dashes",
"default": "2"
},
{
"name": "color",
"type": "string",
"description": "The color of the dashes",
"default": "Colors.black"
},
{"name": "style", "type": "ViewStyle", "description": "Additional style to the dashes"},
{"name": "containerStyle", "type": "ViewStyle", "description": "The container style"}
],
"snippet": ["<Dash vertical={$1} style={$2}/>"]
}
52 changes: 26 additions & 26 deletions src/components/dash/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,50 @@ export type Layout = {

export interface DashProps extends ViewProps {
vertical?: boolean;
dashGap: number;
dashLength: number;
dashThickness: number;
dashColor?: string;
dashStyle?: StyleProp<ViewStyle>;
gap: number;
length: number;
thickness: number;
color?: string;
style?: StyleProp<ViewStyle>;
containerStyle?: StyleProp<ViewStyle>;
}

const Dash = (props: DashProps) => {
const {style, vertical, dashGap, dashLength, dashThickness, dashColor, dashStyle} = props;
const {containerStyle, vertical, gap, length, thickness, color, style} = props;
const [measurements, setMeasurements] = useState<Layout | undefined>();

const onDashLayout = useCallback((event: LayoutChangeEvent) => {
const {x, y, width, height} = event.nativeEvent.layout;
setMeasurements({x, y, width, height});
}, []);

const _dashStyle = useMemo(() => {
const style = {
width: vertical ? dashThickness : dashLength,
height: vertical ? dashLength : dashThickness,
marginRight: vertical ? 0 : dashGap,
marginBottom: vertical ? dashGap : 0,
backgroundColor: dashColor
const dashStyle = useMemo(() => {
const _style = {
width: vertical ? thickness : length,
height: vertical ? length : thickness,
marginRight: vertical ? 0 : gap,
marginBottom: vertical ? gap : 0,
backgroundColor: color
};
return [dashStyle, style];
}, [vertical, dashLength, dashThickness, dashGap, dashColor, dashStyle]);
return [style, _style];
}, [vertical, length, thickness, gap, color, style]);

const lineStyle = useMemo(() => {
const directionStyle = vertical ? styles.column : styles.row;
const sizeStyle = {
width: vertical ? dashThickness : dashLength,
height: vertical ? dashLength : dashThickness
width: vertical ? thickness : length,
height: vertical ? length : thickness
};
return [directionStyle, sizeStyle, style];
}, [style, vertical, dashThickness, dashLength]);
return [directionStyle, sizeStyle, containerStyle];
}, [containerStyle, vertical, thickness, length]);

const renderDash = () => {
const length = (vertical ? measurements?.height : measurements?.width) || 0;
const n = Math.ceil(length / (dashGap + dashLength));
const _length = (vertical ? measurements?.height : measurements?.width) || 0;
const n = Math.ceil(_length / (gap + length));
const dash = [];

for (let i = 0; i < n; i++) {
dash.push(<View key={i} style={_dashStyle}/>);
dash.push(<View key={i} style={dashStyle}/>);
}

return dash;
Expand All @@ -71,10 +71,10 @@ const Dash = (props: DashProps) => {

export default Dash;
Dash.defaultProps = {
dashGap: 6,
dashLength: 6,
dashThickness: 2,
dashColor: Colors.black
gap: 6,
length: 6,
thickness: 2,
color: Colors.black
};

const styles = StyleSheet.create({
Expand Down
2 changes: 1 addition & 1 deletion src/components/timeline/Line.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Line = React.memo((props: LinePropsInternal) => {

const renderLine = () => {
if (type === LineTypes.DASHED) {
return <Dash vertical dashColor={color} style={dashedLineStyle}/>;
return <Dash vertical color={color} containerStyle={dashedLineStyle}/>;
}
return <View style={solidLineStyle}/>;
};
Expand Down